Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Create Makefile target to install operator & test #33

Merged
merged 27 commits into from
Apr 1, 2019

Conversation

Avni-Sharma
Copy link
Contributor

@Avni-Sharma Avni-Sharma commented Mar 21, 2019

Refer: https://jira.coreos.com/browse/ODC-189

This pull request introduces a new Makefile target to run the Operator Lifecycle Manager (OLM) integration test. The target is test-olm-integration, and you can run it like this:

make test-olm-integration

Before running the above, you should set environment variables listed here:

export QUAY_USERNAME=
export QUAY_PASSWORD=
export DEVCONSOLE_OPERATOR_IMAGE=quay.io/<username>/devconsole-operator
export DEVCONSOLE_OPERATOR_REGISTRY_IMAGE=quay.io/<username>/operator-registry

The QUAY_USERNAME and QUAY_PASSWORD is used to login to Quay. The DEVCONSOLE_OPERATOR_IMAGE environment variable is pointing to the operator image location without the tag. TheDEVCONSOLE_OPERATOR_REGISTRY_IMAGE is pointing to the registry image without the tag.

@centos-ci
Copy link

Can one of the admins verify this patch?

@Avni-Sharma
Copy link
Contributor Author

This is a draft. There are a few hard coded variables which need to be fixed. The operator image should be available as a prerequisite for this PR.
I would like to get feedback on the approach taken here.

@baijum baijum requested a review from kwk March 21, 2019 13:08
@@ -127,6 +127,53 @@ e2e-cleanup:
oc login -u system:admin
oc delete project devconsole-e2e-test || true

.PHONY: test-olm-integration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this to a bash script and call it from here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefiles and complicated scripts are not best friends. But if you can split those make targets into multiple ones that depend on each other, it is superior to having a big bash file IMHO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will split it into smaller multiple targets.

@@ -127,6 +127,53 @@ e2e-cleanup:
oc login -u system:admin
oc delete project devconsole-e2e-test || true

.PHONY: test-olm-integration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefiles and complicated scripts are not best friends. But if you can split those make targets into multiple ones that depend on each other, it is superior to having a big bash file IMHO.

make/test.mk Outdated
cp $(CUR_DIR)/manifests/devopsconsole/$(devopsconsole_version)/$(devopsconsole_csv).clusterserviceversion.yaml $(CUR_DIR)/devopsconsole_tmp.yaml

