Skip to content

Commit

Permalink
Improve developer experience by minimizing local changes (open-teleme…
Browse files Browse the repository at this point in the history
…try#2421)

* Improve developer experience

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

* handle e2e tests

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

---------

Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Dec 7, 2023
1 parent e4d21ef commit bab56a3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
28 changes: 23 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ git commit -sam "Add feature X"
gh pr create
```

#### Make changes to the project manifests

The following command should be run to make sure the project manifests are up-to-date:

```bash
make generate manifests bundle api-docs reset
```

The local changes after running the command should be added to the pull request:

The following `make` target is run on CI to verify the project structure:

```bash
make ensure-generate-is-noop
```

### Pre-requisites
* Install [Go](https://golang.org/doc/install).
* Install [Kustomize](https://kubectl.docs.kubernetes.io/installation/kustomize/).
Expand All @@ -37,7 +53,7 @@ Refer to the [Operator SDK documentation](https://sdk.operatorframework.io/docs/

Build the manifests, install the CRD and run the operator as a local process:
```bash
make bundle install run
make install run
```

### Deployment with webhooks
Expand All @@ -58,16 +74,16 @@ The environment variable `CERTMANAGER_VERSION` can be used to override the cert-
CERTMANAGER_VERSION=1.60 make cert-manager
```

When deploying the operator into the cluster using `make deploy`, an image in the format `ghcr.io/${USER}/opentelemetry-operator` is generated. If this format isn't suitable, it can be overridden by:
When deploying the operator into the cluster using `make deploy`, an image in the format `ghcr.io/${DOCKER_USER}/opentelemetry-operator` is generated. If this format isn't suitable, it can be overridden by:

* `IMG_PREFIX`, to override the registry, namespace and image name
* `USER`, to override the namespace
* `DOCKER_USER`, to override the namespace
* `IMG_REPO`, to override the repository (`opentelemetry-operator`)
* `VERSION`, to override only the version part
* `IMG`, to override the entire image specification

```bash
IMG=docker.io/${USER}/opentelemetry-operator:dev-$(git rev-parse --short HEAD)-$(date +%s) make generate bundle container container-push deploy
IMG=docker.io/${DOCKER_USER}/opentelemetry-operator:dev-$(git rev-parse --short HEAD)-$(date +%s) make generate container container-push deploy
```

Your operator will be available in the `opentelemetry-operator-system` namespace.
Expand Down Expand Up @@ -108,6 +124,8 @@ Once they are installed, the tests can be executed with `make prepare-e2e`, whic

The tests are located under `tests/e2e` and are written to be used with `kuttl`. Refer to their documentation to understand how tests are written.

To evert the changes made by the `make prepare-e2e` run `make reset`.

### OpenShift End to End tests
To run the end-to-end tests written for OpenShift, you'll need a OpenShift cluster.

Expand Down Expand Up @@ -188,7 +206,7 @@ BUNDLE_IMG=docker.io/${USER}/opentelemetry-operator-bundle:latest IMG=docker.io/
### Install the operator

```bash
operator-sdk run bundle docker.io/${USER}/opentelemetry-operator-bundle:latest
operator-sdk run bundle docker.io/${DOCKER_USER}/opentelemetry-operator-bundle:latest
```

### Uninstall the operator
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ OPERATOR_LDFLAGS ?= -X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.build
ARCH ?= $(shell go env GOARCH)

# Image URL to use all building/pushing image targets
IMG_PREFIX ?= ghcr.io/${USER}/opentelemetry-operator
DOCKER_USER ?= open-telemetry
IMG_PREFIX ?= ghcr.io/${DOCKER_USER}/opentelemetry-operator
IMG_REPO ?= opentelemetry-operator
IMG ?= ${IMG_PREFIX}/${IMG_REPO}:${VERSION}
BUNDLE_IMG ?= ${IMG_PREFIX}/${IMG_REPO}-bundle:${VERSION}
Expand Down Expand Up @@ -82,7 +83,7 @@ SED ?= $(shell which gsed 2>/dev/null || which sed)

.PHONY: ensure-generate-is-noop
ensure-generate-is-noop: VERSION=$(OPERATOR_VERSION)
ensure-generate-is-noop: USER=open-telemetry
ensure-generate-is-noop: DOCKER_USER=open-telemetry
ensure-generate-is-noop: set-image-controller generate bundle
@# on make bundle config/manager/kustomization.yaml includes changes, which should be ignored for the below check
@git restore config/manager/kustomization.yaml
Expand Down Expand Up @@ -178,7 +179,7 @@ lint: golangci-lint

# Generate code
.PHONY: generate
generate: controller-gen api-docs
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# end-to-tests
Expand Down Expand Up @@ -442,6 +443,16 @@ bundle: kustomize operator-sdk manifests set-image-controller
$(OPERATOR_SDK) bundle validate ./bundle
./hack/ignore-createdAt-bundle.sh

.PHONY: reset
reset: kustomize operator-sdk manifests
$(MAKE) VERSION=${OPERATOR_VERSION} set-image-controller
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version ${OPERATOR_VERSION} $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
./hack/ignore-createdAt-bundle.sh
git checkout config/manager/kustomization.yaml
OPERATOR_IMG=local/opentelemetry-operator:e2e TARGETALLOCATOR_IMG=local/opentelemetry-operator-targetallocator:e2e OPERATOROPAMPBRIDGE_IMG=local/opentelemetry-operator-opamp-bridge:e2e DEFAULT_OPERATOR_IMG=$(IMG) DEFAULT_TARGETALLOCATOR_IMG=$(TARGETALLOCATOR_IMG) DEFAULT_OPERATOROPAMPBRIDGE_IMG=$(OPERATOROPAMPBRIDGE_IMG) SED_BIN="$(SED)" ./hack/modify-test-images.sh

# Build the bundle image, used only for local dev purposes
.PHONY: bundle-build
bundle-build:
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Steps to release a new version of the OpenTelemetry Operator:

1. Change the `versions.txt`, so that it lists the target version of the OpenTelemetry Collector (operand), and the desired version for the target allocator and the operator. The `major.minor` should typically match, with the patch portion being possibly different.
2. Change the `autoinstrumentation-*` versions in `versions.txt` as per the latest supported versions in `autoinstrumentation/`.
3. Run `make bundle USER=open-telemetry VERSION=0.38.0`, using the version that will be released.
3. Run `make bundle DOCKER_USER=open-telemetry VERSION=0.38.0`, using the version that will be released.
4. Change the compatibility matrix in the [readme](./README.md) file, using the OpenTelemetry Operator version to be released and the current latest Kubernetes version as the latest supported version. Remove the oldest entry.
5. Add the changes to the changelog. Manually add versions of all operator components.
6. Check the OpenTelemetry Collector's changelog and ensure migration steps are present in `pkg/collector/upgrade`
Expand Down
10 changes: 6 additions & 4 deletions hack/ignore-createdAt-bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# This code checks if only the createdAt field. If is the only change, it is ignored.
# Else, it will do nothing.
# https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333
git diff --quiet -I'^ createdAt: ' bundle
if ((! $?)) ; then
git checkout bundle
fi
git diff --quiet -I'^ createdAt: ' bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
ret=$?
changes=$(git diff --numstat bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml)
if [ $ret = 0 ] && [ "$changes" = '1 1 bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml' ] ; then
git checkout bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml
fi
16 changes: 10 additions & 6 deletions hack/modify-test-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

SED_BIN=${SED_BIN:-sed}

${SED_BIN} -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/smoke-targetallocator/*.yaml
${SED_BIN} -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-features/00-install.yaml
${SED_BIN} -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/prometheus-config-validation/*.yaml
${SED_BIN} -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-prometheuscr/*.yaml
DEFAULT_TARGETALLOCATOR_IMG=${DEFAULT_TARGETALLOCATOR_IMG:-local/opentelemetry-operator-targetallocator:e2e}
DEFAULT_OPERATOROPAMPBRIDGE_IMG=${DEFAULT_OPERATOROPAMPBRIDGE_IMG:-local/opentelemetry-operator-opamp-bridge:e2e}
DEFAULT_OPERATOR_IMG=${DEFAULT_OPERATOR_IMG:-local/opentelemetry-operator:e2e}

${SED_BIN} -i "s#local/opentelemetry-operator:e2e#${OPERATOR_IMG}#g" tests/e2e-multi-instrumentation/*.yaml
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/smoke-targetallocator/*.yaml
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-features/00-install.yaml
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/prometheus-config-validation/*.yaml
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-prometheuscr/*.yaml

${SED_BIN} -i "s#local/opentelemetry-operator-opamp-bridge:e2e#${OPERATOROPAMPBRIDGE_IMG}#g" tests/e2e-opampbridge/opampbridge/*.yaml
${SED_BIN} -i "s#${DEFAULT_OPERATOR_IMG}#${OPERATOR_IMG}#g" tests/e2e-multi-instrumentation/*.yaml

${SED_BIN} -i "s#${DEFAULT_OPERATOROPAMPBRIDGE_IMG}#${OPERATOROPAMPBRIDGE_IMG}#g" tests/e2e-opampbridge/opampbridge/*.yaml

0 comments on commit bab56a3

Please sign in to comment.