Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log the operator image name when created #452

Merged
merged 7 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions test/e2e/misc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// +build smoke

package e2e

import (
"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"
)

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, namespace)
require.NoError(t, err)

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)
}
29 changes: 28 additions & 1 deletion test/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -77,6 +78,32 @@ func prepare(t *testing.T) (*framework.TestCtx, error) {
return ctx, nil
}

func getJaegerOperatorImages(kubeclient kubernetes.Interface, namespace string) (map[string]string, error) {
imageNamesMap := make(map[string]string)

deployment, err := kubeclient.AppsV1().Deployments(namespace).Get("jaeger-operator", metav1.GetOptions{IncludeUninitialized: false})
if err != nil {
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
}
}
}
}
}

if len(imageNamesMap) == 0 {
return imageNamesMap, errors.New("Could not find the operator image")
} else {
return imageNamesMap, nil
}
}

func isOpenShift(t *testing.T) bool {
apiList, err := availableAPIs(framework.Global.KubeConfig)
if err != nil {
Expand Down