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

Add e2e tests for Operator #201

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
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
VERSION ?= 0.0.1
IMG ?= quay.io/opendatahub/opendatahub-operator:dev-$(VERSION)
IMAGE_BUILDER ?= podman
OPERATOR_NAMESPACE ?= opendatahub-operator-system

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -65,6 +66,9 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# E2E tests additional flags
E2E_TEST_FLAGS = "--skip-deletion=false" # See README.md

.PHONY: all
all: build

Expand Down Expand Up @@ -136,20 +140,22 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | oc apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/crd | oc delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
sed -i'' -e 's,namespace: .*,namespace: '"${OPERATOR_NAMESPACE}"',' config/default/kustomization.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

$(KUSTOMIZE) build config/default | oc apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/default | oc delete --ignore-not-found=$(ignore-not-found) -f -

##@ Build Dependencies

Expand Down Expand Up @@ -187,6 +193,7 @@ $(ENVTEST): $(LOCALBIN)
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
sed -i'' -e 's,namespace: .*,namespace: '"${OPERATOR_NAMESPACE}"',' config/default/kustomization.yaml
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
operator-sdk bundle validate ./bundle

Expand Down Expand Up @@ -238,3 +245,7 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

.PHONY: e2e-test
e2e-test: ## Run e2e tests for the controller
go test ./tests/e2e/ -run ^TestOdhOperator -v --kf-namespace=${OPERATOR_NAMESPACE} ${E2E_TEST_FLAGS}
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ and installed from source manually, see the Developer guide for further instruct

### Developer Guide

**Pre-requisites**
#### Pre-requisites

- Go version **go1.18.4**
- operator-sdk version can be updated to **v1.24.1**

**Build Image**
#### Build Image

- Custom operator image can be built using your local repository
```
Expand All @@ -35,10 +35,14 @@ and installed from source manually, see the Developer guide for further instruct
export KUBECONFIG=<path to kubeconfig>
```

**Deployment**
#### Deployment

**Deploying operator locally**

- Define operator namespace
```
export OPERATOR_NAMESPACE=<namespace-to-install-operator>
```
- Deploy the created image in your cluster using following command:
```
make deploy -e IMG=quay.io/<username>/opendatahub-operator:<custom-tag>
Expand All @@ -51,6 +55,11 @@ and installed from source manually, see the Developer guide for further instruct

**Deploying operator using OLM**

- Define operator namespace
```
export OPERATOR_NAMESPACE=<namespace-to-install-operator>
```

- To create a new bundle, run following command:
```commandline
make bundle
Expand All @@ -65,7 +74,7 @@ and installed from source manually, see the Developer guide for further instruct

- Run the Bundle on a cluster:
```commandline
operator-sdk run bundle quay.io/<username>/opendatahub-operator-bundle:<VERSION>
operator-sdk run bundle quay.io/<username>/opendatahub-operator-bundle:<VERSION> --namespace $OPERATOR_NAMESPACE
```


Expand All @@ -78,4 +87,35 @@ following KfDefs to install Open Data Hub components:



### Run e2e Tests

A user can run the e2e tests in the same namespace as the operator. To deploy
opendatahub-operator refer to [this](#deployment) section. The
following environment variables must be set when running locally:

```shell
export KUBECONFIG=/path/to/kubeconfig
export OPERATOR_NAMESPACE=<namespace-of-operator>
```

Once the above variables are set, run the following:

```shell
make e2e-test
```

Additional flags that can be passed to e2e-tests by setting up `E2E_TEST_FLAGS`
variable. Following table lists all the available flags to run the tests:

| Flag | Description | Default value |
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| --skip-deletion | To skip running of `kfdef-deletion` test that includes deleting `KfDef` resources. Assign this variable to `true` to skip KfDef deletion. | false |



Example command to run full test suite in a custom namespace, skipping the test
for KfDef deletion.

```shell
make e2e-test -e OPERATOR_NAMESPACE=<YOUR_NAMESPACE> -e E2E_TEST_FLAGS="--skip-deletion=true"
```
2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=opendatahub-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.26.0
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.24.1
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

Expand Down
Loading