Skip to content

Commit

Permalink
changed gke validation to accept PortPolicy None
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellee committed May 6, 2024
1 parent 0a343dc commit 981f79a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
17 changes: 9 additions & 8 deletions pkg/cloudproduct/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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}
}
Expand All @@ -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))
}
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/cloudproduct/gke/gke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
},
},
Expand Down Expand Up @@ -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"),
},
},
} {
Expand Down

0 comments on commit 981f79a

Please sign in to comment.