Skip to content

Commit

Permalink
Get Grafana Image from env; bundle cmd for redhat marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Mueller committed Nov 6, 2023
1 parent 6d19d89 commit 3166d43
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 31 deletions.
48 changes: 42 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
# 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.31.0
# Image URL to use all building/pushing image targets
REGISTRY ?= ghcr.io
REPO ?= grafana-operator
Expand Down Expand Up @@ -151,6 +165,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 +206,19 @@ 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:
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(OPERATOR_SDK) bundle validate ./bundle

# e2e
.PHONY: e2e
e2e: kuttl install deploy-kuttl ## Run e2e tests using kuttl.
$(KUTTL) test
Expand Down Expand Up @@ -291,7 +327,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/v1.23.2/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
Expand Down
25 changes: 13 additions & 12 deletions PREPARE_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ After that you need to run `make helm/docs` which will generate the changes to b
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 generate` & `make manifests`
- Update the following fields under `metadata.annotations` in `config/manifests/bases/grafana-operator.clusterserviceversion.yaml`:
- `containerImage`
- `replaces`
- `createdAt`: 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
Expand All @@ -50,6 +49,8 @@ Update `operators/grafana-operator/grafana-operator.package.yaml` with the new t
## RedHat operators
- Run `make bundle/redhat`
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)
that matches the new tag.
Expand Down
2 changes: 2 additions & 0 deletions bundle/manifests/grafana-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ spec:
- --metrics-bind-address=0.0.0.0:9090
- --leader-elect
env:
- name: RELATED_IMAGE_GRAFANA
value: docker.io/grafana/grafana:9.1.6
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
Expand Down
6 changes: 2 additions & 4 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namePrefix: grafana-operator-
#commonLabels:
# someName: someValue

bases:
resources:
- ../crd
- ../rbac
- ../manager
Expand All @@ -23,10 +23,8 @@ bases:
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

resources:
# Add metrics service
- metrics_service.yaml
- metrics_service.yaml

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
Expand Down
6 changes: 4 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- manager.yaml

Expand All @@ -8,8 +11,7 @@ configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

images:
- name: controller
newName: ghcr.io/grafana-operator/grafana-operator
Expand Down
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ spec:
cpu: 100m
memory: 20Mi
env:
- name: RELATED_IMAGE_GRAFANA
value: "docker.io/grafana/grafana:9.1.6"
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
Expand Down
11 changes: 10 additions & 1 deletion controllers/reconcilers/grafana/deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grafana
import (
"context"
"fmt"
"os"

"github.com/grafana-operator/grafana-operator/v5/api/v1beta1"
config2 "github.com/grafana-operator/grafana-operator/v5/controllers/config"
Expand Down Expand Up @@ -132,10 +133,18 @@ func getVolumeMounts(cr *v1beta1.Grafana, scheme *runtime.Scheme) []v1.VolumeMou
return mounts
}

func setGrafanaImage() string {
grafanaImg := os.Getenv("RELATED_IMAGE_GRAFANA")
if grafanaImg == "" {
grafanaImg = fmt.Sprintf("%s@%s", config2.GrafanaImage, config2.GrafanaVersion)
}
return grafanaImg
}

func getContainers(cr *v1beta1.Grafana, scheme *runtime.Scheme, vars *v1beta1.OperatorReconcileVars, openshiftPlatform bool) []v1.Container {
var containers []v1.Container

image := fmt.Sprintf("%s:%s", config2.GrafanaImage, config2.GrafanaVersion)
image := setGrafanaImage()
plugins := model.GetPluginsConfigMap(cr, scheme)

// env var to restart containers if plugins change
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/grafana-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- if .Values.env.grafanaImage }}
- name: RELATED_IMAGE_GRAFANA
value: {{ .Values.env.grafanaImage }}
{{- end }}
- name: WATCH_NAMESPACE
{{- if and .Values.namespaceScope (eq .Values.watchNamespaces "") }}
value: {{ .Release.Namespace }}
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/grafana-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ image:
# -- image pull secrets
imagePullSecrets: []

env:
# -- grafana image, e.g. docker.io/grafana/grafana:9.1.6
grafanaImage: ""

nameOverride: ""
fullnameOverride: ""

Expand Down
4 changes: 1 addition & 3 deletions deploy/kustomize/overlays/cluster_scoped/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
bases:
- ../../base

namespace: grafana

resources:
- ../../base
- rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
bases:
- ../../base

namespace: grafana

resources:
- ../../base
- rbac.yaml

patches:
Expand Down

0 comments on commit 3166d43

Please sign in to comment.