From 7f8b37ff1e7c7d3ba0bd47ca7373ebaf09c199fc Mon Sep 17 00:00:00 2001 From: Vicente Ferrara Date: Wed, 22 May 2024 04:54:32 +0000 Subject: [PATCH] nit --- pkg/apis/agones/v1/gameserver.go | 2 +- pkg/cloudproduct/gke/gke.go | 2 -- pkg/gameservers/controller.go | 11 ++--------- pkg/portallocator/portallocator.go | 1 + pkg/util/runtime/features.go | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/apis/agones/v1/gameserver.go b/pkg/apis/agones/v1/gameserver.go index 6f235cdcc3..67eba0221d 100644 --- a/pkg/apis/agones/v1/gameserver.go +++ b/pkg/apis/agones/v1/gameserver.go @@ -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...) @@ -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 } diff --git a/pkg/cloudproduct/gke/gke.go b/pkg/cloudproduct/gke/gke.go index 439a7ceba6..cf2dc04514 100644 --- a/pkg/cloudproduct/gke/gke.go +++ b/pkg/cloudproduct/gke/gke.go @@ -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 { diff --git a/pkg/gameservers/controller.go b/pkg/gameservers/controller.go index c57b83774f..1bda94834b 100644 --- a/pkg/gameservers/controller.go +++ b/pkg/gameservers/controller.go @@ -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) @@ -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 } @@ -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 } @@ -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 } @@ -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): diff --git a/pkg/portallocator/portallocator.go b/pkg/portallocator/portallocator.go index 6ef954563e..0fb0e27202 100644 --- a/pkg/portallocator/portallocator.go +++ b/pkg/portallocator/portallocator.go @@ -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 } diff --git a/pkg/util/runtime/features.go b/pkg/util/runtime/features.go index a0d9717edd..40c41468bb 100644 --- a/pkg/util/runtime/features.go +++ b/pkg/util/runtime/features.go @@ -140,7 +140,7 @@ var ( FeaturePortPolicyNone: false, // Dev features - FeatureAutopilotPassthroughPort: true, + FeatureAutopilotPassthroughPort: false, // Example feature FeatureExample: false,