From 3434917299c5aafca38bd9ae85a3aff68b7cabf7 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Wed, 29 May 2019 19:17:42 +0200 Subject: [PATCH 1/7] Log the operator image name when created Signed-off-by: Kevin Earls --- test/e2e/utils.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/e2e/utils.go b/test/e2e/utils.go index 1f69de88d..8862e1af2 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -7,10 +7,11 @@ import ( "testing" "time" + "github.com/operator-framework/operator-sdk/pkg/test/e2eutil" + "github.com/pkg/errors" osv1 "github.com/openshift/api/route/v1" osv1sec "github.com/openshift/api/security/v1" framework "github.com/operator-framework/operator-sdk/pkg/test" - "github.com/operator-framework/operator-sdk/pkg/test/e2eutil" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -74,9 +75,36 @@ func prepare(t *testing.T) (*framework.TestCtx, error) { return nil, err } + imageName, err := getJaegerOperatorImage(f.KubeClient) + if err != nil { + return nil, err + } + t.Logf("Using jaeger-operator image %s\n", imageName) + return ctx, nil } +func getJaegerOperatorImage(kubeclient kubernetes.Interface) (string, error) { + emptyOptions := new(metav1.ListOptions) + namespaces, err := kubeclient.CoreV1().Namespaces().List(*emptyOptions) + if err != nil { + return "", err + } else { + for _, item := range namespaces.Items { + dep, err := kubeclient.AppsV1().Deployments(item.Name).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) + if err != nil { + if !strings.Contains(err.Error(), "not found") { + return "", err + } + } else { + return dep.Spec.Template.Spec.Containers[0].Image, nil + } + } + } + + return "", errors.New("Could not find the operator image") +} + func isOpenShift(t *testing.T) bool { apiList, err := availableAPIs(framework.Global.KubeConfig) if err != nil { From 26b114dc0f01684fe60a1dd45a203a466073ee67 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Thu, 30 May 2019 16:09:15 +0200 Subject: [PATCH 2/7] Add a test to confirm we are using the correct image Signed-off-by: Kevin Earls --- Makefile | 7 ++++- test/e2e/misc_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++ test/e2e/utils.go | 43 ++++++++++++++++++------------ 3 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 test/e2e/misc_test.go diff --git a/Makefile b/Makefile index 8dcccd346..2ab61dd02 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ unit-tests: @go test $(PACKAGES) -cover -coverprofile=cover.out .PHONY: e2e-tests -e2e-tests: prepare-e2e-tests e2e-tests-smoke e2e-tests-cassandra e2e-tests-es e2e-tests-self-provisioned-es e2e-tests-streaming +e2e-tests: prepare-e2e-tests e2e-tests-smoke e2e-tests-misc e2e-tests-cassandra e2e-tests-es e2e-tests-self-provisioned-es e2e-tests-streaming .PHONY: prepare-e2e-tests prepare-e2e-tests: crd build docker push @@ -111,6 +111,11 @@ e2e-tests-streaming: prepare-e2e-tests es kafka @echo Running Streaming end-to-end tests... @STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) KAFKA_NAMESPACE=$(KAFKA_NAMESPACE) go test -tags=streaming ./test/e2e/... $(TEST_OPTIONS) +.PHONY: e2e-tests-misc +e2e-tests-misc: prepare-e2e-tests + @echo Running Misc end-to-end tests... + @BUILD_IMAGE=$(BUILD_IMAGE) go test -tags=misc ./test/e2e/... $(TEST_OPTIONS) + .PHONY: run run: crd @rm -rf /tmp/_cert* diff --git a/test/e2e/misc_test.go b/test/e2e/misc_test.go new file mode 100644 index 000000000..adfd082a4 --- /dev/null +++ b/test/e2e/misc_test.go @@ -0,0 +1,62 @@ +// +build misc + +package e2e + +import ( + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + "os" + "testing" + + framework "github.com/operator-framework/operator-sdk/pkg/test" + log "github.com/sirupsen/logrus" +) + +type MiscTestSuite struct { + suite.Suite +} + +func(suite *MiscTestSuite) SetupSuite() { + t = suite.T() + var err error + ctx, err = prepare(t) + if (err != nil) { + if ctx != nil { + ctx.Cleanup() + } + require.FailNow(t, "Failed in prepare with: " + err.Error()) + } + fw = framework.Global + namespace, _ = ctx.GetNamespace() + require.NotNil(t, namespace, "GetNamespace failed") + + addToFrameworkSchemeForSmokeTests(t) +} + +func (suite *MiscTestSuite) TearDownSuite() { + log.Info("Entering TearDownSuite()") + ctx.Cleanup() +} + +func TestMiscSuite(t *testing.T) { + suite.Run(t, new(MiscTestSuite)) +} + +func (suite *MiscTestSuite) SetupTest() { + t = suite.T() +} + +// Make sure we're testing correct image +func (suite *MiscTestSuite) TestValidateBuildImage() { + buildImage := os.Getenv("BUILD_IMAGE") + require.NotEmptyf(t, buildImage, "BUILD_IMAGE must be defined") + imagesMap, err := getJaegerOperatorImages(fw.KubeClient) + require.NoError(t, err) + + // TODO update test to deal with multiple installed operators if necessary + require.Len(t, imagesMap, 1, "Expected 1 deployed operator") + + _, ok := imagesMap[buildImage] + require.Truef(t, ok, "Expected operator image %s not found in map %s\n", buildImage, imagesMap) + t.Logf("Using jaeger-operator image(s) %s\n", imagesMap) +} \ No newline at end of file diff --git a/test/e2e/utils.go b/test/e2e/utils.go index 8862e1af2..ac43cd81b 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -75,34 +75,43 @@ func prepare(t *testing.T) (*framework.TestCtx, error) { return nil, err } - imageName, err := getJaegerOperatorImage(f.KubeClient) - if err != nil { - return nil, err - } - t.Logf("Using jaeger-operator image %s\n", imageName) - return ctx, nil } -func getJaegerOperatorImage(kubeclient kubernetes.Interface) (string, error) { +// Return a map of image name to WATCH_NAMESPACE for all deployed jaeger-operators +func getJaegerOperatorImages(kubeclient kubernetes.Interface) (map[string]string, error) { + imageNamesMap := make(map[string]string) emptyOptions := new(metav1.ListOptions) namespaces, err := kubeclient.CoreV1().Namespaces().List(*emptyOptions) if err != nil { - return "", err - } else { - for _, item := range namespaces.Items { - dep, err := kubeclient.AppsV1().Deployments(item.Name).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) - if err != nil { - if !strings.Contains(err.Error(), "not found") { - return "", err + return imageNamesMap, err + } + + for _, item := range namespaces.Items { + deployment, err := kubeclient.AppsV1().Deployments(item.Name).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) + if err != nil { + if !strings.Contains(err.Error(), "not found") { + return imageNamesMap, err + } + } else { + containers := deployment.Spec.Template.Spec.Containers + for _, container := range containers { + if container.Name == "jaeger-operator" { + for _, env := range container.Env { + if env.Name == "WATCH_NAMESPACE" { + imageNamesMap[container.Image] = env.Value + } + } } - } else { - return dep.Spec.Template.Spec.Containers[0].Image, nil } } } - return "", errors.New("Could not find the operator image") + if len(imageNamesMap) == 0 { + return imageNamesMap, errors.New("Could not find the operator image") + } else { + return imageNamesMap, nil + } } func isOpenShift(t *testing.T) bool { From fee42eb76f430b18c3d147742029a692f9188c87 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Thu, 30 May 2019 16:22:22 +0200 Subject: [PATCH 3/7] Add misc tests to Travis Signed-off-by: Kevin Earls --- .travis/rune2eTests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis/rune2eTests.sh b/.travis/rune2eTests.sh index df5e53aec..47d4cca62 100755 --- a/.travis/rune2eTests.sh +++ b/.travis/rune2eTests.sh @@ -14,6 +14,8 @@ elif [ "${TEST_GROUP}" = "smoke" ] then echo "Running Smoke Tests" make e2e-tests-smoke + echo "Running Misc Tests" + make e2e-tests-misc elif [ "${TEST_GROUP}" = "cassandra" ] then echo "Running Cassandra Tests" From fb9471cca286ef2df44c2770d7fde972327e4013 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Thu, 30 May 2019 16:34:37 +0200 Subject: [PATCH 4/7] Fix import order Signed-off-by: Kevin Earls --- test/e2e/misc_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/misc_test.go b/test/e2e/misc_test.go index adfd082a4..61f72c8d3 100644 --- a/test/e2e/misc_test.go +++ b/test/e2e/misc_test.go @@ -3,11 +3,11 @@ package e2e import ( - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" "os" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" framework "github.com/operator-framework/operator-sdk/pkg/test" log "github.com/sirupsen/logrus" ) @@ -59,4 +59,4 @@ func (suite *MiscTestSuite) TestValidateBuildImage() { _, ok := imagesMap[buildImage] require.Truef(t, ok, "Expected operator image %s not found in map %s\n", buildImage, imagesMap) t.Logf("Using jaeger-operator image(s) %s\n", imagesMap) -} \ No newline at end of file +} From 3675e843246a52e8dedd838ab57fb8fb4f11a911 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Thu, 30 May 2019 16:47:18 +0200 Subject: [PATCH 5/7] Simplify by adding misc_test to smoke tests Signed-off-by: Kevin Earls --- .travis/rune2eTests.sh | 2 -- Makefile | 7 +------ test/e2e/misc_test.go | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.travis/rune2eTests.sh b/.travis/rune2eTests.sh index 47d4cca62..df5e53aec 100755 --- a/.travis/rune2eTests.sh +++ b/.travis/rune2eTests.sh @@ -14,8 +14,6 @@ elif [ "${TEST_GROUP}" = "smoke" ] then echo "Running Smoke Tests" make e2e-tests-smoke - echo "Running Misc Tests" - make e2e-tests-misc elif [ "${TEST_GROUP}" = "cassandra" ] then echo "Running Cassandra Tests" diff --git a/Makefile b/Makefile index 2ab61dd02..8dcccd346 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ unit-tests: @go test $(PACKAGES) -cover -coverprofile=cover.out .PHONY: e2e-tests -e2e-tests: prepare-e2e-tests e2e-tests-smoke e2e-tests-misc e2e-tests-cassandra e2e-tests-es e2e-tests-self-provisioned-es e2e-tests-streaming +e2e-tests: prepare-e2e-tests e2e-tests-smoke e2e-tests-cassandra e2e-tests-es e2e-tests-self-provisioned-es e2e-tests-streaming .PHONY: prepare-e2e-tests prepare-e2e-tests: crd build docker push @@ -111,11 +111,6 @@ e2e-tests-streaming: prepare-e2e-tests es kafka @echo Running Streaming end-to-end tests... @STORAGE_NAMESPACE=$(STORAGE_NAMESPACE) KAFKA_NAMESPACE=$(KAFKA_NAMESPACE) go test -tags=streaming ./test/e2e/... $(TEST_OPTIONS) -.PHONY: e2e-tests-misc -e2e-tests-misc: prepare-e2e-tests - @echo Running Misc end-to-end tests... - @BUILD_IMAGE=$(BUILD_IMAGE) go test -tags=misc ./test/e2e/... $(TEST_OPTIONS) - .PHONY: run run: crd @rm -rf /tmp/_cert* diff --git a/test/e2e/misc_test.go b/test/e2e/misc_test.go index 61f72c8d3..65f03acf9 100644 --- a/test/e2e/misc_test.go +++ b/test/e2e/misc_test.go @@ -1,4 +1,4 @@ -// +build misc +// +build smoke package e2e From 29b5aeb6a9de2bb3879e3049684f9be49f4b5e43 Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Thu, 30 May 2019 17:35:15 +0200 Subject: [PATCH 6/7] Simplify, just get operator image from deployment in current namespace Signed-off-by: Kevin Earls --- Makefile | 2 +- test/e2e/misc_test.go | 3 +-- test/e2e/utils.go | 34 +++++++++++++--------------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 8dcccd346..2d7abe83b 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ prepare-e2e-tests: crd build docker push .PHONY: e2e-tests-smoke e2e-tests-smoke: prepare-e2e-tests @echo Running Smoke end-to-end tests... - @go test -tags=smoke ./test/e2e/... $(TEST_OPTIONS) + @BUILD_IMAGE=$(BUILD_IMAGE) go test -tags=smoke ./test/e2e/... $(TEST_OPTIONS) .PHONY: e2e-tests-cassandra e2e-tests-cassandra: prepare-e2e-tests cassandra diff --git a/test/e2e/misc_test.go b/test/e2e/misc_test.go index 65f03acf9..0efa7a741 100644 --- a/test/e2e/misc_test.go +++ b/test/e2e/misc_test.go @@ -50,10 +50,9 @@ func (suite *MiscTestSuite) SetupTest() { func (suite *MiscTestSuite) TestValidateBuildImage() { buildImage := os.Getenv("BUILD_IMAGE") require.NotEmptyf(t, buildImage, "BUILD_IMAGE must be defined") - imagesMap, err := getJaegerOperatorImages(fw.KubeClient) + imagesMap, err := getJaegerOperatorImages(fw.KubeClient, namespace) require.NoError(t, err) - // TODO update test to deal with multiple installed operators if necessary require.Len(t, imagesMap, 1, "Expected 1 deployed operator") _, ok := imagesMap[buildImage] diff --git a/test/e2e/utils.go b/test/e2e/utils.go index ac43cd81b..bf903e65b 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -78,29 +78,21 @@ func prepare(t *testing.T) (*framework.TestCtx, error) { return ctx, nil } -// Return a map of image name to WATCH_NAMESPACE for all deployed jaeger-operators -func getJaegerOperatorImages(kubeclient kubernetes.Interface) (map[string]string, error) { +func getJaegerOperatorImages(kubeclient kubernetes.Interface, namespace string) (map[string]string, error) { imageNamesMap := make(map[string]string) - emptyOptions := new(metav1.ListOptions) - namespaces, err := kubeclient.CoreV1().Namespaces().List(*emptyOptions) - if err != nil { - return imageNamesMap, err - } - for _, item := range namespaces.Items { - deployment, err := kubeclient.AppsV1().Deployments(item.Name).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) - if err != nil { - if !strings.Contains(err.Error(), "not found") { - return imageNamesMap, err - } - } else { - containers := deployment.Spec.Template.Spec.Containers - for _, container := range containers { - if container.Name == "jaeger-operator" { - for _, env := range container.Env { - if env.Name == "WATCH_NAMESPACE" { - imageNamesMap[container.Image] = env.Value - } + deployment, err := kubeclient.AppsV1().Deployments(namespace).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) + if err != nil { + if !strings.Contains(err.Error(), "not found") { + return imageNamesMap, err + } + } else { + containers := deployment.Spec.Template.Spec.Containers + for _, container := range containers { + if container.Name == "jaeger-operator" { + for _, env := range container.Env { + if env.Name == "WATCH_NAMESPACE" { + imageNamesMap[container.Image] = env.Value } } } From d4967e2d8fa483ca2d0861bc64280b97606b078b Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Mon, 3 Jun 2019 09:45:36 +0200 Subject: [PATCH 7/7] Remove unneeded error check Signed-off-by: Kevin Earls --- test/e2e/utils.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/e2e/utils.go b/test/e2e/utils.go index bf903e65b..a2b466a6f 100644 --- a/test/e2e/utils.go +++ b/test/e2e/utils.go @@ -83,9 +83,7 @@ func getJaegerOperatorImages(kubeclient kubernetes.Interface, namespace string) deployment, err := kubeclient.AppsV1().Deployments(namespace).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false}) if err != nil { - if !strings.Contains(err.Error(), "not found") { - return imageNamesMap, err - } + return imageNamesMap, err } else { containers := deployment.Spec.Template.Spec.Containers for _, container := range containers {