Skip to content

Commit ef37cb5

Browse files
authored
Merge pull request kubernetes#128634 from thockin/remove_PodHostIPs_gate_for_1.32
Remove PodHostIPs feature gates
2 parents 7667a68 + 6e5a3cd commit ef37cb5

File tree

10 files changed

+37
-212
lines changed

10 files changed

+37
-212
lines changed

pkg/api/pod/util.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
377377
// default pod validation options based on feature gate
378378
opts := apivalidation.PodValidationOptions{
379379
AllowInvalidPodDeletionCost: !utilfeature.DefaultFeatureGate.Enabled(features.PodDeletionCost),
380-
// Allow pod spec to use status.hostIPs in downward API if feature is enabled
381-
AllowHostIPsField: utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs),
382380
// Do not allow pod spec to use non-integer multiple of huge page unit size default
383381
AllowIndivisibleHugePagesValues: false,
384382
AllowInvalidLabelValueInSelector: false,
@@ -396,9 +394,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
396394
opts.AllowOnlyRecursiveSELinuxChangePolicy = useOnlyRecursiveSELinuxChangePolicy(oldPodSpec)
397395

398396
if oldPodSpec != nil {
399-
// if old spec has status.hostIPs downwardAPI set, we must allow it
400-
opts.AllowHostIPsField = opts.AllowHostIPsField || hasUsedDownwardAPIFieldPathWithPodSpec(oldPodSpec, "status.hostIPs")
401-
402397
// if old spec used non-integer multiple of huge page unit size, we must allow it
403398
opts.AllowIndivisibleHugePagesValues = usesIndivisibleHugePagesValues(oldPodSpec)
404399

@@ -536,55 +531,6 @@ func relaxedEnvVarUsed(name string, oldPodEnvVarNames sets.Set[string]) bool {
536531
return false
537532
}
538533

539-
func hasUsedDownwardAPIFieldPathWithPodSpec(podSpec *api.PodSpec, fieldPath string) bool {
540-
if podSpec == nil {
541-
return false
542-
}
543-
for _, vol := range podSpec.Volumes {
544-
if hasUsedDownwardAPIFieldPathWithVolume(&vol, fieldPath) {
545-
return true
546-
}
547-
}
548-
for _, c := range podSpec.InitContainers {
549-
if hasUsedDownwardAPIFieldPathWithContainer(&c, fieldPath) {
550-
return true
551-
}
552-
}
553-
for _, c := range podSpec.Containers {
554-
if hasUsedDownwardAPIFieldPathWithContainer(&c, fieldPath) {
555-
return true
556-
}
557-
}
558-
return false
559-
}
560-
561-
func hasUsedDownwardAPIFieldPathWithVolume(volume *api.Volume, fieldPath string) bool {
562-
if volume == nil || volume.DownwardAPI == nil {
563-
return false
564-
}
565-
for _, file := range volume.DownwardAPI.Items {
566-
if file.FieldRef != nil &&
567-
file.FieldRef.FieldPath == fieldPath {
568-
return true
569-
}
570-
}
571-
return false
572-
}
573-
574-
func hasUsedDownwardAPIFieldPathWithContainer(container *api.Container, fieldPath string) bool {
575-
if container == nil {
576-
return false
577-
}
578-
for _, env := range container.Env {
579-
if env.ValueFrom != nil &&
580-
env.ValueFrom.FieldRef != nil &&
581-
env.ValueFrom.FieldRef.FieldPath == fieldPath {
582-
return true
583-
}
584-
}
585-
return false
586-
}
587-
588534
// GetValidationOptionsFromPodTemplate will return pod validation options for specified template.
589535
func GetValidationOptionsFromPodTemplate(podTemplate, oldPodTemplate *api.PodTemplateSpec) apivalidation.PodValidationOptions {
590536
var newPodSpec, oldPodSpec *api.PodSpec
@@ -859,11 +805,6 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
859805
podStatus.ResourceClaimStatuses = nil
860806
}
861807

862-
// drop HostIPs to empty (disable PodHostIPs).
863-
if !utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) && !hostIPsInUse(oldPodStatus) {
864-
podStatus.HostIPs = nil
865-
}
866-
867808
if !utilfeature.DefaultFeatureGate.Enabled(features.RecursiveReadOnlyMounts) && !rroInUse(oldPodSpec) {
868809
for i := range podStatus.ContainerStatuses {
869810
podStatus.ContainerStatuses[i].VolumeMounts = nil
@@ -900,13 +841,6 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
900841
}
901842
}
902843

