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

Make operator workable on disconnected clusters #1234

Merged
merged 15 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
74 changes: 67 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@
# Current Operator version
VERSION ?= 5.4.2

# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)

# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
USE_IMAGE_DIGESTS ?= false
ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif

# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.32.0

OPM_VERSION ?= v1.23.2
YQ_VERSION ?= v4.35.2

# Read Grafana Image and Version from go code
GRAFANA_IMAGE := $(shell grep 'GrafanaImage' controllers/config/operator_constants.go | sed 's/.*"\(.*\)".*/\1/')
GRAFANA_VERSION := $(shell grep 'GrafanaVersion' controllers/config/operator_constants.go | sed 's/.*"\(.*\)".*/\1/')

# Image URL to use all building/pushing image targets
REGISTRY ?= ghcr.io
REPO ?= grafana-operator
Expand Down Expand Up @@ -50,12 +72,30 @@ all: manifests test kustomize-crd api-docs
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: yq
YQ = ./bin/yq
yq: ## Download yq locally if necessary.
ifeq (,$(wildcard $(YQ)))
ifeq (,$(shell which yq 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(YQ)) ;\
OSTYPE=$(shell uname | awk '{print tolower($0)}') && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(YQ) https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_$${OSTYPE}_$${ARCH} ;\
chmod +x $(YQ) ;\
}
else
YQ = $(shell which yq)
endif
endif

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
manifests: yq controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." crd:maxDescLen=0,generateEmbeddedObjectMeta=false output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." crd:maxDescLen=0,generateEmbeddedObjectMeta=false output:crd:artifacts:config=deploy/helm/grafana-operator/crds
yq -i '(select(.kind == "Deployment") | .spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_GRAFANA").value = "$(GRAFANA_IMAGE):$(GRAFANA_VERSION)"), (select(.kind == "Namespace"))' config/manager/manager.yaml

.PHONY: kustomize-crd
kustomize-crd: kustomize manifests
Expand Down Expand Up @@ -151,6 +191,23 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (, $(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
}
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif

###
# END OF kubebuilder SECTION
###
Expand All @@ -175,14 +232,17 @@ endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(OPERATOR_SDK) bundle validate ./bundle

# e2e
.PHONY: bundle/redhat
bundle/redhat: BUNDLE_GEN_FLAGS += --use-image-digests
bundle/redhat: bundle

# e2e
.PHONY: e2e
e2e: kuttl install deploy-kuttl ## Run e2e tests using kuttl.
$(KUTTL) test
Expand Down Expand Up @@ -291,7 +351,7 @@ ifeq (,$(shell which opm 2>/dev/null))
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
Expand Down
51 changes: 30 additions & 21 deletions PREPARE_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,52 @@

In this repo you will need to perform the following tasks manually

## Documentation
## New release

Currently our documentation needs to be updated in two spots.
Hurray, time for a new release.
Follow the instructions below.

Currently our **documentation** needs to be updated in two spots.

You need to change the version in [hugo/config.toml](hugo/config.toml).
You also need to change the version for helm in [deploy/helm/grafana-operator/Chart.yaml](deploy/helm/grafana-operator/Chart.yaml).
After that you need to run `make helm/docs` which will generate the changes to become visible on our homepage.

## OLM

There is a lot of information on what is needed to manage OLM [compatible operators](https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/creating-the-csv).

- Update the `Makefile` version
- `make generate`, `make manifests` & `make bundle`
- Update `containerImage` field in `config/manifests/bases/grafana-operator.clusterserviceversion.yaml`
- Update `replaces` field in `config/manifests/bases/grafana-operator.clusterserviceversion.yaml`
- Update `CreatedAt` field in `config/manifests/bases/grafana-operator.clusterserviceversion.yaml`
You will have to asses when it's going to get merged and you will be able to do a release.
You should make sure it's the same date. If not you will have to change it
manually when creating PR:s to OLM.

# This is how the time syntax should look.
$ docker inspect ghcr.io/grafana-operator/grafana-operator:v5.0.0 |jq '.[0].Created'
"2023-11-22T10:34:12.173861869Z"
# 2023-11-22T10:34:12Z is enough
- Run `make bundle`
- `Helm` look if any rbac rules have been changed in the last release, if so verify that the rbac rules for the helm chart is correct. This should be done in those PRs but it don't hurt take an extra look.
- Create a PR and get it merged
- Create a new release with the new tag, make sure to compile release notes (github has an option to do this for you)

## OLM

After version v5.4.1, we no longer update the image version in this repo, but only upstream in the OLM repos.
This to support disconnected mode, for more information see [PR 1234](https://github.com/grafana-operator/grafana-operator/pull/1234).

After cutting a new release according to the instructions above, run the below instructions in this repo and create a PR to the different upstream repos, there is no need to create a PR to this repo.

There is a lot of information on what is needed to manage OLM [compatible operators](https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/creating-the-csv).

- Run `make generate` & `make manifests`
- Update the following fields under `metadata.annotations` in `config/manifests/bases/grafana-operator.clusterserviceversion.yaml`:
- `containerImage`
- `replaces`
- `createdAt`: Make sure that createdAt matches when the image was published. If not you will have to change it manually when creating PR:s to OLM.
```
# This is how the time syntax should look.
$ docker inspect ghcr.io/grafana-operator/grafana-operator:v5.0.0 |jq '.[0].Created'
"2023-11-22T10:34:12.173861869Z"
# 2023-11-22T10:34:12Z is enough
```
- Run `make bundle/redhat`
To update the OLM channels you will need to create a PR in the following repos:
You will need to sign your commits, and make sure they are squashed before submitting the PR, be aware that these repos also require you to sign certain open-source agreement documents as part of the CI-checks.
- [community operators](https://github.com/k8s-operatorhub/community-operators)
- [RedHat operators](https://github.com/redhat-openshift-ecosystem/community-operators-prod/tree/main/operators)
## Community operators
### Community operators
Create a new version of the operator under
[https://github.com/k8s-operatorhub/community-operators/tree/main/operators/grafana-operator](https://github.com/k8s-operatorhub/community-operators/tree/main/operators/grafana-operator)
Expand All @@ -48,7 +57,7 @@ Copy the content of `bundle/manifests/` in the grafana-operator repo from the ta
Update `operators/grafana-operator/grafana-operator.package.yaml` with the new tag.
## RedHat operators
### RedHat operators
Create a new version of the operator under
[https://github.com/redhat-openshift-ecosystem/community-operators-prod/tree/main/operators/grafana-operator](https://github.com/redhat-openshift-ecosystem/community-operators-prod/tree/main/operators/grafana-operator)
Expand Down
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=grafana-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.31.0
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

Expand Down
Loading
Loading