From 26cfea876a7960ca5a31d8619d2175fad27eaeb8 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 3 May 2024 19:13:23 +0200 Subject: [PATCH] changed gke validation to accept PortPolicy None --- pkg/cloudproduct/gke/gke.go | 17 +++++++++-------- pkg/cloudproduct/gke/gke_test.go | 14 ++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/cloudproduct/gke/gke.go b/pkg/cloudproduct/gke/gke.go index cc8009352e..a70aede8f1 100644 --- a/pkg/cloudproduct/gke/gke.go +++ b/pkg/cloudproduct/gke/gke.go @@ -39,10 +39,10 @@ const ( hostPortAssignmentAnnotation = "autopilot.gke.io/host-port-assignment" primaryContainerAnnotation = "autopilot.gke.io/primary-container" - errPortPolicyMustBeDynamic = "portPolicy must be Dynamic on GKE Autopilot" - errRangeInvalid = "range must not be used on GKE Autopilot" - errSchedulingMustBePacked = "scheduling strategy must be Packed on GKE Autopilot" - errEvictionSafeOnUpgradeInvalid = "eviction.safe OnUpgrade not supported on GKE Autopilot" + errPortPolicyMustBeDynamicOrNone = "portPolicy must be Dynamic or None on GKE Autopilot" + errRangeInvalid = "range must not be used on GKE Autopilot" + errSchedulingMustBePacked = "scheduling strategy must be Packed on GKE Autopilot" + errEvictionSafeOnUpgradeInvalid = "eviction.safe OnUpgrade not supported on GKE Autopilot" ) var ( @@ -126,7 +126,8 @@ func (*gkeAutopilot) SyncPodPortsToGameServer(gs *agonesv1.GameServer, pod *core func (*gkeAutopilot) NewPortAllocator(portRanges map[string]portallocator.PortRange, _ informers.SharedInformerFactory, - _ externalversions.SharedInformerFactory) portallocator.Interface { + _ externalversions.SharedInformerFactory, +) portallocator.Interface { defPortRange := portRanges[agonesv1.DefaultPortRange] return &autopilotPortAllocator{minPort: defPortRange.MinPort, maxPort: defPortRange.MaxPort} } @@ -136,10 +137,10 @@ func (*gkeAutopilot) WaitOnFreePorts() bool { return true } func (g *gkeAutopilot) ValidateGameServerSpec(gss *agonesv1.GameServerSpec, fldPath *field.Path) field.ErrorList { allErrs := g.ValidateScheduling(gss.Scheduling, fldPath.Child("scheduling")) for i, p := range gss.Ports { - if p.PortPolicy != agonesv1.Dynamic { - allErrs = append(allErrs, field.Invalid(fldPath.Child("ports").Index(i).Child("portPolicy"), string(p.PortPolicy), errPortPolicyMustBeDynamic)) + if p.PortPolicy != agonesv1.Dynamic && p.PortPolicy != agonesv1.None { + allErrs = append(allErrs, field.Invalid(fldPath.Child("ports").Index(i).Child("portPolicy"), string(p.PortPolicy), errPortPolicyMustBeDynamicOrNone)) } - if p.Range != agonesv1.DefaultPortRange { + if p.Range != agonesv1.DefaultPortRange && p.PortPolicy != agonesv1.None { allErrs = append(allErrs, field.Invalid(fldPath.Child("ports").Index(i).Child("range"), p.Range, errRangeInvalid)) } } diff --git a/pkg/cloudproduct/gke/gke_test.go b/pkg/cloudproduct/gke/gke_test.go index 78fcc3e1f0..128176edae 100644 --- a/pkg/cloudproduct/gke/gke_test.go +++ b/pkg/cloudproduct/gke/gke_test.go @@ -109,6 +109,12 @@ func TestValidateGameServer(t *testing.T) { ContainerPort: 1234, Protocol: corev1.ProtocolTCP, }, + { + Name: "none-udp", + PortPolicy: agonesv1.None, + ContainerPort: 1234, + Protocol: corev1.ProtocolUDP, + }, }, safeToEvict: agonesv1.EvictionSafeAlways, scheduling: apis.Packed, @@ -172,8 +178,8 @@ func TestValidateGameServer(t *testing.T) { scheduling: apis.Distributed, want: field.ErrorList{ field.Invalid(field.NewPath("spec", "scheduling"), "Distributed", "scheduling strategy must be Packed on GKE Autopilot"), - field.Invalid(field.NewPath("spec", "ports").Index(1).Child("portPolicy"), "Static", "portPolicy must be Dynamic on GKE Autopilot"), - field.Invalid(field.NewPath("spec", "ports").Index(2).Child("portPolicy"), "Static", "portPolicy must be Dynamic on GKE Autopilot"), + field.Invalid(field.NewPath("spec", "ports").Index(1).Child("portPolicy"), "Static", "portPolicy must be Dynamic or None on GKE Autopilot"), + field.Invalid(field.NewPath("spec", "ports").Index(2).Child("portPolicy"), "Static", "portPolicy must be Dynamic or None on GKE Autopilot"), field.Invalid(field.NewPath("spec", "eviction", "safe"), "OnUpgrade", "eviction.safe OnUpgrade not supported on GKE Autopilot"), }, }, @@ -206,8 +212,8 @@ func TestValidateGameServer(t *testing.T) { scheduling: apis.Distributed, want: field.ErrorList{ field.Invalid(field.NewPath("spec", "scheduling"), "Distributed", "scheduling strategy must be Packed on GKE Autopilot"), - field.Invalid(field.NewPath("spec", "ports").Index(1).Child("portPolicy"), "Static", "portPolicy must be Dynamic on GKE Autopilot"), - field.Invalid(field.NewPath("spec", "ports").Index(2).Child("portPolicy"), "Static", "portPolicy must be Dynamic on GKE Autopilot"), + field.Invalid(field.NewPath("spec", "ports").Index(1).Child("portPolicy"), "Static", "portPolicy must be Dynamic or None on GKE Autopilot"), + field.Invalid(field.NewPath("spec", "ports").Index(2).Child("portPolicy"), "Static", "portPolicy must be Dynamic or None on GKE Autopilot"), }, }, } {