@@ -43,14 +43,11 @@ import (
43
43
"k8s.io/apimachinery/pkg/util/strategicpatch"
44
44
"k8s.io/apimachinery/pkg/util/uuid"
45
45
"k8s.io/apimachinery/pkg/util/wait"
46
- utilfeature "k8s.io/apiserver/pkg/util/feature"
47
46
clientset "k8s.io/client-go/kubernetes"
48
47
"k8s.io/client-go/kubernetes/fake"
49
48
"k8s.io/client-go/rest"
50
49
core "k8s.io/client-go/testing"
51
- featuregatetesting "k8s.io/component-base/featuregate/testing"
52
50
"k8s.io/component-base/version"
53
- "k8s.io/kubernetes/pkg/features"
54
51
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
55
52
cadvisortest "k8s.io/kubernetes/pkg/kubelet/cadvisor/testing"
56
53
"k8s.io/kubernetes/pkg/kubelet/cm"
@@ -786,8 +783,6 @@ func TestUpdateNodeStatusError(t *testing.T) {
786
783
}
787
784
788
785
func TestUpdateNodeStatusWithLease (t * testing.T ) {
789
- defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .NodeLease , true )()
790
-
791
786
testKubelet := newTestKubelet (t , false /* controllerAttachDetachEnabled */ )
792
787
defer testKubelet .Cleanup ()
793
788
clock := testKubelet .fakeClock
@@ -1020,116 +1015,7 @@ func TestUpdateNodeStatusWithLease(t *testing.T) {
1020
1015
assert .IsType (t , core.GetActionImpl {}, actions [9 ])
1021
1016
}
1022
1017
1023
- func TestUpdateNodeStatusAndVolumesInUseWithoutNodeLease (t * testing.T ) {
1024
- defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .NodeLease , false )()
1025
-
1026
- cases := []struct {
1027
- desc string
1028
- existingVolumes []v1.UniqueVolumeName // volumes to initially populate volumeManager
1029
- existingNode * v1.Node // existing node object
1030
- expectedNode * v1.Node // new node object after patch
1031
- expectedReportedInUse []v1.UniqueVolumeName // expected volumes reported in use in volumeManager
1032
- }{
1033
- {
1034
- desc : "no volumes and no update" ,
1035
- existingNode : & v1.Node {ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname }},
1036
- expectedNode : & v1.Node {ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname }},
1037
- },
1038
- {
1039
- desc : "volumes inuse on node and volumeManager" ,
1040
- existingVolumes : []v1.UniqueVolumeName {"vol1" },
1041
- existingNode : & v1.Node {
1042
- ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname },
1043
- Status : v1.NodeStatus {
1044
- VolumesInUse : []v1.UniqueVolumeName {"vol1" },
1045
- },
1046
- },
1047
- expectedNode : & v1.Node {
1048
- ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname },
1049
- Status : v1.NodeStatus {
1050
- VolumesInUse : []v1.UniqueVolumeName {"vol1" },
1051
- },
1052
- },
1053
- expectedReportedInUse : []v1.UniqueVolumeName {"vol1" },
1054
- },
1055
- {
1056
- desc : "volumes inuse on node but not in volumeManager" ,
1057
- existingNode : & v1.Node {
1058
- ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname },
1059
- Status : v1.NodeStatus {
1060
- VolumesInUse : []v1.UniqueVolumeName {"vol1" },
1061
- },
1062
- },
1063
- expectedNode : & v1.Node {ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname }},
1064
- },
1065
- {
1066
- desc : "volumes inuse in volumeManager but not on node" ,
1067
- existingVolumes : []v1.UniqueVolumeName {"vol1" },
1068
- existingNode : & v1.Node {ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname }},
1069
- expectedNode : & v1.Node {
1070
- ObjectMeta : metav1.ObjectMeta {Name : testKubeletHostname },
1071
- Status : v1.NodeStatus {
1072
- VolumesInUse : []v1.UniqueVolumeName {"vol1" },
1073
- },
1074
- },
1075
- expectedReportedInUse : []v1.UniqueVolumeName {"vol1" },
1076
- },
1077
- }
1078
-
1079
- for _ , tc := range cases {
1080
- t .Run (tc .desc , func (t * testing.T ) {
1081
- // Setup
1082
- testKubelet := newTestKubelet (t , false /* controllerAttachDetachEnabled */ )
1083
- defer testKubelet .Cleanup ()
1084
-
1085
- kubelet := testKubelet .kubelet
1086
- kubelet .kubeClient = nil // ensure only the heartbeat client is used
1087
- kubelet .containerManager = & localCM {ContainerManager : cm .NewStubContainerManager ()}
1088
- kubelet .lastStatusReportTime = kubelet .clock .Now ()
1089
- kubelet .nodeStatusReportFrequency = time .Hour
1090
- kubelet .machineInfo = & cadvisorapi.MachineInfo {}
1091
-
1092
- // override test volumeManager
1093
- fakeVolumeManager := kubeletvolume .NewFakeVolumeManager (tc .existingVolumes )
1094
- kubelet .volumeManager = fakeVolumeManager
1095
-
1096
- // Only test VolumesInUse setter
1097
- kubelet .setNodeStatusFuncs = []func (* v1.Node ) error {
1098
- nodestatus .VolumesInUse (kubelet .volumeManager .ReconcilerStatesHasBeenSynced ,
1099
- kubelet .volumeManager .GetVolumesInUse ),
1100
- }
1101
-
1102
- kubeClient := testKubelet .fakeKubeClient
1103
- kubeClient .ReactionChain = fake .NewSimpleClientset (& v1.NodeList {Items : []v1.Node {* tc .existingNode }}).ReactionChain
1104
-
1105
- // Execute
1106
- assert .NoError (t , kubelet .updateNodeStatus ())
1107
-
1108
- // Validate
1109
- actions := kubeClient .Actions ()
1110
- if tc .expectedNode != nil {
1111
- assert .Len (t , actions , 2 )
1112
- assert .IsType (t , core.GetActionImpl {}, actions [0 ])
1113
- assert .IsType (t , core.PatchActionImpl {}, actions [1 ])
1114
- patchAction := actions [1 ].(core.PatchActionImpl )
1115
-
1116
- updatedNode , err := applyNodeStatusPatch (tc .existingNode , patchAction .GetPatch ())
1117
- require .NoError (t , err )
1118
- assert .True (t , apiequality .Semantic .DeepEqual (tc .expectedNode , updatedNode ), "%s" , diff .ObjectDiff (tc .expectedNode , updatedNode ))
1119
- } else {
1120
- assert .Len (t , actions , 1 )
1121
- assert .IsType (t , core.GetActionImpl {}, actions [0 ])
1122
- }
1123
-
1124
- reportedInUse := fakeVolumeManager .GetVolumesReportedInUse ()
1125
- assert .True (t , apiequality .Semantic .DeepEqual (tc .expectedReportedInUse , reportedInUse ), "%s" , diff .ObjectDiff (tc .expectedReportedInUse , reportedInUse ))
1126
- })
1127
- }
1128
- }
1129
-
1130
1018
func TestUpdateNodeStatusAndVolumesInUseWithNodeLease (t * testing.T ) {
1131
- defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .NodeLease , true )()
1132
-
1133
1019
cases := []struct {
1134
1020
desc string
1135
1021
existingVolumes []v1.UniqueVolumeName // volumes to initially populate volumeManager
0 commit comments