Remove DefaultHostNetworkHostPortsInPodTemplates gate

This behavior was deprecated in 1.28.
This commit is contained in:
Tim Hockin 2024-04-19 15:19:58 -07:00
parent 5a71f37805
commit a2fb1b51ac
No known key found for this signature in database
3 changed files with 4 additions and 44 deletions

View File

@ -228,12 +228,6 @@ func SetDefaults_PodSpec(obj *v1.PodSpec) {
if obj.RestartPolicy == "" { if obj.RestartPolicy == "" {
obj.RestartPolicy = v1.RestartPolicyAlways obj.RestartPolicy = v1.RestartPolicyAlways
} }
if utilfeature.DefaultFeatureGate.Enabled(features.DefaultHostNetworkHostPortsInPodTemplates) {
if obj.HostNetwork {
defaultHostNetworkPorts(&obj.Containers)
defaultHostNetworkPorts(&obj.InitContainers)
}
}
if obj.SecurityContext == nil { if obj.SecurityContext == nil {
obj.SecurityContext = &v1.PodSecurityContext{} obj.SecurityContext = &v1.PodSecurityContext{}
} }

View File

@ -208,14 +208,8 @@ func testWorkloadDefaults(t *testing.T, featuresEnabled bool) {
".Spec.HostNetwork": "true", ".Spec.HostNetwork": "true",
".Spec.Containers[0].Ports[0].ContainerPort": "12345", ".Spec.Containers[0].Ports[0].ContainerPort": "12345",
} }
if utilfeature.DefaultFeatureGate.Enabled(features.DefaultHostNetworkHostPortsInPodTemplates) {
m[".Spec.Containers"] = `[{"name":"","ports":[{"hostPort":12345,"containerPort":12345,"protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}]`
m[".Spec.Containers[0].Ports"] = `[{"hostPort":12345,"containerPort":12345,"protocol":"TCP"}]`
m[".Spec.Containers[0].Ports[0].HostPort"] = "12345"
} else {
m[".Spec.Containers"] = `[{"name":"","ports":[{"containerPort":12345,"protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}]` m[".Spec.Containers"] = `[{"name":"","ports":[{"containerPort":12345,"protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}]`
m[".Spec.Containers[0].Ports"] = `[{"containerPort":12345,"protocol":"TCP"}]` m[".Spec.Containers[0].Ports"] = `[{"containerPort":12345,"protocol":"TCP"}]`
}
for k, v := range expectedDefaults { for k, v := range expectedDefaults {
if _, found := m[k]; !found { if _, found := m[k]; !found {
m[k] = v m[k] = v
@ -379,40 +373,23 @@ func testPodDefaults(t *testing.T, featuresEnabled bool) {
func TestPodHostNetworkDefaults(t *testing.T) { func TestPodHostNetworkDefaults(t *testing.T) {
cases := []struct { cases := []struct {
name string name string
gate bool
hostNet bool hostNet bool
expectPodDefault bool expectPodDefault bool
expectPodSpecDefault bool expectPodSpecDefault bool
}{{ }{{
name: "gate disabled, hostNetwork=false", name: "hostNetwork=false",
gate: false,
hostNet: false, hostNet: false,
expectPodDefault: false, expectPodDefault: false,
expectPodSpecDefault: false, expectPodSpecDefault: false,
}, { }, {
name: "gate disabled, hostNetwork=true", name: "hostNetwork=true",
gate: false,
hostNet: true, hostNet: true,
expectPodDefault: true, expectPodDefault: true,
expectPodSpecDefault: false, expectPodSpecDefault: false,
}, {
name: "gate enabled, hostNetwork=false",
gate: true,
hostNet: false,
expectPodDefault: false,
expectPodSpecDefault: false,
}, {
name: "gate enabled, hostNetwork=true",
gate: true,
hostNet: true,
expectPodDefault: true,
expectPodSpecDefault: true,
}} }}
for _, tc := range cases { for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DefaultHostNetworkHostPortsInPodTemplates, tc.gate)()
const portNum = 12345 const portNum = 12345
spec := v1.PodSpec{ spec := v1.PodSpec{
HostNetwork: tc.hostNet, HostNetwork: tc.hostNet,

View File

@ -187,15 +187,6 @@ const (
// Set the scheduled time as an annotation in the job. // Set the scheduled time as an annotation in the job.
CronJobsScheduledAnnotation featuregate.Feature = "CronJobsScheduledAnnotation" CronJobsScheduledAnnotation featuregate.Feature = "CronJobsScheduledAnnotation"
// owner: @thockin
// deprecated: v1.28
//
// Changes when the default value of PodSpec.containers[].ports[].hostPort
// is assigned. The default is to only set a default value in Pods.
// Enabling this means a default will be assigned even to embeddedPodSpecs
// (e.g. in a Deployment), which is the historical default.
DefaultHostNetworkHostPortsInPodTemplates featuregate.Feature = "DefaultHostNetworkHostPortsInPodTemplates"
// owner: @elezar // owner: @elezar
// kep: http://kep.k8s.io/4009 // kep: http://kep.k8s.io/4009
// alpha: v1.28 // alpha: v1.28
@ -1040,8 +1031,6 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
CronJobsScheduledAnnotation: {Default: true, PreRelease: featuregate.Beta}, CronJobsScheduledAnnotation: {Default: true, PreRelease: featuregate.Beta},
DefaultHostNetworkHostPortsInPodTemplates: {Default: false, PreRelease: featuregate.Deprecated},
DisableCloudProviders: {Default: true, PreRelease: featuregate.Beta}, DisableCloudProviders: {Default: true, PreRelease: featuregate.Beta},
DisableKubeletCloudCredentialProviders: {Default: true, PreRelease: featuregate.Beta}, DisableKubeletCloudCredentialProviders: {Default: true, PreRelease: featuregate.Beta},