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

Cross-component E2E for operator framework #286

Merged
merged 6 commits into from
Aug 11, 2023
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
12 changes: 12 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ $(KUSTOMIZE): $(BINGO_DIR)/kustomize.mod
@echo "(re)installing $(GOBIN)/kustomize-v4.5.7"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=kustomize.mod -o=$(GOBIN)/kustomize-v4.5.7 "sigs.k8s.io/kustomize/kustomize/v4"

OPERATOR_SDK := $(GOBIN)/operator-sdk-v1.31.0
$(OPERATOR_SDK): $(BINGO_DIR)/operator-sdk.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/operator-sdk-v1.31.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -ldflags=-X=github.com/operator-framework/operator-sdk/internal/version.Version=v1.31.0 -mod=mod -modfile=operator-sdk.mod -o=$(GOBIN)/operator-sdk-v1.31.0 "github.com/operator-framework/operator-sdk/cmd/operator-sdk"

OPM := $(GOBIN)/opm-v1.28.0
$(OPM): $(BINGO_DIR)/opm.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/opm-v1.28.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=opm.mod -o=$(GOBIN)/opm-v1.28.0 "github.com/operator-framework/operator-registry/cmd/opm"

SETUP_ENVTEST := $(GOBIN)/setup-envtest-v0.0.0-20230606045100-e54088c8c7da
$(SETUP_ENVTEST): $(BINGO_DIR)/setup-envtest.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
11 changes: 11 additions & 0 deletions .bingo/operator-sdk.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20

replace github.com/containerd/containerd => github.com/containerd/containerd v1.4.11

replace github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d

replace github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0

require github.com/operator-framework/operator-sdk v1.31.0 // cmd/operator-sdk -ldflags=-X=github.com/operator-framework/operator-sdk/internal/version.Version=v1.31.0
1,590 changes: 1,590 additions & 0 deletions .bingo/operator-sdk.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .bingo/opm.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20

replace github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d

require github.com/operator-framework/operator-registry v1.28.0 // cmd/opm
947 changes: 947 additions & 0 deletions .bingo/opm.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ KIND="${GOBIN}/kind-v0.15.0"

KUSTOMIZE="${GOBIN}/kustomize-v4.5.7"

OPERATOR_SDK="${GOBIN}/operator-sdk-v1.31.0"

OPM="${GOBIN}/opm-v1.28.0"

SETUP_ENVTEST="${GOBIN}/setup-envtest-v0.0.0-20230606045100-e54088c8c7da"

23 changes: 23 additions & 0 deletions .github/workflows/operator-developer-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: operator-developer-e2e

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
operator-developer-e2e:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Run the operator framework e2e test
run: |
make operator-developer-e2e
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ E2E_FLAGS ?= ""
test-e2e: $(GINKGO) ## Run the e2e tests
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e

