Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Feb 27, 2024
1 parent 30e3e17 commit 0b1484d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 215 deletions.
71 changes: 16 additions & 55 deletions pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,81 +1179,42 @@ func TestDropDisabledPodStatusFields(t *testing.T) {
}

tests := []struct {
name string
podStatus *api.PodStatus
oldPodStatus *api.PodStatus
wantPodStatus *api.PodStatus
featureEnabled bool
name string
podStatus *api.PodStatus
oldPodStatus *api.PodStatus
wantPodStatus *api.PodStatus
}{
{
name: "gate off, old=without, new=without",
oldPodStatus: podWithoutHostIPs(),
podStatus: podWithoutHostIPs(),
featureEnabled: false,
name: "gate on, old=without, new=without",
oldPodStatus: podWithoutHostIPs(),
podStatus: podWithoutHostIPs(),

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,
name: "gate on, old=without, new=with",
oldPodStatus: podWithoutHostIPs(),
podStatus: podWithHostIPs(),

wantPodStatus: podWithHostIPs(),
},
{
name: "gate on, old=without, new=without",
oldPodStatus: podWithoutHostIPs(),
podStatus: podWithoutHostIPs(),
featureEnabled: true,
name: "gate on, old=with, new=without",
oldPodStatus: podWithHostIPs(),
podStatus: podWithoutHostIPs(),

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,
name: "gate on, old=with, new=with",
oldPodStatus: podWithHostIPs(),
podStatus: podWithHostIPs(),

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) {
Expand Down
12 changes: 0 additions & 12 deletions pkg/apis/core/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24590,18 +24590,6 @@ func TestValidateDownwardAPIHostIPs(t *testing.T) {
featureEnabled: true,
fieldSel: &core.ObjectFieldSelector{FieldPath: "status.hostIPs"},
},
{
name: "has no hostIPs field, featuregate disabled",
expectError: false,
featureEnabled: false,
fieldSel: &core.ObjectFieldSelector{FieldPath: "status.hostIP"},
},
{
name: "has hostIPs field, featuregate disabled",
expectError: true,
featureEnabled: false,
fieldSel: &core.ObjectFieldSelector{FieldPath: "status.hostIPs"},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
Expand Down
41 changes: 1 addition & 40 deletions pkg/kubelet/kubelet_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ func TestMakeEnvironmentVariables(t *testing.T) {
testCases := []struct {
name string // the name of the test case
ns string // the namespace to generate environment for
enablePodHostIPs bool // enable PodHostIPs feature gate
enableServiceLinks *bool // enabling service links
container *v1.Container // the container to use
nilLister bool // whether the lister should be nil
Expand Down Expand Up @@ -643,7 +642,6 @@ func TestMakeEnvironmentVariables(t *testing.T) {
},
{
name: "downward api pod",
enablePodHostIPs: true,
ns: "downward-api",
enableServiceLinks: &falseValue,
container: &v1.Container{
Expand Down Expand Up @@ -737,7 +735,6 @@ func TestMakeEnvironmentVariables(t *testing.T) {
},
{
name: "downward api pod ips reverse order",
enablePodHostIPs: true,
ns: "downward-api",
enableServiceLinks: &falseValue,
container: &v1.Container{
Expand Down Expand Up @@ -791,7 +788,6 @@ func TestMakeEnvironmentVariables(t *testing.T) {
},
{
name: "downward api pod ips multiple ips",
enablePodHostIPs: true,
ns: "downward-api",
enableServiceLinks: &falseValue,
container: &v1.Container{
Expand Down Expand Up @@ -1988,36 +1984,10 @@ func TestMakeEnvironmentVariables(t *testing.T) {
},
expectedError: true,
},
{
name: "downward api pod without host ips",
enablePodHostIPs: false,
ns: "downward-api",
enableServiceLinks: &falseValue,
container: &v1.Container{
Env: []v1.EnvVar{
{
Name: "HOST_IPS",
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "status.hostIPs",
},
},
},
},
},
podIPs: []string{"1.2.3.4", "fd00::6"},
nilLister: true,
expectedEnvs: []kubecontainer.EnvVar{
{Name: "HOST_IPS", Value: ""},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, tc.enablePodHostIPs)()

fakeRecorder := record.NewFakeRecorder(1)
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
testKubelet.kubelet.recorder = fakeRecorder
Expand Down Expand Up @@ -3304,7 +3274,6 @@ func Test_generateAPIPodStatus(t *testing.T) {

tests := []struct {
name string
enablePodHostIPs bool // enable PodHostIPs feature gate
pod *v1.Pod
currentStatus *kubecontainer.PodStatus
unreadyContainer []string
Expand Down Expand Up @@ -3349,6 +3318,7 @@ func Test_generateAPIPodStatus(t *testing.T) {
expected: v1.PodStatus{
Phase: v1.PodFailed,
HostIP: "127.0.0.1",
HostIPs: []v1.HostIP{{IP: "127.0.0.1"}, {IP: "::1"}},
QOSClass: v1.PodQOSBestEffort,
Conditions: []v1.PodCondition{
{Type: v1.PodInitialized, Status: v1.ConditionTrue},
Expand Down Expand Up @@ -3390,7 +3360,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
runningState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodRunning,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3430,7 +3399,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
runningState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodRunning,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3471,7 +3439,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
runningState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodSucceeded,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3516,7 +3483,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
Reason: "Test",
Message: "test",
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodSucceeded,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3570,7 +3536,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
Reason: "Test",
Message: "test",
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodSucceeded,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3613,7 +3578,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
waitingState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodPending,
HostIP: "127.0.0.1",
Expand Down Expand Up @@ -3667,7 +3631,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
runningState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodPending,
Reason: "Test",
Expand Down Expand Up @@ -3729,7 +3692,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
runningState("containerB"),
},
},
enablePodHostIPs: true,
expected: v1.PodStatus{
Phase: v1.PodRunning,
HostIP: "127.0.0.1",
Expand All @@ -3756,7 +3718,6 @@ func Test_generateAPIPodStatus(t *testing.T) {
for _, enablePodReadyToStartContainersCondition := range []bool{false, true} {
t.Run(test.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodDisruptionConditions, test.enablePodDisruptionConditions)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, test.enablePodHostIPs)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodReadyToStartContainersCondition, enablePodReadyToStartContainersCondition)()
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
defer testKubelet.Cleanup()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/network/dual_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var _ = common.SIGDescribe(feature.IPv6DualStack, func() {
framework.ExpectNoError(err, "failed to delete pod")
})

f.It("should create pod, add ipv6 and ipv4 ip to host ips", feature.PodHostIPs, func(ctx context.Context) {
f.It("should create pod, add ipv6 and ipv4 ip to host ips", func(ctx context.Context) {
podName := "pod-dualstack-ips"

pod := &v1.Pod{
Expand Down
Loading

0 comments on commit 0b1484d

Please sign in to comment.