Skip to content

Commit

Permalink
featuregate: adds validation if PortPolicyNone is not enabled (#3871)
Browse files Browse the repository at this point in the history
Then validation should fail if the PortPolicy field is set to the value None
  • Loading branch information
daniellee authored Jun 17, 2024
1 parent 2a16d13 commit 541dafe
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/apis/agones/v1/gameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,14 @@ func (gss *GameServerSpec) validateFeatureGates(fldPath *field.Path) field.Error
}
}

if !runtime.FeatureEnabled(runtime.FeaturePortPolicyNone) {
for i, p := range gss.Ports {
if p.PortPolicy == None {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("ports").Index(i).Child("portPolicy"), fmt.Sprintf("Value cannot be set to %s unless feature flag %s is enabled", None, runtime.FeaturePortPolicyNone)))
}
}
}

return allErrs
}

Expand Down
49 changes: 48 additions & 1 deletion pkg/apis/agones/v1/gameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,52 @@ func TestGameServerValidateFeatures(t *testing.T) {
},
},
},
{
description: "PortPolicyNone is disabled, PortPolicy field set to None",
feature: fmt.Sprintf("%s=false", runtime.FeaturePortPolicyNone),
gs: GameServer{
Spec: GameServerSpec{
Ports: []GameServerPort{
{
Name: "main",
ContainerPort: 7777,
PortPolicy: None,
},
},
Container: "testing",
Lists: map[string]ListStatus{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}},
},
},
},
want: field.ErrorList{
field.Forbidden(
field.NewPath("spec.ports[0].portPolicy"),
"Value cannot be set to None unless feature flag PortPolicyNone is enabled",
),
},
},
{
description: "PortPolicyNone is enabled, PortPolicy field set to None",
feature: fmt.Sprintf("%s=true", runtime.FeaturePortPolicyNone),
gs: GameServer{
Spec: GameServerSpec{
Ports: []GameServerPort{
{
Name: "main",
ContainerPort: 7777,
PortPolicy: None,
},
},
Container: "testing",
Lists: map[string]ListStatus{},
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "testing", Image: "testing/image"}}},
},
},
},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -1499,7 +1545,8 @@ func TestGameServerPassthroughPortAnnotation(t *testing.T) {
{Name: "containerOne", Image: "container/image"},
{Name: "containerTwo", Image: "container/image"},
{Name: "containerThree", Image: "container/image"},
{Name: "containerFour", Image: "container/image"}},
{Name: "containerFour", Image: "container/image"},
},
},
},
}}
Expand Down

0 comments on commit 541dafe

Please sign in to comment.