mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-18 08:09:58 +00:00
Add dropDisabledStatusFields
This commit is contained in:
parent
e061143de7
commit
dacb689002
@ -544,6 +544,18 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
|
|||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation) && !dynamicResourceAllocationInUse(oldPodSpec) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation) && !dynamicResourceAllocationInUse(oldPodSpec) {
|
||||||
podStatus.ResourceClaimStatuses = nil
|
podStatus.ResourceClaimStatuses = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drop HostIPs to empty (disable PodHostIPs).
|
||||||
|
if !utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) && !hostIPsInUse(oldPodStatus) {
|
||||||
|
podStatus.HostIPs = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hostIPsInUse(podStatus *api.PodStatus) bool {
|
||||||
|
if podStatus == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return len(podStatus.HostIPs) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// dropDisabledDynamicResourceAllocationFields removes pod claim references from
|
// dropDisabledDynamicResourceAllocationFields removes pod claim references from
|
||||||
|
@ -1165,6 +1165,112 @@ func TestDropDisabledTopologySpreadConstraintsFields(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDropDisabledPodStatusFields(t *testing.T) {
|
||||||
|
podWithHostIPs := func() *api.PodStatus {
|
||||||
|
return &api.PodStatus{
|
||||||
|
HostIPs: makeHostIPs("10.0.0.1", "fd00:10::1"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
podWithoutHostIPs := func() *api.PodStatus {
|
||||||
|
return &api.PodStatus{
|
||||||
|
HostIPs: nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
podStatus *api.PodStatus
|
||||||
|
oldPodStatus *api.PodStatus
|
||||||
|
wantPodStatus *api.PodStatus
|
||||||
|
featureEnabled bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "gate off, old=without, new=without",
|
||||||
|
oldPodStatus: podWithoutHostIPs(),
|
||||||
|
podStatus: podWithoutHostIPs(),
|
||||||
|
featureEnabled: false,
|
||||||
|
|
||||||
|
wantPodStatus: podWithoutHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate off, old=without, new=with",
|
||||||
|
oldPodStatus: podWithoutHostIPs(),
|
||||||
|
podStatus: podWithHostIPs(),
|
||||||
|
featureEnabled: false,
|
||||||
|
|
||||||
|
wantPodStatus: podWithoutHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate off, old=with, new=without",
|
||||||
|
oldPodStatus: podWithHostIPs(),
|
||||||
|
podStatus: podWithoutHostIPs(),
|
||||||
|
featureEnabled: false,
|
||||||
|
|
||||||
|
wantPodStatus: podWithoutHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate off, old=with, new=with",
|
||||||
|
oldPodStatus: podWithHostIPs(),
|
||||||
|
podStatus: podWithHostIPs(),
|
||||||
|
featureEnabled: false,
|
||||||
|
|
||||||
|
wantPodStatus: podWithHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate on, old=without, new=without",
|
||||||
|
oldPodStatus: podWithoutHostIPs(),
|
||||||
|
podStatus: podWithoutHostIPs(),
|
||||||
|
featureEnabled: true,
|
||||||
|
|
||||||
|
wantPodStatus: podWithoutHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate on, old=without, new=with",
|
||||||
|
oldPodStatus: podWithoutHostIPs(),
|
||||||
|
podStatus: podWithHostIPs(),
|
||||||
|
featureEnabled: true,
|
||||||
|
|
||||||
|
wantPodStatus: podWithHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate on, old=with, new=without",
|
||||||
|
oldPodStatus: podWithHostIPs(),
|
||||||
|
podStatus: podWithoutHostIPs(),
|
||||||
|
featureEnabled: true,
|
||||||
|
|
||||||
|
wantPodStatus: podWithoutHostIPs(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "gate on, old=with, new=with",
|
||||||
|
oldPodStatus: podWithHostIPs(),
|
||||||
|
podStatus: podWithHostIPs(),
|
||||||
|
featureEnabled: true,
|
||||||
|
|
||||||
|
wantPodStatus: podWithHostIPs(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, tt.featureEnabled)()
|
||||||
|
|
||||||
|
dropDisabledPodStatusFields(tt.podStatus, tt.oldPodStatus, &api.PodSpec{}, &api.PodSpec{})
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(tt.podStatus, tt.wantPodStatus) {
|
||||||
|
t.Errorf("dropDisabledStatusFields() = %v, want %v", tt.podStatus, tt.wantPodStatus)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeHostIPs(ips ...string) []api.HostIP {
|
||||||
|
ret := []api.HostIP{}
|
||||||
|
for _, ip := range ips {
|
||||||
|
ret = append(ret, api.HostIP{IP: ip})
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func TestDropNodeInclusionPolicyFields(t *testing.T) {
|
func TestDropNodeInclusionPolicyFields(t *testing.T) {
|
||||||
ignore := api.NodeInclusionPolicyIgnore
|
ignore := api.NodeInclusionPolicyIgnore
|
||||||
honor := api.NodeInclusionPolicyHonor
|
honor := api.NodeInclusionPolicyHonor
|
||||||
|
Loading…
Reference in New Issue
Block a user