Skip to content

Commit 62e7d19

Browse files
committed
Add mirror pod e2e test
1 parent f827863 commit 62e7d19

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

test/e2e_node/mirror_pod_test.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ import (
2323
"path/filepath"
2424
"time"
2525

26-
"k8s.io/api/core/v1"
26+
v1 "k8s.io/api/core/v1"
27+
apiequality "k8s.io/apimachinery/pkg/api/equality"
2728
"k8s.io/apimachinery/pkg/api/errors"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/apimachinery/pkg/types"
3031
"k8s.io/apimachinery/pkg/util/uuid"
3132
clientset "k8s.io/client-go/kubernetes"
33+
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
3234
"k8s.io/kubernetes/test/e2e/framework"
35+
imageutils "k8s.io/kubernetes/test/utils/image"
3336

37+
"github.com/google/go-cmp/cmp"
3438
"github.com/onsi/ginkgo"
3539
"github.com/onsi/gomega"
36-
imageutils "k8s.io/kubernetes/test/utils/image"
3740
)
3841

3942
var _ = framework.KubeDescribe("MirrorPod", func() {
@@ -188,7 +191,7 @@ func checkMirrorPodRunning(cl clientset.Interface, name, namespace string) error
188191
if pod.Status.Phase != v1.PodRunning {
189192
return fmt.Errorf("expected the mirror pod %q to be running, got %q", name, pod.Status.Phase)
190193
}
191-
return nil
194+
return validateMirrorPod(cl, pod)
192195
}
193196

194197
func checkMirrorPodRecreatedAndRunning(cl clientset.Interface, name, namespace string, oUID types.UID) error {
@@ -202,5 +205,49 @@ func checkMirrorPodRecreatedAndRunning(cl clientset.Interface, name, namespace s
202205
if pod.Status.Phase != v1.PodRunning {
203206
return fmt.Errorf("expected the mirror pod %q to be running, got %q", name, pod.Status.Phase)
204207
}
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+
205252
return nil
206253
}

0 commit comments

Comments
 (0)