From 24df623049283d93830a8cceeba48254bfc813ec Mon Sep 17 00:00:00 2001 From: hetong07 Date: Thu, 4 Mar 2021 16:01:26 -0800 Subject: [PATCH] Multinode-test: create 2 pods deployment and validate the DNS is available to them. --- test/integration/multinode_test.go | 49 +++++++++++++++++++ .../multinodes/multinode-test-deployment.yaml | 32 ++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/integration/testdata/multinodes/multinode-test-deployment.yaml diff --git a/test/integration/multinode_test.go b/test/integration/multinode_test.go index 369bb0067a..0f28354238 100644 --- a/test/integration/multinode_test.go +++ b/test/integration/multinode_test.go @@ -45,6 +45,7 @@ func TestMultiNode(t *testing.T) { validator validatorFunc }{ {"FreshStart2Nodes", validateMultiNodeStart}, + {"DeployApp2Nodes", validateDeployAppToMultiNode}, {"AddNode", validateAddNodeToMultiNode}, {"ProfileList", validateProfileListWithMultiNode}, {"StopNode", validateStopRunningNode}, @@ -387,3 +388,51 @@ func validatNameConflict(ctx context.Context, t *testing.T, profile string) { t.Logf("failed to clean temporary profile. args %q : %v", rr.Command(), err) } } + +func validateDeployAppToMultiNode(ctx context.Context, t *testing.T, profile string) { + // Create a deployment for app + _, err := Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "apply", "-f", "./testdata/multinodes/multinode-test-deployment.yaml")) + if err != nil { + t.Errorf("failed to create hello deployment to multinode cluster") + } + + _, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "rollout", "status", "deployment/hello")) + if err != nil { + t.Errorf("failed to delploy hello to multinode cluster") + } + + // resolve Pod IPs + rr, err := Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].status.podIP}'")) + if err != nil { + t.Errorf("failed retrieve Pod IPs") + } + podIPs := strings.Split(strings.Trim(rr.Stdout.String(), "'"), " ") + if len(podIPs) != 2 { + t.Errorf("expected 2 Pod IPs but got %d", len(podIPs)) + } + if podIPs[0] == podIPs[1] { + t.Errorf("expected 2 different pod IPs but got %s and %s", podIPs[0], podIPs[0]) + } + + // get Pod names + rr, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "get", "pods", "-o", "jsonpath='{.items[*].metadata.name}'")) + if err != nil { + t.Errorf("failed get Pod names") + } + podNames := strings.Split(strings.Trim(rr.Stdout.String(), "'"), " ") + + // verify both Pods could resolve a public DNS + for _, name := range podNames { + _, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "--", "exec", name, "nslookup", "kubernetes.io")) + if err != nil { + t.Errorf("Pod %s could not resolve 'kubernetes.io': %v", name, err) + } + } + // clean up, delete all pods + for _, name := range podNames { + _, err = Run(t, exec.CommandContext(ctx, Target(), "kubectl", "-p", profile, "delete", "pod", name)) + if err != nil { + t.Errorf("fail to delete pod %s: %v", name, err) + } + } +} diff --git a/test/integration/testdata/multinodes/multinode-test-deployment.yaml b/test/integration/testdata/multinodes/multinode-test-deployment.yaml new file mode 100644 index 0000000000..e16f632c60 --- /dev/null +++ b/test/integration/testdata/multinodes/multinode-test-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello +spec: + replicas: 2 + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 100% + selector: + matchLabels: + app: hello + template: + metadata: + labels: + app: hello + spec: + affinity: + # ⬇⬇⬇ This ensures pods will land on separate hosts + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: [{ key: app, operator: In, values: [hello-from] }] + topologyKey: "kubernetes.io/hostname" + containers: + - name: hello-from + image: pbitty/hello-from:latest + ports: + - name: http + containerPort: 80 + terminationGracePeriodSeconds: 1