Skip to content

Commit a75058b

Browse files
committed
Added helm operator
1 parent 889ecd2 commit a75058b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+8334
-0
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Build the manager binary
2+
FROM quay.io/operator-framework/helm-operator:v1.26.0
3+
4+
ENV HOME=/opt/helm
5+
COPY watches.yaml ${HOME}/watches.yaml
6+
COPY helm-charts ${HOME}/helm-charts
7+
WORKDIR ${HOME}

Makefile

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# VERSION defines the project version for the bundle.
2+
# Update this value when you upgrade the version of your project.
3+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6+
VERSION ?= 0.0.1
7+
8+
# CHANNELS define the bundle channels used in the bundle.
9+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
10+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
11+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
12+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
13+
ifneq ($(origin CHANNELS), undefined)
14+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
15+
endif
16+
17+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
18+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
19+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
20+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
21+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
22+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
23+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
24+
endif
25+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
26+
27+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28+
# This variable is used to construct full image tags for bundle and catalog images.
29+
#
30+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31+
# mariadb.mmontes.io/helm-operator-bundle:$VERSION and mariadb.mmontes.io/helm-operator-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= mariadb.mmontes.io/helm-operator
33+
34+
# BUNDLE_IMG defines the image:tag used for the bundle.
35+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
37+
38+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
40+
41+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42+
# You can enable this value if you would like to use SHA Based Digests
43+
# To enable set flag to true
44+
USE_IMAGE_DIGESTS ?= false
45+
ifeq ($(USE_IMAGE_DIGESTS), true)
46+
BUNDLE_GEN_FLAGS += --use-image-digests
47+
endif
48+
49+
# Image URL to use all building/pushing image targets
50+
IMG ?= mmontes11/mariadb-operator-helm:latest
51+
52+
.PHONY: all
53+
all: docker-build
54+
55+
##@ General
56+
57+
# The help target prints out all targets with their descriptions organized
58+
# beneath their categories. The categories are represented by '##@' and the
59+
# target descriptions by '##'. The awk commands is responsible for reading the
60+
# entire set of makefiles included in this invocation, looking for lines of the
61+
# file as xyz: ## something, and then pretty-format the target and help. Then,
62+
# if there's a line with ##@ something, that gets pretty-printed as a category.
63+
# More info on the usage of ANSI control characters for terminal formatting:
64+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
65+
# More info on the awk command:
66+
# http://linuxcommand.org/lc3_adv_awk.php
67+
68+
.PHONY: help
69+
help: ## Display this help.
70+
@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)
71+
72+
##@ Build
73+
74+
.PHONY: run
75+
run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
76+
$(HELM_OPERATOR) run
77+
78+
.PHONY: docker-build
79+
docker-build: ## Build docker image with the manager.
80+
docker build -t ${IMG} .
81+
82+
.PHONY: docker-push
83+
docker-push: ## Push docker image with the manager.
84+
docker push ${IMG}
85+
86+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
87+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
88+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
89+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
90+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
91+
# To properly provided solutions that supports more than one platform you should use this option.
92+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
93+
.PHONY: docker-buildx
94+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
95+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
96+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
97+
- docker buildx create --name project-v3-builder
98+
docker buildx use project-v3-builder
99+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
100+
- docker buildx rm project-v3-builder
101+
rm Dockerfile.cross
102+
103+
##@ Deployment
104+
105+
.PHONY: install
106+
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
107+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
108+
109+
.PHONY: uninstall
110+
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
111+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
112+
113+
.PHONY: deploy
114+
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
115+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
116+
$(KUSTOMIZE) build config/default | kubectl apply -f -
117+
118+
.PHONY: undeploy
119+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
120+
$(KUSTOMIZE) build config/default | kubectl delete -f -
121+
122+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
123+
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
124+
125+
.PHONY: kustomize
126+
KUSTOMIZE = $(shell pwd)/bin/kustomize
127+
kustomize: ## Download kustomize locally if necessary.
128+
ifeq (,$(wildcard $(KUSTOMIZE)))
129+
ifeq (,$(shell which kustomize 2>/dev/null))
130+
@{ \
131+
set -e ;\
132+
mkdir -p $(dir $(KUSTOMIZE)) ;\
133+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.7/kustomize_v4.5.7_$(OS)_$(ARCH).tar.gz | \
134+
tar xzf - -C bin/ ;\
135+
}
136+
else
137+
KUSTOMIZE = $(shell which kustomize)
138+
endif
139+
endif
140+
141+
.PHONY: helm-operator
142+
HELM_OPERATOR = $(shell pwd)/bin/helm-operator
143+
helm-operator: ## Download helm-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist.
144+
ifeq (,$(wildcard $(HELM_OPERATOR)))
145+
ifeq (,$(shell which helm-operator 2>/dev/null))
146+
@{ \
147+
set -e ;\
148+
mkdir -p $(dir $(HELM_OPERATOR)) ;\
149+
curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.26.0/helm-operator_$(OS)_$(ARCH) ;\
150+
chmod +x $(HELM_OPERATOR) ;\
151+
}
152+
else
153+
HELM_OPERATOR = $(shell which helm-operator)
154+
endif
155+
endif
156+
157+
.PHONY: bundle
158+
bundle: kustomize ## Generate bundle manifests and metadata, then validate generated files.
159+
operator-sdk generate kustomize manifests -q
160+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
161+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
162+
operator-sdk bundle validate ./bundle
163+
164+
.PHONY: bundle-build
165+
bundle-build: ## Build the bundle image.
166+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
167+
168+
.PHONY: bundle-push
169+
bundle-push: ## Push the bundle image.
170+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
171+
172+
.PHONY: opm
173+
OPM = ./bin/opm
174+
opm: ## Download opm locally if necessary.
175+
ifeq (,$(wildcard $(OPM)))
176+
ifeq (,$(shell which opm 2>/dev/null))
177+
@{ \
178+
set -e ;\
179+
mkdir -p $(dir $(OPM)) ;\
180+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$(OS)-$(ARCH)-opm ;\
181+
chmod +x $(OPM) ;\
182+
}
183+
else
184+
OPM = $(shell which opm)
185+
endif
186+
endif
187+
188+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
189+
# These images MUST exist in a registry and be pull-able.
190+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
191+
192+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
193+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
194+
195+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
196+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
197+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
198+
endif
199+
200+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
201+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
202+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
203+
.PHONY: catalog-build
204+
catalog-build: opm ## Build a catalog image.
205+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
206+
207+
# Push the catalog image.
208+
.PHONY: catalog-push
209+
catalog-push: ## Push a catalog image.
210+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

