@@ -2,6 +2,7 @@ package validate
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"log"
6
7
7
8
acnk8s "github.com/Azure/azure-container-networking/test/internal/kubernetes"
@@ -72,6 +73,10 @@ func CreateValidator(ctx context.Context, clientset *kubernetes.Clientset, confi
72
73
switch os {
73
74
case "windows" :
74
75
checks = windowsChecksMap [cni ]
76
+ err := acnk8s .RestartKubeProxyService (ctx , clientset , privilegedNamespace , privilegedLabelSelector , config )
77
+ if err != nil {
78
+ return nil , errors .Wrapf (err , "failed to restart kubeproxy" )
79
+ }
75
80
case "linux" :
76
81
checks = linuxChecksMap [cni ]
77
82
default :
@@ -99,7 +104,7 @@ func (v *Validator) Validate(ctx context.Context) error {
99
104
if v .os == "linux" {
100
105
// We are restarting the systmemd network and checking that the connectivity works after the restart. For more details: https://github.com/cilium/cilium/issues/18706
101
106
log .Printf ("Validating the restart network scenario" )
102
- err = v .ValidateRestartNetwork (ctx )
107
+ err = v .validateRestartNetwork (ctx )
103
108
if err != nil {
104
109
return errors .Wrapf (err , "failed to validate restart network scenario" )
105
110
}
@@ -117,33 +122,6 @@ func (v *Validator) ValidateStateFile(ctx context.Context) error {
117
122
return nil
118
123
}
119
124
120
- func (v * Validator ) ValidateRestartNetwork (ctx context.Context ) error {
121
- nodes , err := acnk8s .GetNodeList (ctx , v .clientset )
122
- if err != nil {
123
- return errors .Wrapf (err , "failed to get node list" )
124
- }
125
-
126
- for index := range nodes .Items {
127
- // get the privileged pod
128
- pod , err := acnk8s .GetPodsByNode (ctx , v .clientset , privilegedNamespace , privilegedLabelSelector , nodes .Items [index ].Name )
129
- if err != nil {
130
- return errors .Wrapf (err , "failed to get privileged pod" )
131
- }
132
-
133
- privelegedPod := pod .Items [0 ]
134
- // exec into the pod to get the state file
135
- _ , err = acnk8s .ExecCmdOnPod (ctx , v .clientset , privilegedNamespace , privelegedPod .Name , restartNetworkCmd , v .config )
136
- if err != nil {
137
- return errors .Wrapf (err , "failed to exec into privileged pod - %s" , privelegedPod .Name )
138
- }
139
- err = acnk8s .WaitForPodsRunning (ctx , v .clientset , "" , "" )
140
- if err != nil {
141
- return errors .Wrapf (err , "failed to wait for pods running" )
142
- }
143
- }
144
- return nil
145
- }
146
-
147
125
func (v * Validator ) validateIPs (ctx context.Context , stateFileIps stateFileIpsFunc , cmd []string , checkType , namespace , labelSelector string ) error {
148
126
log .Printf ("Validating %s state file" , checkType )
149
127
nodes , err := acnk8s .GetNodeListByLabelSelector (ctx , v .clientset , nodeSelectorMap [v .os ])
@@ -157,6 +135,9 @@ func (v *Validator) validateIPs(ctx context.Context, stateFileIps stateFileIpsFu
157
135
if err != nil {
158
136
return errors .Wrapf (err , "failed to get privileged pod" )
159
137
}
138
+ if len (pod .Items ) == 0 {
139
+ return errors .Errorf ("there are no privileged pods on node - %v" , nodes .Items [index ].Name )
140
+ }
160
141
podName := pod .Items [0 ].Name
161
142
// exec into the pod to get the state file
162
143
result , err := acnk8s .ExecCmdOnPod (ctx , v .clientset , namespace , podName , cmd , v .config )
@@ -165,7 +146,7 @@ func (v *Validator) validateIPs(ctx context.Context, stateFileIps stateFileIpsFu
165
146
}
166
147
filePodIps , err := stateFileIps (result )
167
148
if err != nil {
168
- return errors .Wrapf (err , "failed to get pod ips from state file" )
149
+ return errors .Wrapf (err , "failed to get pod ips from state file on node %v" , nodes . Items [ index ]. Name )
169
150
}
170
151
if len (filePodIps ) == 0 && v .restartCase {
171
152
log .Printf ("No pods found on node %s" , nodes .Items [index ].Name )
@@ -175,7 +156,7 @@ func (v *Validator) validateIPs(ctx context.Context, stateFileIps stateFileIpsFu
175
156
podIps := getPodIPsWithoutNodeIP (ctx , v .clientset , nodes .Items [index ])
176
157
177
158
if err := compareIPs (filePodIps , podIps ); err != nil {
178
- return errors .Wrapf (errors . New ( "State file validation failed" ), " for %s on node %s" , checkType , nodes .Items [index ].Name )
159
+ return errors .Wrapf (err , "State file validation failed for %s on node %s" , checkType , nodes .Items [index ].Name )
179
160
}
180
161
}
181
162
log .Printf ("State file validation for %s passed" , checkType )
@@ -257,36 +238,24 @@ func (v *Validator) ValidateDualStackControlPlane(ctx context.Context) error {
257
238
return nil
258
239
}
259
240
260
- func (v * Validator ) RestartKubeProxyService (ctx context.Context ) error {
261
- nodes , err := acnk8s .GetNodeList (ctx , v .clientset )
262
- if err != nil {
263
- return errors .Wrapf (err , "failed to get node list" )
264
- }
265
-
266
- for index := range nodes .Items {
267
- node := nodes .Items [index ]
268
- if node .Status .NodeInfo .OperatingSystem != string (corev1 .Windows ) {
269
- continue
270
- }
271
- // get the privileged pod
272
- pod , err := acnk8s .GetPodsByNode (ctx , v .clientset , privilegedNamespace , privilegedLabelSelector , nodes .Items [index ].Name )
273
- if err != nil {
274
- return errors .Wrapf (err , "failed to get privileged pod" )
275
- }
276
-
277
- privelegedPod := pod .Items [0 ]
278
- // exec into the pod and restart kubeproxy
279
- _ , err = acnk8s .ExecCmdOnPod (ctx , v .clientset , privilegedNamespace , privelegedPod .Name , restartKubeProxyCmd , v .config )
280
- if err != nil {
281
- return errors .Wrapf (err , "failed to exec into privileged pod - %s" , privelegedPod .Name )
282
- }
283
- }
284
- return nil
285
- }
286
-
287
241
func (v * Validator ) Cleanup (ctx context.Context ) {
288
242
// deploy privileged pod
289
243
privilegedDaemonSet := acnk8s .MustParseDaemonSet (privilegedDaemonSetPathMap [v .os ])
290
244
daemonsetClient := v .clientset .AppsV1 ().DaemonSets (privilegedNamespace )
291
245
acnk8s .MustDeleteDaemonset (ctx , daemonsetClient , privilegedDaemonSet )
292
246
}
247
+
248
+ func cnsCacheStateFileIps (result []byte ) (map [string ]string , error ) {
249
+ var cnsLocalCache CNSLocalCache
250
+
251
+ err := json .Unmarshal (result , & cnsLocalCache )
252
+ if err != nil {
253
+ return nil , errors .Wrapf (err , "failed to unmarshal cns local cache" )
254
+ }
255
+
256
+ cnsPodIps := make (map [string ]string )
257
+ for index := range cnsLocalCache .IPConfigurationStatus {
258
+ cnsPodIps [cnsLocalCache .IPConfigurationStatus [index ].IPAddress ] = cnsLocalCache .IPConfigurationStatus [index ].PodInfo .Name ()
259
+ }
260
+ return cnsPodIps , nil
261
+ }
0 commit comments