.PHONY: test-op-dev-e2e
test-op-dev-e2e: $(GINKGO) ## Run operator create, upgrade and delete tests
CONTAINER_RUNTIME=$(CONTAINER_RUNTIME) $(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/operator-framework-e2e

.PHONY: test-unit
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
Expand All @@ -111,6 +115,10 @@ e2e: KUSTOMIZE_BUILD_DIR=config/e2e
e2e: GO_BUILD_FLAGS=-cover
e2e: run kind-load-test-artifacts test-e2e e2e-coverage kind-cluster-cleanup ## Run e2e test suite on local kind cluster

.PHONY: operator-developer-e2e
operator-developer-e2e: KIND_CLUSTER_NAME=operator-controller-op-dev-e2e ## Run operator-developer e2e on local kind cluster
operator-developer-e2e: run $(OPM) $(OPERATOR_SDK) $(KUSTOMIZE) deploy-local-registry test-op-dev-e2e cleanup-local-registry kind-cluster-cleanup

.PHONY: e2e-coverage
e2e-coverage:
COVERAGE_OUTPUT=./e2e-cover.out ./hack/e2e-coverage.sh
Expand Down Expand Up @@ -141,6 +149,24 @@ kind-load-test-artifacts: $(KIND) ## Load the e2e testdata container images into
$(KIND) load docker-image localhost/testdata/bundles/plain-v0/plain:v0.1.0 --name $(KIND_CLUSTER_NAME)
$(KIND) load docker-image localhost/testdata/catalogs/test-catalog:e2e --name $(KIND_CLUSTER_NAME)

.PHONY: deploy-local-registry
deploy-local-registry: ## Deploy local registry
$(CONTAINER_RUNTIME) run -d -p 5001:5000 --restart=always --name local-registry registry:2

.PHONY: cleanup-local-registry
cleanup-local-registry: ## Stop and remove local registry
$(CONTAINER_RUNTIME) container stop local-registry
$(CONTAINER_RUNTIME) container rm -v local-registry

opm: $(OPM)
$(OPM) $(OPM_ARGS)

operator-sdk: $(OPERATOR_SDK)
(cd $(OPERATOR_SDK_PROJECT_PATH) && $(OPERATOR_SDK) $(OPERATOR_SDK_ARGS))
Comment on lines +161 to +165
Copy link
Member

Choose a reason for hiding this comment

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

Unless I'm missing something - we do not use these two targets.

Copy link
Member

Choose a reason for hiding this comment

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

Ah... I see - we use them in tests. This is not obvous and I think deserves a comment.


However in my opinion E2E tests should not be calling make to install opm and operator-sdk binaries. I think it is not critical for now, but we need to create an issue for this (unless there are objections to the idea below).

I think we need to change tests so that it:

  • Either has opm and operator-sdk in PATH and simply runs it like exec.Command("opm", ...)
  • Or receives a path to opm and friends via arguments/env vars or somehow else.

This way we can run a matrix for our tests and use different versions of opm and operator-sdk.

Also it will make test code a bit cleaner (but would require some more test setup code instead).


kustomize: $(KUSTOMIZE)
(cd $(OPERATOR_SDK_PROJECT_PATH) && $(KUSTOMIZE) $(KUSTOMIZE_ARGS))

##@ Build

export VERSION ?= $(shell git describe --tags --always --dirty)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ require (
github.com/go-logr/logr v1.2.4
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42
github.com/operator-framework/catalogd v0.4.1
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266
github.com/operator-framework/operator-registry v1.27.1
github.com/operator-framework/rukpak v0.13.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
k8s.io/apiextensions-apiserver v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/component-base v0.26.1
Expand Down Expand Up @@ -94,7 +96,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42 // indirect
github.com/otiai10/copy v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -135,7 +136,6 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.1 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/apiserver v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
Expand Down
202 changes: 202 additions & 0 deletions test/operator-framework-e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Cross-component E2E for operator framework
dtfranz marked this conversation as resolved.
Show resolved Hide resolved

This is a cross-component demo with all OLM v1 repositories. The ginkgo test does the following:
- Uses operator-sdk and kustomize to build `plain+v0` bundles and create catalogs to include the bundles.
- Installs, upgrades and deletes a `plain+v0` operator.
- Uses operator-sdk to build `registry+v1` bundles and create catalogs to include the bundles.
- Installs, upgrades and deletes a `registry+v1` operator.

The steps in the ginkgo test can be summarized as follows:

1. start with an empty directory
2. call operator-sdk to initialize and generate an operator
3. generate a bundle directory
4. build/push/kind load bundle images from the bundle directories
5. repeat steps 2-4 as necessary to get bundles for multiple operator versions
6. generate a catalog directory
7. build/push/kind load the catalog
8. create a Catalog CR (with kubectl operator)
9. create an Operator CR (with kubectl operator)
10. trigger Operator upgrades (with kubectl operator)
11. delete the Operator CR (with kubectl operator)
12. delete the Catalog CR (with kubectl operator)
13. repeat steps 2-12 for each bundle format (e.g. registry+v1 and plain+v0)
## Objective
- Development on OLM v1 is split across multiple repositories, and the list of relevant repositories may grow over time. While we have demos showing improvements in functionality of components over time, it can be difficult to have a picture of the state of OLM v1 at any given time for someone not following its development closely. Having a single source to look for OLM v1 behavior can provide more clarity about the state of the project.
- With the scale of the OLM v1 project, it is useful to have a means to test components in the operator development + lifecycle pipeline together to create a more cohesive experience for all users.

## Getting Started
- This test currently only works with the container runtime `docker`.
- Building operator-controller, deploying it into the cluster and rest of the configuration is done in the `MakeFile` of this repo under the target `operator-developer-e2e`. This includes:

- Setting up a kind cluster named `operator-controller-op-dev-e2e`.
- Installing the operator controller onto the cluster.
- Setting up `opm`, `operator-sdk` and `kustomize` using bingo.
- Setting up a local registry server for building and loading images.
### Input Values used

Below are the input values used in the test which is specified in the `operator_framework_test.go`.

- The following structs defined are required, to accept input for both `plain+v0` and `registry+v1` bundles:
- For getting bundle related inputs:
```
type BundleInfo struct {
baseFolderPath string
bundles []BundleContent
}

type BundleContent struct {
bInputDir string
bundleVersion string
imageRef string
}
```
- `baseFolderPath` - Base/root path of the folder where the specific bundle type input data is stored.[root path to plain-v0 or registry-v1 bundles testdata]
- `bundles` - Stores the data relevant to different versions of the bundle.
- `bInputDir` - The directory that stores the specific version of the bundle data. The name of the directory is formed and is of the format `<operatorName>.v<bundleVersion>`.
- `bundleVersion` - The specific version of the bundle data.
- `imageRef` - This is formed. Stores the bundle image reference which will be of the format `<registry_repo>/< operatorName>-bundle:v.<bundleVersion>`
- For getting catalog related inputs:
```
type CatalogDInfo struct {
baseFolderPath string
catalogDir string
operatorName string
desiredChannelName string
imageRef string
fbcFileName string
}
```
- `baseFolderPath` - Base/root path of the folder that stores the catalogs.
- `operatorName` - Name of the operator to be installed from the bundles.
- `desiredChannelName` - Desired channel name for the operator.
- `catalogDir` - This is formed. The directory to store the catalog/FBC. The directory name will be of the format: `<operator-name>-catalog`
- `imageRef` - This is formed. Stores the FBC image reference which will be of the format: `<registry_repo>/<catalogDir>:test`
- `fbcFileName` - Name of the FBC file. This is hard-coded as `catalog.yaml`.
- For getting information related to the install/upgrade action for operators:
```
type OperatorActionInfo struct {
installVersion string
upgradeVersion string
}
```
- `installVersion` - Version of the operator to be installed on the cluster.
- `upgradeVersion` - Version of the operator to be upgraded on the cluster.

- The below inputs are used to form the bundle using operator-sdk.

```
type SdkProjectInfo struct {
projectName string
domainName string
group string
version string
kind string
}
```
## How to run
- Makefile target `operator-developer-e2e` : Runs the entire E2E setup.
- Makefile target `test-op-dev-e2e`: Runs the ginkgo test.
- Makefile target `deploy-local-registry`: Deploys local registry
- Makefile target `cleanup-local-registry` : Stops and removes local registry
- Makefile target `kind-cluster-cleanup`: Deletes the kind cluster

## Bundle Types
### Plain bundles
- The `plain+v0` bundles are formed using `operator-sdk` and `kustomize`.
- The `kustomize` organizes the different resources present in the `operator-sdk` project into a single yaml file.
- The Dockerfile for the bundle is named `plainbundle.Dockerfile` and is generated using a custom routine.
- The generated bundle is stored in the format:
```
plain-v0
└── <operatorName>.v<bundleVersion>
└── manifests
│ └── mainfest.yaml
└── plainbundle.Dockerfile
```


- The FBC template is formed by a custom routine by using the operatorName, desiredChannelName, bundle imageRefs and bundleVersions.
- `Default channel` is not used in forming the FBC as it is not an OLMv1 concept.
- Only one `olm.channel` is generated which is the given <desiredChannelName>.
- Upgrade graph is formed with only replaces edge.
- The generated FBC is not validated using `opm` as the tool has no support for plain bundles.
- The Dockerfile for the catalog is named `<operator-name>-catalog.Dockerfile` and is generated using a custom routine.
- The generated catalog is stored in the format:
```
catalogs
└── <operator-name>-catalog
│ └── catalog.yaml
└── <operator-name>-catalog.Dockerfile
```
- The catalog CR is then formed with the name `<operatorName>-catalog`.

- The operator is then installed and has the name `<operatorName>`.

### Registry Bundles

- The registry+v1 bundles are formed using operator-sdk.
- The generated CSV uses the default values.
- The bundle content is formed within the operator-sdk project directory in the folder `bundle`. This is moved to the bundle directory folder.
- The generated Dockerfile has the name `bundle.Dockerfile`. The Dockerfile and bundle structure is genearted by the `operator-sdk` tool.
- The generated bundle is stored in the format:
```
registry-v1
└── <operatorName>.v<bundleVersion>
└── manifests
└── metadata
└── bundle.Dockerfile
```

- The FBC is formed using `opm alpha render-template semver` tool.
- The semver template named `registry-semver.yaml` is formed using a custom routine by passing the bundle imageRefs.
- `generatemajorchannels` and `generateminorchannels` is set to false in the semver template.
- The generated catalog is stored in the format:
```
catalogs
└── <operator-name>-catalog
│ └── catalog.yaml
└── <operator-name>-catalog.Dockerfile
```

- The catalog resource is then formed with the name `<operatorName>-catalog`.

- The operator is then installed and has the name `<operatorName>`.


- After the e2e workflow, all the files formed are cleared.


## To-do
1. The resources are read from input manifests using universal decoder from `k8s.io/apimachinery/pkg/runtime/serializer`.
- However, in cases where a single file contains multiple YAML documents separated by `---,` the `UniversalDecoder` recognizes only the first resource. This situation is relevant as for `plain+v0` bundles generated through `kustomize,` the manifest has multiple YAML documents are combined into one file using --- separators. This is now handled by splitting the content of the YAML file and decoding each of them using the `UniversalDecoder`.
- This workaround can be improved using `YAMLToJSONDecoder` from `k8s.io/apimachinery/pkg/util/yaml`. And the kind, api version and name can be get by decoding into `Unstructured` from `k8s.io/apimachinery/pkg/apis/meta/v1/unstructured`.
2. All the tests pass and the operator is installed successfully. The bundledeployment succeeds and the resources are created. But the pod for the new operator failes due to `ImagePullBackOff`.
- This is because the `Deployment` controller-manager uses the image `controller:latest` which is not present on the cluster.
- The solution would be to replace `controller:latest` with the `busybox:latest` and then pulling and loading `busybox:latest` onto cluster.
- The replacement could possibly be achieved by adding the following to `config/default/kustomization.yaml` under `operator-sdk` project:
```
images:
- name: controller
newName: controller
newTag: latest
```
## Issues
1. This test currently only works with the container runtime `docker`.
- The default value of CONTAINER_RUNTIME defined in the Makefile is `docker`. Therefore the correct runtime has to be assigned to the variable `CONTAINER_RUNTIME` before calling the make target if docker is what is not being used. The test routine also assumes the runtime as `docker` if it is unable to retrieve the value of the environment variable.
- But this is only a partial fix to the problem. With this change the test for `plain+v0` bundles will pass but for `registry+v1` will fail for other container runtimes. This is because `registry+v1` uses `operator-sdk` support. Thus to mimic the user experience, the targets `bundle-build` and `bundle-push` from the generated Makefile by operator-sdk tool, which has docker being hard coded as the container runtime, is used to build and push the bundle images. This could be marked as an issue and addressed when hard coding docker as container runtime in the generated Makefile is addressed by operator-sdk.

2. The `opm`,`operator-sdk` and `kustomize` binaries are added in operator-controller using `bingo`.
- But based on discussions, if required test should be changed so that it has `opm` and `operator-sdk` in `PATH` and simply runs it like `exec.Command("opm", ...)`.
- This will enable in running [a matrix](https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs) for the tests and to use different versions of `opm` and `operator-sdk`.
- This might help in emulating the user experience better.

## Tooling gaps

Following are the tooling gaps identified while testing `operator-framework` end-to-end:
- `opm` doesn't have plain bundle support.
- No tool for forming FBC for plain bundles.
- No tool for generating Dockerfile for plain bundles.
- No tool for generating Dockerfile for plain catalogs.
- Since `opm` doesn't have plain bundle support, there is no means to validate the FBC generated for plain bundles.

Loading
Loading