903-
func hostIPsInUse(podStatus *api.PodStatus) bool {
904-
if podStatus == nil {
905-
return false
906-
}
907-
return len(podStatus.HostIPs) > 0
908-
}
909-
910844
// dropDisabledDynamicResourceAllocationFields removes pod claim references from
911845
// container specs and pod-level resource claims unless they are already used
912846
// by the old pod spec.

pkg/apis/core/validation/validation.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,6 @@ func validateDownwardAPIVolumeFile(file *core.DownwardAPIVolumeFile, fldPath *fi
10731073
if file.ResourceFieldRef != nil {
10741074
allErrs = append(allErrs, field.Invalid(fldPath, "resource", "fieldRef and resourceFieldRef can not be specified simultaneously"))
10751075
}
1076-
allErrs = append(allErrs, validateDownwardAPIHostIPs(file.FieldRef, fldPath.Child("fieldRef"), opts)...)
10771076
} else if file.ResourceFieldRef != nil {
10781077
localValidContainerResourceFieldPathPrefixes := validContainerResourceFieldPathPrefixesWithDownwardAPIHugePages
10791078
allErrs = append(allErrs, validateContainerResourceFieldSelector(file.ResourceFieldRef, &validContainerResourceFieldPathExpressions, &localValidContainerResourceFieldPathPrefixes, fldPath.Child("resourceFieldRef"), true)...)
@@ -2655,7 +2654,6 @@ func validateEnvVarValueFrom(ev core.EnvVar, fldPath *field.Path, opts PodValida
26552654
if ev.ValueFrom.FieldRef != nil {
26562655
numSources++
26572656
allErrs = append(allErrs, validateObjectFieldSelector(ev.ValueFrom.FieldRef, &validEnvDownwardAPIFieldPathExpressions, fldPath.Child("fieldRef"))...)
2658-
allErrs = append(allErrs, validateDownwardAPIHostIPs(ev.ValueFrom.FieldRef, fldPath.Child("fieldRef"), opts)...)
26592657
}
26602658
if ev.ValueFrom.ResourceFieldRef != nil {
26612659
numSources++
@@ -2719,16 +2717,6 @@ func validateObjectFieldSelector(fs *core.ObjectFieldSelector, expressions *sets
27192717
return allErrs
27202718
}
27212719

2722-
func validateDownwardAPIHostIPs(fieldSel *core.ObjectFieldSelector, fldPath *field.Path, opts PodValidationOptions) field.ErrorList {
2723-
allErrs := field.ErrorList{}
2724-
if !opts.AllowHostIPsField {
2725-
if fieldSel.FieldPath == "status.hostIPs" {
2726-
allErrs = append(allErrs, field.Forbidden(fldPath, "may not be set when feature gate 'PodHostIPs' is not enabled"))
2727-
}
2728-
}
2729-
return allErrs
2730-
}
2731-
27322720
func validateContainerResourceFieldSelector(fs *core.ResourceFieldSelector, expressions *sets.Set[string], prefixes *sets.Set[string], fldPath *field.Path, volume bool) field.ErrorList {
27332721
allErrs := field.ErrorList{}
27342722

@@ -4041,8 +4029,6 @@ type PodValidationOptions struct {
40414029
AllowInvalidLabelValueInSelector bool
40424030
// Allow pod spec to use non-integer multiple of huge page unit size
40434031
AllowIndivisibleHugePagesValues bool
4044-
// Allow pod spec to use status.hostIPs in downward API if feature is enabled
4045-
AllowHostIPsField bool
40464032
// Allow invalid topologySpreadConstraint labelSelector for backward compatibility
40474033
AllowInvalidTopologySpreadConstraintLabelSelector bool
40484034
// Allow projected token volumes with non-local paths

pkg/apis/core/validation/validation_test.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23736,41 +23736,6 @@ func TestValidateAppArmorProfileFormat(t *testing.T) {
2373623736
}
2373723737
}
2373823738

23739-
func TestValidateDownwardAPIHostIPs(t *testing.T) {
23740-
testCases := []struct {
23741-
name string
23742-
expectError bool
23743-
featureEnabled bool
23744-
fieldSel *core.ObjectFieldSelector
23745-
}{
23746-
{
23747-
name: "has no hostIPs field, featuregate enabled",
23748-
expectError: false,
23749-
featureEnabled: true,
23750-
fieldSel: &core.ObjectFieldSelector{FieldPath: "status.hostIP"},
23751-
},
23752-
{
23753-
name: "has hostIPs field, featuregate enabled",
23754-
expectError: false,
23755-
featureEnabled: true,
23756-
fieldSel: &core.ObjectFieldSelector{FieldPath: "status.hostIPs"},
23757-
},
23758-
}
23759-
for _, testCase := range testCases {
23760-
t.Run(testCase.name, func(t *testing.T) {
23761-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, testCase.featureEnabled)
23762-
23763-
errs := validateDownwardAPIHostIPs(testCase.fieldSel, field.NewPath("fieldSel"), PodValidationOptions{AllowHostIPsField: testCase.featureEnabled})
23764-
if testCase.expectError && len(errs) == 0 {
23765-
t.Errorf("Unexpected success")
23766-
}
23767-
if !testCase.expectError && len(errs) != 0 {
23768-
t.Errorf("Unexpected error(s): %v", errs)
23769-
}
23770-
})
23771-
}
23772-
}
23773-
2377423739
func TestValidatePVSecretReference(t *testing.T) {
2377523740
rootFld := field.NewPath("name")
2377623741
type args struct {

pkg/features/kube_features.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,6 @@ const (
472472
// sandbox creation and network configuration completes successfully
473473
PodReadyToStartContainersCondition featuregate.Feature = "PodReadyToStartContainersCondition"
474474

475-
// owner: @wzshiming
476-
// kep: http://kep.k8s.io/2681
477-
//
478-
// Adds pod.status.hostIPs and downward API
479-
PodHostIPs featuregate.Feature = "PodHostIPs"
480-
481475
// owner: @AxeZhan
482476
// kep: http://kep.k8s.io/3960
483477
//

pkg/features/versioned_kube_features.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,6 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
562562
{Version: version.MustParse("1.31"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.33
563563
},
564564

565-
PodHostIPs: {
566-
{Version: version.MustParse("1.28"), Default: false, PreRelease: featuregate.Alpha},
567-
{Version: version.MustParse("1.29"), Default: true, PreRelease: featuregate.Beta},
568-
{Version: version.MustParse("1.30"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.32
569-
},
570-
571565
PodIndexLabel: {
572566
{Version: version.MustParse("1.28"), Default: true, PreRelease: featuregate.Beta},
573567
{Version: version.MustParse("1.32"), Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.35

pkg/kubelet/kubelet_pods.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,6 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *v1.ObjectFieldSelector, pod
949949
}
950950
return hostIPs[0].String(), nil
951951
case "status.hostIPs":
952-
if !utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) {
953-
return "", nil
954-
}
955952
hostIPs, err := kl.getHostIPsAnyWay()
956953
if err != nil {
957954
return "", err
@@ -1921,11 +1918,9 @@ func (kl *Kubelet) generateAPIPodStatus(pod *v1.Pod, podStatus *kubecontainer.Po
19211918
}
19221919
}
19231920
s.HostIP = hostIPs[0].String()
1924-
if utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) {
1925-
s.HostIPs = []v1.HostIP{{IP: s.HostIP}}
1926-
if len(hostIPs) == 2 {
1927-
s.HostIPs = append(s.HostIPs, v1.HostIP{IP: hostIPs[1].String()})
1928-
}
1921+
s.HostIPs = []v1.HostIP{{IP: s.HostIP}}
1922+
if len(hostIPs) == 2 {
1923+
s.HostIPs = append(s.HostIPs, v1.HostIP{IP: hostIPs[1].String()})
19291924
}
19301925

19311926
// HostNetwork Pods inherit the node IPs as PodIPs. They are immutable once set,

test/conformance/testdata/conformance.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,14 @@
21522152
in the container.
21532153
release: v1.9
21542154
file: test/e2e/common/node/downwardapi.go
2155+
- testname: DownwardAPI, environment for hostIPs
2156+
codename: '[sig-node] Downward API should provide hostIPs as an env var [NodeConformance]
2157+
[Conformance]'
2158+
description: Downward API MUST expose Pod and Container fields as environment variables.
2159+
Specify hostIPs as environment variable in the Pod Spec are visible at runtime
2160+
in the container.
2161+
release: v1.32
2162+
file: test/e2e/common/node/downwardapi.go
21552163
- testname: DownwardAPI, environment for Pod UID
21562164
codename: '[sig-node] Downward API should provide pod UID as env vars [NodeConformance]
21572165
[Conformance]'

test/e2e/common/node/downwardapi.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,32 @@ var _ = SIGDescribe("Downward API", func() {
110110
testDownwardAPI(ctx, f, podName, env, expectations)
111111
})
112112

113+
/*
114+
Release: v1.32
115+
Testname: DownwardAPI, environment for hostIPs
116+
Description: Downward API MUST expose Pod and Container fields as environment variables. Specify hostIPs as environment variable in the Pod Spec are visible at runtime in the container.
117+
*/
118+
framework.ConformanceIt("should provide hostIPs as an env var", f.WithNodeConformance(), func(ctx context.Context) {
119+
podName := "downward-api-" + string(uuid.NewUUID())
120+
env := []v1.EnvVar{
121+
{
122+
Name: "HOST_IP",
123+
ValueFrom: &v1.EnvVarSource{
124+
FieldRef: &v1.ObjectFieldSelector{
125+
APIVersion: "v1",
126+
FieldPath: "status.hostIP",
127+
},
128+
},
129+
},
130+
}
131+
132+
expectations := []string{
133+
fmt.Sprintf("HOST_IP=%v|%v", e2enetwork.RegexIPv4, e2enetwork.RegexIPv6),
134+
}
135+
136+
testDownwardAPI(ctx, f, podName, env, expectations)
137+
})
138+
113139
ginkgo.It("should provide host IP and pod IP as an env var if pod uses host network [LinuxOnly]", func(ctx context.Context) {
114140
podName := "downward-api-" + string(uuid.NewUUID())
115141
env := []v1.EnvVar{

test/e2e_node/pod_host_ips.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,14 @@ import (
2424
"github.com/onsi/gomega"
2525

2626
v1 "k8s.io/api/core/v1"
27-
"k8s.io/apimachinery/pkg/api/resource"
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/apimachinery/pkg/util/uuid"
3029
netutils "k8s.io/utils/net"
3130

32-
utilfeature "k8s.io/apiserver/pkg/util/feature"
33-
kubefeatures "k8s.io/kubernetes/pkg/features"
3431
utilnode "k8s.io/kubernetes/pkg/util/node"
3532
"k8s.io/kubernetes/test/e2e/framework"
36-
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
3733
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
3834
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
39-
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
40-
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
4135
"k8s.io/kubernetes/test/e2e/network/common"
4236
imageutils "k8s.io/kubernetes/test/utils/image"
4337
admissionapi "k8s.io/pod-security-admission/api"
@@ -109,31 +103,6 @@ var _ = common.SIGDescribe("Pod Host IPs", func() {
109103
err = podClient.Delete(ctx, pod.Name, *metav1.NewDeleteOptions(1))
110104
framework.ExpectNoError(err, "failed to delete pod")
111105
})
112-
113-
ginkgo.It("should provide hostIPs as an env var", func(ctx context.Context) {
114-
if !utilfeature.DefaultFeatureGate.Enabled(kubefeatures.PodHostIPs) {
115-
e2eskipper.Skipf("PodHostIPs feature is not enabled")
116-
}
117-
118-
podName := "downward-api-" + string(uuid.NewUUID())
119-
env := []v1.EnvVar{
120-
{
121-
Name: "HOST_IPS",
122-
ValueFrom: &v1.EnvVarSource{
123-
FieldRef: &v1.ObjectFieldSelector{
124-
APIVersion: "v1",
125-
FieldPath: "status.hostIPs",
126-
},
127-
},
128-
},
129-
}
130-
131-
expectations := []string{
132-
fmt.Sprintf("HOST_IPS=%v|%v", e2enetwork.RegexIPv4, e2enetwork.RegexIPv6),
133-
}
134-
135-
testDownwardAPI(ctx, f, podName, env, expectations)
136-
})
137106
})
138107
})
139108

@@ -176,35 +145,3 @@ func genHostIPsForNode(ctx context.Context, f *framework.Framework, nodeName str
176145
}
177146
return nil, fmt.Errorf("no such node %q", nodeName)
178147
}
179-
180-
func testDownwardAPI(ctx context.Context, f *framework.Framework, podName string, env []v1.EnvVar, expectations []string) {
181-
pod := &v1.Pod{
182-
ObjectMeta: metav1.ObjectMeta{
183-
Name: podName,
184-
Labels: map[string]string{"name": podName},
185-
},
186-
Spec: v1.PodSpec{
187-
Containers: []v1.Container{
188-
{
189-
Name: "dapi-container",
190-
Image: imageutils.GetE2EImage(imageutils.BusyBox),
191-
Command: []string{"sh", "-c", "env"},
192-
Resources: v1.ResourceRequirements{
193-
Requests: v1.ResourceList{
194-
v1.ResourceCPU: resource.MustParse("250m"),
195-
v1.ResourceMemory: resource.MustParse("32Mi"),
196-
},
197-
Limits: v1.ResourceList{
198-
v1.ResourceCPU: resource.MustParse("1250m"),
199-
v1.ResourceMemory: resource.MustParse("64Mi"),
200-
},
201-
},
202-
Env: env,
203-
},
204-
},
205-
RestartPolicy: v1.RestartPolicyNever,
206-
},
207-
}
208-
209-
e2epodoutput.TestContainerOutputRegexp(ctx, f, "downward api env vars", pod, 0, expectations)
210-
}

test/featuregates_linter/test_data/versioned_feature_list.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -878,20 +878,6 @@
878878
lockToDefault: true
879879
preRelease: GA
880880
version: "1.31"
881-
- name: PodHostIPs
882-
versionedSpecs:
883-
- default: false
884-
lockToDefault: false
885-
preRelease: Alpha
886-
version: "1.28"
887-
- default: true
888-
lockToDefault: false
889-
preRelease: Beta
890-
version: "1.29"
891-
- default: true
892-
lockToDefault: true
893-
preRelease: GA
894-
version: "1.30"
895881
- name: PodIndexLabel
896882
versionedSpecs:
897883
- default: true

0 commit comments

Comments
 (0)