mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
add observedGeneration to pod's dropDisabledStatusFields
This commit is contained in:
parent
6edd921746
commit
12d34624ba
@ -854,6 +854,13 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
|
||||
dropUserField(podStatus.ContainerStatuses)
|
||||
dropUserField(podStatus.EphemeralContainerStatuses)
|
||||
}
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodObservedGenerationTracking) && !podObservedGenerationTrackingInUse(oldPodStatus) {
|
||||
podStatus.ObservedGeneration = 0
|
||||
for i := range podStatus.Conditions {
|
||||
podStatus.Conditions[i].ObservedGeneration = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dropDisabledDynamicResourceAllocationFields removes pod claim references from
|
||||
@ -1050,18 +1057,28 @@ func nodeTaintsPolicyInUse(podSpec *api.PodSpec) bool {
|
||||
|
||||
// hostUsersInUse returns true if the pod spec has spec.hostUsers field set.
|
||||
func hostUsersInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec != nil && podSpec.SecurityContext != nil && podSpec.SecurityContext.HostUsers != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return podSpec != nil && podSpec.SecurityContext != nil && podSpec.SecurityContext.HostUsers != nil
|
||||
}
|
||||
|
||||
func supplementalGroupsPolicyInUse(podSpec *api.PodSpec) bool {
|
||||
if podSpec != nil && podSpec.SecurityContext != nil && podSpec.SecurityContext.SupplementalGroupsPolicy != nil {
|
||||
return podSpec != nil && podSpec.SecurityContext != nil && podSpec.SecurityContext.SupplementalGroupsPolicy != nil
|
||||
}
|
||||
|
||||
func podObservedGenerationTrackingInUse(podStatus *api.PodStatus) bool {
|
||||
if podStatus == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if podStatus.ObservedGeneration != 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, condition := range podStatus.Conditions {
|
||||
if condition.ObservedGeneration != 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -1016,7 +1017,7 @@ func TestValidatePodDeletionCostOption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropDisabledPodStatusFields(t *testing.T) {
|
||||
func TestDropDisabledPodStatusFields_HostIPs(t *testing.T) {
|
||||
podWithHostIPs := func() *api.PodStatus {
|
||||
return &api.PodStatus{
|
||||
HostIPs: makeHostIPs("10.0.0.1", "fd00:10::1"),
|
||||
@ -1083,6 +1084,104 @@ func makeHostIPs(ips ...string) []api.HostIP {
|
||||
return ret
|
||||
}
|
||||
|
||||
func TestDropDisabledPodStatusFields_ObservedGeneration(t *testing.T) {
|
||||
now := metav1.NewTime(time.Now())
|
||||
|
||||
podWithObservedGen := func() *api.PodStatus {
|
||||
return &api.PodStatus{
|
||||
ObservedGeneration: 1,
|
||||
Conditions: []api.PodCondition{{
|
||||
LastProbeTime: now,
|
||||
LastTransitionTime: now,
|
||||
}},
|
||||
}
|
||||
}
|
||||
podWithObservedGenInConditions := func() *api.PodStatus {
|
||||
return &api.PodStatus{
|
||||
Conditions: []api.PodCondition{{
|
||||
LastProbeTime: now,
|
||||
LastTransitionTime: now,
|
||||
ObservedGeneration: 1,
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
podWithoutObservedGen := func() *api.PodStatus {
|
||||
return &api.PodStatus{
|
||||
Conditions: []api.PodCondition{{
|
||||
LastProbeTime: now,
|
||||
LastTransitionTime: now,
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
podStatus *api.PodStatus
|
||||
oldPodStatus *api.PodStatus
|
||||
wantPodStatus *api.PodStatus
|
||||
}{
|
||||
{
|
||||
name: "old=without, new=without",
|
||||
oldPodStatus: podWithoutObservedGen(),
|
||||
podStatus: podWithoutObservedGen(),
|
||||
|
||||
wantPodStatus: podWithoutObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=without, new=with",
|
||||
oldPodStatus: podWithoutObservedGen(),
|
||||
podStatus: podWithObservedGen(),
|
||||
|
||||
wantPodStatus: podWithoutObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=with, new=without",
|
||||
oldPodStatus: podWithObservedGen(),
|
||||
podStatus: podWithoutObservedGen(),
|
||||
|
||||
wantPodStatus: podWithoutObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=with, new=with",
|
||||
oldPodStatus: podWithObservedGen(),
|
||||
podStatus: podWithObservedGen(),
|
||||
|
||||
wantPodStatus: podWithObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=without, new=withInConditions",
|
||||
oldPodStatus: podWithoutObservedGen(),
|
||||
podStatus: podWithObservedGenInConditions(),
|
||||
|
||||
wantPodStatus: podWithoutObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=withInConditions, new=without",
|
||||
oldPodStatus: podWithObservedGenInConditions(),
|
||||
podStatus: podWithoutObservedGen(),
|
||||
|
||||
wantPodStatus: podWithoutObservedGen(),
|
||||
},
|
||||
{
|
||||
name: "old=withInConditions, new=withInCondtions",
|
||||
oldPodStatus: podWithObservedGenInConditions(),
|
||||
podStatus: podWithObservedGenInConditions(),
|
||||
|
||||
wantPodStatus: podWithObservedGenInConditions(),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
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 TestDropNodeInclusionPolicyFields(t *testing.T) {
|
||||
ignore := api.NodeInclusionPolicyIgnore
|
||||
honor := api.NodeInclusionPolicyHonor
|
||||
|
Loading…
Reference in New Issue
Block a user