PROJECT

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
domain: mariadb.mmontes.io
2+
layout:
3+
- helm.sdk.operatorframework.io/v1
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: mariadb-operator-helm
8+
resources:
9+
- api:
10+
crdVersion: v1
11+
namespaced: true
12+
domain: mariadb.mmontes.io
13+
group: helm
14+
kind: MariadbOperator
15+
version: v1alpha1
16+
version: "3"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: mariadboperators.helm.mariadb.mmontes.io
6+
spec:
7+
group: helm.mariadb.mmontes.io
8+
names:
9+
kind: MariadbOperator
10+
listKind: MariadbOperatorList
11+
plural: mariadboperators
12+
singular: mariadboperator
13+
scope: Namespaced
14+
versions:
15+
- name: v1alpha1
16+
schema:
17+
openAPIV3Schema:
18+
description: MariadbOperator is the Schema for the mariadboperators API
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: Spec defines the desired state of MariadbOperator
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
status:
37+
description: Status defines the observed state of MariadbOperator
38+
type: object
39+
x-kubernetes-preserve-unknown-fields: true
40+
type: object
41+
served: true
42+
storage: true
43+
subresources:
44+
status: {}

config/crd/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This kustomization.yaml is not intended to be run by itself,
2+
# since it depends on service name and namespace that are out of this kustomize package.
3+
# It should be run by config/default
4+
resources:
5+
- bases/helm.mariadb.mmontes.io_mariadboperators.yaml
6+
#+kubebuilder:scaffold:crdkustomizeresource

config/default/kustomization.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Adds namespace to all resources.
2+
namespace: mariadb-operator-helm-system
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
namePrefix: mariadb-operator-helm-
10+
11+
# Labels to add to all resources and selectors.
12+
#labels:
13+
#- includeSelectors: true
14+
# pairs:
15+
# someName: someValue
16+
17+
resources:
18+
- ../crd
19+
- ../rbac
20+
- ../manager
21+
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
22+
#- ../prometheus
23+
24+
patchesStrategicMerge:
25+
# Protect the /metrics endpoint by putting it behind auth.
26+
# If you want your controller-manager to expose the /metrics
27+
# endpoint w/o any authn/z, please comment the following line.
28+
- manager_auth_proxy_patch.yaml
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This patch inject a sidecar container which is a HTTP proxy for the
2+
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: controller-manager
7+
namespace: system
8+
spec:
9+
template:
10+
spec:
11+
affinity:
12+
nodeAffinity:
13+
requiredDuringSchedulingIgnoredDuringExecution:
14+
nodeSelectorTerms:
15+
- matchExpressions:
16+
- key: kubernetes.io/arch
17+
operator: In
18+
values:
19+
- amd64
20+
- arm64
21+
- ppc64le
22+
- s390x
23+
- key: kubernetes.io/os
24+
operator: In
25+
values:
26+
- linux
27+
containers:
28+
- name: kube-rbac-proxy
29+
securityContext:
30+
allowPrivilegeEscalation: false
31+
capabilities:
32+
drop:
33+
- "ALL"
34+
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0
35+
args:
36+
- "--secure-listen-address=0.0.0.0:8443"
37+
- "--upstream=http://127.0.0.1:8080/"
38+
- "--logtostderr=true"
39+
- "--v=0"
40+
ports:
41+
- containerPort: 8443
42+
protocol: TCP
43+
name: https
44+
resources:
45+
limits:
46+
cpu: 500m
47+
memory: 128Mi
48+
requests:
49+
cpu: 5m
50+
memory: 64Mi
51+
- name: manager
52+
args:
53+
- "--health-probe-bind-address=:8081"
54+
- "--metrics-bind-address=127.0.0.1:8080"
55+
- "--leader-elect"
56+
- "--leader-election-id=helm-operator"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: controller-manager
5+
namespace: system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager

config/manager/kustomization.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: mmontes11/mariadb-operator-helm
8+
newTag: latest

0 commit comments

Comments
 (0)