Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentefb committed May 22, 2024
1 parent 6fe2b26 commit 7f8b37f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ func (gs *GameServer) Pod(apiHooks APIHooks, sidecars ...corev1.Container) (*cor
return nil, err
}
}

// Put the sidecars at the start of the list of containers so that the kubelet starts them first.
containers := make([]corev1.Container, 0, len(sidecars)+len(pod.Spec.Containers))
containers = append(containers, sidecars...)
Expand All @@ -779,6 +778,7 @@ func (gs *GameServer) Pod(apiHooks APIHooks, sidecars ...corev1.Container) (*cor
if err := apiHooks.SetEviction(gs.Status.Eviction, pod); err != nil {
return nil, err
}

return pod, nil
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/cloudproduct/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,11 @@ func (apa *autopilotPortAllocator) Allocate(gs *agonesv1.GameServer) *agonesv1.G

var ports []agonesv1.GameServerPort
for i, p := range gs.Spec.Ports {

if p.PortPolicy != agonesv1.Dynamic && !runtime.FeatureEnabled(runtime.FeatureAutopilotPassthroughPort) {
logger.WithField("gs", gs.Name).WithField("portPolicy", p.PortPolicy).Error(
"GameServer has invalid PortPolicy for Autopilot - this should have been rejected by webhooks. Refusing to assign ports.")
return gs
}

p.HostPort = int32(i + 1) // Autopilot expects _some_ host port - use a value unique to this GameServer Port.

if p.Protocol == agonesv1.ProtocolTCPUDP {
Expand Down
11 changes: 2 additions & 9 deletions pkg/gameservers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func NewController(
// initializes a new logger for extensions.
func NewExtensions(apiHooks agonesv1.APIHooks, wh *webhooks.WebHook) *Extensions {
ext := &Extensions{apiHooks: apiHooks}

ext.baseLogger = runtime.NewLoggerWithType(ext)

wh.AddHandler("/mutate", agonesv1.Kind("GameServer"), admissionv1.Create, ext.creationMutationHandler)
Expand All @@ -215,7 +216,6 @@ func NewExtensions(apiHooks agonesv1.APIHooks, wh *webhooks.WebHook) *Extensions
if runtime.FeatureEnabled(runtime.FeatureAutopilotPassthroughPort) {
wh.AddHandler("/mutate", corev1.SchemeGroupVersion.WithKind("Pod").GroupKind(), admissionv1.Create, ext.creationMutationHandlerPod)
}

return ext
}

Expand Down Expand Up @@ -280,6 +280,7 @@ func (ext *Extensions) creationMutationHandler(review admissionv1.AdmissionRevie
pt := admissionv1.PatchTypeJSONPatch
review.Response.PatchType = &pt
review.Response.Patch = jsonPatch

return review, nil
}

Expand Down Expand Up @@ -628,17 +629,10 @@ func (c *Controller) syncDevelopmentGameServer(ctx context.Context, gs *agonesv1
// createGameServerPod creates the backing Pod for a given GameServer
func (c *Controller) createGameServerPod(ctx context.Context, gs *agonesv1.GameServer) (*agonesv1.GameServer, error) {
sidecar := c.sidecar(gs)

c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "after sidecar")

pod, err := gs.Pod(c.controllerHooks, sidecar)
c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "after pod")

if err != nil {
// this shouldn't happen, but if it does.
loggerForGameServer(gs, c.baseLogger).WithError(err).Error("error creating pod from Game Server")
c.recorder.Event(gs, corev1.EventTypeNormal, string(gs.Status.State), "ERROR CREATING POD")

gs, err = c.moveToErrorState(ctx, gs, err.Error())
return gs, err
}
Expand All @@ -662,7 +656,6 @@ func (c *Controller) createGameServerPod(ctx context.Context, gs *agonesv1.GameS

loggerForGameServer(gs, c.baseLogger).WithField("pod", pod).Debug("Creating Pod for GameServer")
pod, err = c.podGetter.Pods(gs.ObjectMeta.Namespace).Create(ctx, pod, metav1.CreateOptions{})
loggerForGameServer(gs, c.baseLogger).WithField("pod", pod).Info("Pod for GameServer was created but there could berror")
if err != nil {
switch {
case k8serrors.IsAlreadyExists(err):
Expand Down
1 change: 1 addition & 0 deletions pkg/portallocator/portallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func (pa *portRangeAllocator) Allocate(gs *agonesv1.GameServer) *agonesv1.GameSe
if p.Protocol == agonesv1.ProtocolTCPUDP {
var duplicate = p
duplicate.HostPort = a.port

if duplicate.PortPolicy == agonesv1.Passthrough {
duplicate.ContainerPort = a.port
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/runtime/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var (
FeaturePortPolicyNone: false,

// Dev features
FeatureAutopilotPassthroughPort: true,
FeatureAutopilotPassthroughPort: false,

// Example feature
FeatureExample: false,
Expand Down

0 comments on commit 7f8b37f

Please sign in to comment.