@@ -23,17 +23,20 @@ import (
23
23
"path/filepath"
24
24
"time"
25
25
26
- "k8s.io/api/core/v1"
26
+ v1 "k8s.io/api/core/v1"
27
+ apiequality "k8s.io/apimachinery/pkg/api/equality"
27
28
"k8s.io/apimachinery/pkg/api/errors"
28
29
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
30
"k8s.io/apimachinery/pkg/types"
30
31
"k8s.io/apimachinery/pkg/util/uuid"
31
32
clientset "k8s.io/client-go/kubernetes"
33
+ kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
32
34
"k8s.io/kubernetes/test/e2e/framework"
35
+ imageutils "k8s.io/kubernetes/test/utils/image"
33
36
37
+ "github.com/google/go-cmp/cmp"
34
38
"github.com/onsi/ginkgo"
35
39
"github.com/onsi/gomega"
36
- imageutils "k8s.io/kubernetes/test/utils/image"
37
40
)
38
41
39
42
var _ = framework .KubeDescribe ("MirrorPod" , func () {
@@ -188,7 +191,7 @@ func checkMirrorPodRunning(cl clientset.Interface, name, namespace string) error
188
191
if pod .Status .Phase != v1 .PodRunning {
189
192
return fmt .Errorf ("expected the mirror pod %q to be running, got %q" , name , pod .Status .Phase )
190
193
}
191
- return nil
194
+ return validateMirrorPod ( cl , pod )
192
195
}
193
196
194
197
func checkMirrorPodRecreatedAndRunning (cl clientset.Interface , name , namespace string , oUID types.UID ) error {
@@ -202,5 +205,49 @@ func checkMirrorPodRecreatedAndRunning(cl clientset.Interface, name, namespace s
202
205
if pod .Status .Phase != v1 .PodRunning {
203
206
return fmt .Errorf ("expected the mirror pod %q to be running, got %q" , name , pod .Status .Phase )
204
207
}
208
+ return validateMirrorPod (cl , pod )
209
+ }
210
+
211
+ func validateMirrorPod (cl clientset.Interface , mirrorPod * v1.Pod ) error {
212
+ hash , ok := mirrorPod .Annotations [kubetypes .ConfigHashAnnotationKey ]
213
+ if ! ok || hash == "" {
214
+ return fmt .Errorf ("expected mirror pod %q to have a hash annotation" , mirrorPod .Name )
215
+ }
216
+ mirrorHash , ok := mirrorPod .Annotations [kubetypes .ConfigMirrorAnnotationKey ]
217
+ if ! ok || mirrorHash == "" {
218
+ return fmt .Errorf ("expected mirror pod %q to have a mirror pod annotation" , mirrorPod .Name )
219
+ }
220
+ if hash != mirrorHash {
221
+ return fmt .Errorf ("expected mirror pod %q to have a matching mirror pod hash: got %q; expected %q" , mirrorPod .Name , mirrorHash , hash )
222
+ }
223
+ source , ok := mirrorPod .Annotations [kubetypes .ConfigSourceAnnotationKey ]
224
+ if ! ok {
225
+ return fmt .Errorf ("expected mirror pod %q to have a source annotation" , mirrorPod .Name )
226
+ }
227
+ if source == kubetypes .ApiserverSource {
228
+ return fmt .Errorf ("expected mirror pod %q source to not be 'api'; got: %q" , mirrorPod .Name , source )
229
+ }
230
+
231
+ if len (mirrorPod .OwnerReferences ) != 1 {
232
+ return fmt .Errorf ("expected mirror pod %q to have a single owner reference: got %d" , mirrorPod .Name , len (mirrorPod .OwnerReferences ))
233
+ }
234
+ node , err := cl .CoreV1 ().Nodes ().Get (framework .TestContext .NodeName , metav1.GetOptions {})
235
+ if err != nil {
236
+ return fmt .Errorf ("failed to fetch test node: %v" , err )
237
+ }
238
+
239
+ controller := true
240
+ expectedOwnerRef := metav1.OwnerReference {
241
+ APIVersion : "v1" ,
242
+ Kind : "Node" ,
243
+ Name : framework .TestContext .NodeName ,
244
+ UID : node .UID ,
245
+ Controller : & controller ,
246
+ }
247
+ ref := mirrorPod .OwnerReferences [0 ]
248
+ if ! apiequality .Semantic .DeepEqual (ref , expectedOwnerRef ) {
249
+ return fmt .Errorf ("unexpected mirror pod %q owner ref: %v" , mirrorPod .Name , cmp .Diff (expectedOwnerRef , ref ))
250
+ }
251
+
205
252
return nil
206
253
}
0 commit comments