sed -e "s,REPLACE_IMAGE,quay.io/baijum/devopsconsole-operator:0.1.0," -i $(CUR_DIR)/manifests/devopsconsole/${devopsconsole_version}/${devopsconsole_csv}.clusterserviceversion.yaml
docker build -f $(CUR_DIR)/test/olm/Dockerfile $(CUR_DIR) -t $(DEVOPSCONSOLE_OPERATOR_REGISTRY):$(devopsconsole_version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we have multiple more simply steps that are testable on their own? For example, build the docker image, then you can do docker images to see if it is there. If this remains in a makefile I think we should have targets depend on each other.
If one of those commands in this target fails, you probably have a hard time finding out how to test only one bit in particular.

make/test.mk Outdated

operator-sdk test local ./test/olm/ --go-test-flags "-v -parallel=1"

#TODO: the below command should be replaced with the actual test command.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use #TODO(Avni-Sharma): ... to help others know that it is @Avni-Sharma who's supposed to fix this or who added this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

make/test.mk Outdated
#TODO: the below command should be replaced with the actual test command.
#go test ./test/olm/... -root=$(PWD) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/test/global-manifests.yaml -namespacedMan deploy/test/namespace-manifests.yaml -v -parallel=1 -singleNamespace

# .PHONY: olm-integration-setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I meant by have the make targets depend on each other.

@sbose78
Copy link
Member

sbose78 commented Mar 22, 2019

/shrug

Following the operator-sdk testing framework. Referred Corrine's/Tina's PR.
Copy link
Member

@sbose78 sbose78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I spent quite some time debugging the absence of a rolebinding which was present in deploy/.. but absent when deployed using the registry.

And then I realized that our csv yaml needed a fix.

Doesn't necessarily have to be a part of this PR, but a validation to check if the service account can see relevant resources in a different namespace is going to be very useful.

make/test.mk Outdated
oc login -u system:admin
oc create -f https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/master/deploy/upstream/quickstart/olm.yaml
#Baiju's image. Replace it with the actual image
$(eval image := "quay.io/baijum/devopsconsole-operator:0.1.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, you could tag it as quay.io/redhat-developers/devopsconsole-operator:test{commitid}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be coming through DEVOPSCONSOLE_OPERATOR_IMAGE environment variable

make/test.mk Outdated

#oc tag 172.30.1.1:5000/$(namespace)/operator-registry:latest $(DEVOPSCONSOLE_OPERATOR_REGISTRY):$(devopsconsole_version)
sed -e "s,REPLACE_IMAGE,$(DEVOPSCONSOLE_OPERATOR_REGISTRY):$(devopsconsole_version)," $(CUR_DIR)/test/olm/catalog_source.yaml | oc create -f -
oc create -f $(CUR_DIR)/test/olm/subscription.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The creation of the CatalogSource is missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous line creates CatalogSource.

make/test.mk Outdated
oc create -f $(CUR_DIR)/test/olm/subscription.yaml
sleep 1m
oc get catalogsources -n olm
oc get subscriptions -n operators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate the status of the subscription?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. and valid that the 'deployment' is 'ready'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All validation will be moved to test written in Go.

make/test.mk Outdated

# .PHONY: olm-integration-setup
# olm-integration-setup: e2e-cleanup
# oc new-project devconsole-e2e-test || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, it has been seen that deletion of the namespace at the end of the test takes time , which sometimes blocks the next test run because creation of the namespace with the same name is attempted.

You could consider creating a unique namespace name every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ideally when should a cleanup happen?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create a namespace with a random string appended to it "devconsole-e2e-test-xyz" and delete it. Let the 'garbage collection' happen at its own pace by openshift.

@baijum baijum changed the title Makefile script to install the operator and test Create Makefile target to install operator & test Mar 26, 2019
make/test.mk Outdated
@@ -88,6 +88,9 @@ ALL_PKGS_EXCLUDE_PATTERN = 'vendor\|app\|tool\/cli\|design\|client\|test'
GOANALYSIS_PKGS_EXCLUDE_PATTERN="vendor|app|client|tool/cli"
GOANALYSIS_DIRS=$(shell go list -f {{.Dir}} ./... | grep -v -E $(GOANALYSIS_PKGS_EXCLUDE_PATTERN))

RANDOM := $(shell uuidgen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once PR #34 is merged, remove this line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed duplicate.

@baijum baijum marked this pull request as ready for review March 27, 2019 06:52
@sbose78
Copy link
Member

sbose78 commented Mar 27, 2019

/assign @baijum

Copy link
Member

@baijum baijum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Avni-Sharma Let's wait for one more approval before merging.

make/test.mk Outdated
@docker login -u $(QUAY_USERNAME) -p $(QUAY_PASSWORD) $(REGISTRY_URI)
docker push $(DEVOPSCONSOLE_OPERATOR_REGISTRY_IMAGE):$(devopsconsole_version)

sed -e "s,REPLACE_IMAGE,$(DEVOPSCONSOLE_OPERATOR_REGISTRY_IMAGE):$(devopsconsole_version)," $(CUR_DIR)/test/olm/catalog_source.yaml | oc apply -f -
Copy link
Contributor

@corinnekrych corinnekrych Mar 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need some if/else to keep Makefile macOS compatible. See we did with Tina did on previous test PR.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

@baiju if that's a tiny change, you could. Otherwise we could merge this PR and consider doing that in a separate PR.
I would like to see how the usage with Openshift CI would be. Using the internal registry might be easier there - have to see how it goes.

@baijum
Copy link
Member

baijum commented Apr 1, 2019

@sbose78 That ConfigMap based approach requires some more work. Let's do it separately later.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

/ok-to-test

@@ -56,6 +56,32 @@ e2e-cleanup: get-test-namespace
$(Q)-oc delete -f ./deploy/test/role_binding_test.yaml --namespace $(TEST_NAMESPACE)
$(Q)-oc delete -f ./deploy/test/operator_test.yaml --namespace $(TEST_NAMESPACE)

.PHONY: test-olm-integration
## Runs the OLM integration tests without coverage
test-olm-integration: push-operator-image olm-integration-setup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calls

.PHONY: build-operator-image
## Build and create the operator container image
build-operator-image:
	operator-sdk build $(DEVCONSOLE_OPERATOR_IMAGE)

The CI test pushing to the latest tag can be disastrous :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. d27da00

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

On Mac

Step 5/7 : RUN sed -e "s,REPLACE_IMAGE,${image}," -i manifests/devconsole/${version}/devconsole-operator.v${version}.clusterserviceversion.yaml
 ---> Running in 5127469a3818
sed: couldn't open temporary file manifests/devconsole/0.1.0/sedZf4K3u: Permission denied
The command '/bin/sh -c sed -e "s,REPLACE_IMAGE,${image}," -i manifests/devconsole/${version}/devconsole-operator.v${version}.clusterserviceversion.yaml' returned a non-zero code: 4
make: *** [test-olm-integration] Error 4

@baijum
Copy link
Member

baijum commented Apr 1, 2019

@sbose78 Can you check the permission of the 0.1.0 directory in the host system (Mac)?

For me it shows something like this:

ls -ld manifests/devconsole/0.1.0/
drwxrwxr-x. 2 baiju baiju 4096 Apr  1 20:51 manifests/devconsole/0.1.0/

I just freshly cloned a new repo, I got the same permission.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

$ ls -ld manifests/devconsole/0.1.0/
drwxr-xr-x  5 sbose  staff  160 Apr  1 12:01 manifests/devconsole/0.1.0/

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

On re-running:

oc apply -f ./test/e2e/subscription.yaml
subscription.operators.coreos.com/my-devopsconsole unchanged

Need to verify if we are cleaning up the subscription.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

any_image(.)tag should be good as well.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

The CatalogSource object gets created into olm namespace and the Subscription goes into operators . Let's ensure that the namespaces are present before we try creating resources in them. As far as I remember, the namespaces were absent in openshift 4.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

.. although it would be fair to have this PR focus on openshift 3 with OLM, and then make this test work for openshift 4 in a different PR.

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

All version numbers can be a derivative of the commit id .

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avni-Sharma, baijum, sbose78

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sbose78
Copy link
Member

sbose78 commented Apr 1, 2019

Following are the follow-up tasks:
#66
#65

@sbose78 sbose78 merged commit 7f3e8a4 into redhat-developer:master Apr 1, 2019
@baijum baijum mentioned this pull request Apr 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants