From cda03d2f270bdfb51372192766123904f6d88278 Mon Sep 17 00:00:00 2001 From: anishakj <43978302+anishakj@users.noreply.github.com> Date: Tue, 2 Mar 2021 08:39:26 +0530 Subject: [PATCH] Added more endtoend tests (#303) * Added more endtoend tests Signed-off-by: anishakj * Fixed formatting errors Signed-off-by: anishakj * Fixed secret creation Signed-off-by: anishakj * Added pull secrets Signed-off-by: anishakj --- .github/workflows/ci.yaml | 1 + go.sum | 1 + pkg/test/e2e/e2eutil/zookeepercluster_util.go | 18 +++++ test/e2e/basic_test.go | 3 + test/e2e/image_pullsecret_test.go | 67 +++++++++++++++++++ test/e2e/scale_test.go | 4 ++ test/e2e/zookeepercluster_test.go | 1 + 7 files changed, 95 insertions(+) create mode 100644 test/e2e/image_pullsecret_test.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ca8a3c48..420ae228d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,6 +54,7 @@ jobs: sudo kubectl cluster-info echo "cluster info" sudo kubectl -n kube-system get pod -o wide + sudo kubectl create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username="testanisha" --docker-password="123456789" --docker-email=testimage456@gmail.com - name: E2E run: sudo make test-e2e publish: diff --git a/go.sum b/go.sum index 178e8003e..8c19553ff 100644 --- a/go.sum +++ b/go.sum @@ -136,6 +136,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= +github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= diff --git a/pkg/test/e2e/e2eutil/zookeepercluster_util.go b/pkg/test/e2e/e2eutil/zookeepercluster_util.go index 062e68168..023e4302c 100644 --- a/pkg/test/e2e/e2eutil/zookeepercluster_util.go +++ b/pkg/test/e2e/e2eutil/zookeepercluster_util.go @@ -231,3 +231,21 @@ func DeletePods(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, z } return nil } +func CheckAdminService(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, z *api.ZookeeperCluster) error { + listOptions := metav1.ListOptions{ + LabelSelector: labels.SelectorFromSet(map[string]string{"app": z.GetName()}).String(), + } + serviceList, err := f.KubeClient.CoreV1().Services(z.Namespace).List(listOptions) + if err != nil { + return err + } + + for _, sn := range serviceList.Items { + if sn.Name == "zookeeper-admin-server" { + t.Logf("Admin service is enabled") + t.Logf("servicenameis %v", sn.Name) + return nil + } + } + return fmt.Errorf("Admin Service is not enabled") +} diff --git a/test/e2e/basic_test.go b/test/e2e/basic_test.go index de5f49d51..f66deb759 100644 --- a/test/e2e/basic_test.go +++ b/test/e2e/basic_test.go @@ -48,6 +48,9 @@ func testCreateRecreateCluster(t *testing.T) { err = zk_e2eutil.WaitForClusterToBecomeReady(t, f, ctx, zk, podSize) g.Expect(err).NotTo(HaveOccurred()) + err = zk_e2eutil.CheckAdminService(t, f, ctx, zk) + g.Expect(err).NotTo(HaveOccurred()) + err = zk_e2eutil.DeleteCluster(t, f, ctx, zk) g.Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/image_pullsecret_test.go b/test/e2e/image_pullsecret_test.go new file mode 100644 index 000000000..f3b48e8e5 --- /dev/null +++ b/test/e2e/image_pullsecret_test.go @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + +package e2e + +import ( + "testing" + + . "github.com/onsi/gomega" + framework "github.com/operator-framework/operator-sdk/pkg/test" + zk_e2eutil "github.com/pravega/zookeeper-operator/pkg/test/e2e/e2eutil" + v1 "k8s.io/api/core/v1" +) + +// Test create and recreate a Zookeeper cluster with the same name +func testImagePullSecret(t *testing.T) { + g := NewGomegaWithT(t) + + doCleanup := true + ctx := framework.NewTestCtx(t) + defer func() { + if doCleanup { + ctx.Cleanup() + } + }() + + namespace, err := ctx.GetNamespace() + g.Expect(err).NotTo(HaveOccurred()) + f := framework.Global + + defaultCluster := zk_e2eutil.NewDefaultCluster(namespace) + + defaultCluster.WithDefaults() + defaultCluster.Status.Init() + defaultCluster.Spec.Persistence.VolumeReclaimPolicy = "Delete" + defaultCluster.Spec.Image.Repository = "testanisha/zookeeper" + defaultCluster.Spec.Image.Tag = "checksecret_1" + defaultCluster.Spec.Pod.ImagePullSecrets = []v1.LocalObjectReference{ + { + Name: "regcred", + }, + } + zk, err := zk_e2eutil.CreateCluster(t, f, ctx, defaultCluster) + g.Expect(err).NotTo(HaveOccurred()) + + // A default Zookeeper cluster should have 3 replicas + podSize := 3 + err = zk_e2eutil.WaitForClusterToBecomeReady(t, f, ctx, zk, podSize) + g.Expect(err).NotTo(HaveOccurred()) + + err = zk_e2eutil.CheckAdminService(t, f, ctx, zk) + g.Expect(err).NotTo(HaveOccurred()) + + err = zk_e2eutil.DeleteCluster(t, f, ctx, zk) + g.Expect(err).NotTo(HaveOccurred()) + + err = zk_e2eutil.WaitForClusterToTerminate(t, f, ctx, zk) + g.Expect(err).NotTo(HaveOccurred()) + +} diff --git a/test/e2e/scale_test.go b/test/e2e/scale_test.go index 2ce513010..603761427 100644 --- a/test/e2e/scale_test.go +++ b/test/e2e/scale_test.go @@ -60,6 +60,10 @@ func testScaleCluster(t *testing.T) { err = zk_e2eutil.UpdateCluster(t, f, ctx, zk) g.Expect(err).NotTo(HaveOccurred()) + podDeleteCount := 2 + err = zk_e2eutil.DeletePods(t, f, ctx, zk, podDeleteCount) + g.Expect(err).NotTo(HaveOccurred()) + err = zk_e2eutil.WaitForClusterToBecomeReady(t, f, ctx, zk, podSize) g.Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/zookeepercluster_test.go b/test/e2e/zookeepercluster_test.go index b708c79f5..b378b3220 100644 --- a/test/e2e/zookeepercluster_test.go +++ b/test/e2e/zookeepercluster_test.go @@ -61,6 +61,7 @@ func testZookeeperCluster(t *testing.T) { "testMultiZKCluster": testMultiZKCluster, "testUpgradeCluster": testUpgradeCluster, "testCreateRecreateCluster": testCreateRecreateCluster, + "testImagePullSecret": testImagePullSecret, "testScaleCluster": testScaleCluster, "testEphemeralStorage": testEphemeralStorage, }