Skip to content

Commit 2766ff4

Browse files
Fix helm chart issues (#17)
* fixes on the helm chart added helm chart integration test Signed-off-by: raffaelespazzoli <[email protected]> * helm test successful Signed-off-by: raffaelespazzoli <[email protected]> * tested olm deployment Signed-off-by: raffaelespazzoli <[email protected]>
1 parent c99fb66 commit 2766ff4

25 files changed

+1318
-297
lines changed

.github/workflows/pr.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ on:
88
jobs:
99
shared-operator-workflow:
1010
name: shared-operator-workflow
11-
uses: redhat-cop/github-workflows-operators/.github/workflows/[email protected]
11+
uses: redhat-cop/github-workflows-operators/.github/workflows/[email protected]
12+
with:
13+
RUN_UNIT_TESTS: true
14+
RUN_INTEGRATION_TESTS: false
15+
RUN_HELMCHART_TEST: true

.github/workflows/push.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ on:
1010
jobs:
1111
shared-operator-workflow:
1212
name: shared-operator-workflow
13-
uses: redhat-cop/github-workflows-operators/.github/workflows/[email protected].0
13+
uses: redhat-cop/github-workflows-operators/.github/workflows/[email protected].3
1414
secrets:
1515
COMMUNITY_OPERATOR_PAT: ${{ secrets.COMMUNITY_OPERATOR_PAT }}
1616
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
1717
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
1818
with:
1919
PR_ACTOR: "[email protected]"
20+
RUN_UNIT_TESTS: true
21+
RUN_INTEGRATION_TESTS: false
22+
RUN_HELMCHART_TEST: true

Makefile

+88-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHART_REPO_URL ?= http://example.com
22
HELM_REPO_DEST ?= /tmp/gh-pages
33
OPERATOR_NAME ?=$(shell basename -z `pwd`)
4+
HELM_VERSION ?= v3.8.0
5+
KIND_VERSION ?= v0.11.1
6+
KUBECTL_VERSION ?= v1.21.1
7+
VAULT_VERSION ?= 1.9.3
48

59
# VERSION defines the project version for the bundle.
610
# Update this value when you upgrade the version of your project.
@@ -94,6 +98,13 @@ vet: ## Run go vet against code.
9498
test: manifests generate fmt vet envtest ## Run tests.
9599
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
96100

101+
.PHONY: kind-setup
102+
kind-setup: kind kubectl helm
103+
$(KIND) delete cluster
104+
$(KIND) create cluster --image docker.io/kindest/node:$(KUBECTL_VERSION) --config=./integration/cluster-kind.yaml
105+
$(HELM) upgrade ingress-nginx ./integration/helm/ingress-nginx -i --create-namespace -n ingress-nginx --atomic
106+
$(KUBECTL) wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s
107+
97108
##@ Build
98109

99110
build: generate fmt vet ## Build manager binary.
@@ -110,18 +121,18 @@ docker-push: ## Push docker image with the manager.
110121

111122
##@ Deployment
112123

113-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
114-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
124+
install: manifests kustomize kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
125+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
115126

116-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
117-
$(KUSTOMIZE) build config/crd | kubectl delete -f -
127+
uninstall: manifests kustomize kubectl ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
128+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -f -
118129

119-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
130+
deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
120131
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
121-
$(KUSTOMIZE) build config/default | kubectl apply -f -
132+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
122133

123-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
124-
$(KUSTOMIZE) build config/default | kubectl delete -f -
134+
undeploy: kustomize kubectl ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
135+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete -f -
125136

126137

127138
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
@@ -207,7 +218,7 @@ catalog-push: ## Push a catalog image.
207218
$(MAKE) docker-push IMG=$(CATALOG_IMG)
208219

209220
# Generate helm chart
210-
helmchart: kustomize
221+
helmchart: kustomize helm
211222
mkdir -p ./charts/${OPERATOR_NAME}/templates
212223
mkdir -p ./charts/${OPERATOR_NAME}/crds
213224
repo=${OPERATOR_NAME} envsubst < ./config/local-development/tilt/env-replace-image.yaml > ./config/local-development/tilt/replace-image.yaml
@@ -220,15 +231,80 @@ helmchart: kustomize
220231
version=${VERSION} image_repo=$${IMG%:*} envsubst < ./config/helmchart/values.yaml.tpl > ./charts/${OPERATOR_NAME}/values.yaml
221232
sed -i '1s/^/{{ if .Values.enableMonitoring }}/' ./charts/${OPERATOR_NAME}/templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME}-controller-manager-metrics-monitor.yaml
222233
echo {{ end }} >> ./charts/${OPERATOR_NAME}/templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME}-controller-manager-metrics-monitor.yaml
223-
helm lint ./charts/${OPERATOR_NAME}
234+
$(HELM) lint ./charts/${OPERATOR_NAME}
224235

225236
helmchart-repo: helmchart
226237
mkdir -p ${HELM_REPO_DEST}/${OPERATOR_NAME}
227-
helm package -d ${HELM_REPO_DEST}/${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
228-
helm repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
238+
$(HELM) package -d ${HELM_REPO_DEST}/${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
239+
$(HELM) repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
229240

230241
helmchart-repo-push: helmchart-repo
231242
git -C ${HELM_REPO_DEST} add .
232243
git -C ${HELM_REPO_DEST} status
233244
git -C ${HELM_REPO_DEST} commit -m "Release ${VERSION}"
234245
git -C ${HELM_REPO_DEST} push origin "gh-pages"
246+
247+
HELM_TEST_IMG_NAME ?= ${OPERATOR_NAME}
248+
HELM_TEST_IMG_TAG ?= helmchart-test
249+
250+
# Deploy the helmchart to a kind cluster to test deployment.
251+
# If the test-metrics sidecar in the prometheus pod is ready, the metrics work and the test is successful.
252+
.PHONY: helmchart-test
253+
helmchart-test: kind-setup helmchart
254+
$(MAKE) IMG=${HELM_TEST_IMG_NAME}:${HELM_TEST_IMG_TAG} docker-build
255+
docker tag ${HELM_TEST_IMG_NAME}:${HELM_TEST_IMG_TAG} docker.io/library/${HELM_TEST_IMG_NAME}:${HELM_TEST_IMG_TAG}
256+
$(KIND) load docker-image ${HELM_TEST_IMG_NAME}:${HELM_TEST_IMG_TAG} docker.io/library/${HELM_TEST_IMG_NAME}:${HELM_TEST_IMG_TAG}
257+
$(HELM) repo add jetstack https://charts.jetstack.io
258+
$(HELM) install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.7.1 --set installCRDs=true
259+
$(HELM) repo add prometheus-community https://prometheus-community.github.io/helm-charts
260+
$(HELM) install kube-prometheus-stack prometheus-community/kube-prometheus-stack -n default -f integration/kube-prometheus-stack-values.yaml
261+
$(HELM) install prometheus-rbac integration/helm/prometheus-rbac -n default
262+
$(HELM) upgrade -i ${OPERATOR_NAME}-local charts/${OPERATOR_NAME} -n ${OPERATOR_NAME}-local --create-namespace \
263+
--set enableCertManager=true \
264+
--set image.repository=${HELM_TEST_IMG_NAME} \
265+
--set image.tag=${HELM_TEST_IMG_TAG}
266+
$(KUBECTL) wait --namespace ${OPERATOR_NAME}-local --for=condition=ready pod --selector=app.kubernetes.io/name=${OPERATOR_NAME} --timeout=90s
267+
$(KUBECTL) wait --namespace default --for=condition=ready pod prometheus-kube-prometheus-stack-prometheus-0 --timeout=180s
268+
$(KUBECTL) exec prometheus-kube-prometheus-stack-prometheus-0 -n default -c test-metrics -- /bin/sh -c "echo 'Example metrics...' && cat /tmp/ready"
269+
270+
.PHONY: kind
271+
KIND = ./bin/kind
272+
kind: ## Download kind locally if necessary.
273+
ifeq (,$(wildcard $(KIND)))
274+
ifeq (,$(shell which kind 2>/dev/null))
275+
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@${KIND_VERSION})
276+
else
277+
KIND = $(shell which kind)
278+
endif
279+
endif
280+
281+
.PHONY: kubectl
282+
KUBECTL = ./bin/kubectl
283+
kubectl: ## Download kubectl locally if necessary.
284+
ifeq (,$(wildcard $(KUBECTL)))
285+
ifeq (,$(shell which kubectl 2>/dev/null))
286+
echo "Downloading ${KUBECTL} for managing k8s resources."
287+
OS=$(shell go env GOOS) ;\
288+
ARCH=$(shell go env GOARCH) ;\
289+
curl --create-dirs -sSLo ${KUBECTL} https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/$${OS}/$${ARCH}/kubectl ;\
290+
chmod +x ${KUBECTL}
291+
else
292+
KUBECTL = $(shell which kubectl)
293+
endif
294+
endif
295+
296+
.PHONY: helm
297+
HELM = ./bin/helm
298+
helm: ## Download helm locally if necessary.
299+
ifeq (,$(wildcard $(HELM)))
300+
ifeq (,$(shell which helm 2>/dev/null))
301+
echo "Downloading ${HELM}."
302+
OS=$(shell go env GOOS) ;\
303+
ARCH=$(shell go env GOARCH) ;\
304+
curl --create-dirs -sSLo ${HELM}.tar.gz https://get.helm.sh/helm-${HELM_VERSION}-$${OS}-$${ARCH}.tar.gz ;\
305+
tar -xf ${HELM}.tar.gz -C ./bin/ ;\
306+
mv ./bin/$${OS}-$${ARCH}/helm ${HELM}
307+
else
308+
HELM = $(shell which helm)
309+
endif
310+
endif
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
- op: add
22
path: /metadata/annotations
33
value:
4-
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/webhook-server-cert"
4+
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/serving-cert"

config/helmchart/templates/certificate.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,17 @@ spec:
1818
kind: Issuer
1919
name: selfsigned-issuer
2020
secretName: webhook-server-cert
21+
---
22+
apiVersion: cert-manager.io/v1
23+
kind: Certificate
24+
metadata:
25+
name: metrics-serving-cert
26+
spec:
27+
dnsNames:
28+
- patch-operator-controller-manager-metrics-service.{{ .Release.Namespace }}.svc
29+
- patch-operator-controller-manager-metrics-service.{{ .Release.Namespace }}.svc.cluster.local
30+
issuerRef:
31+
kind: Issuer
32+
name: selfsigned-issuer
33+
secretName: patch-operator-certs
2134
{{ end }}

config/helmchart/templates/manager.yaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
selector:
99
matchLabels:
1010
{{- include "patch-operator.selectorLabels" . | nindent 6 }}
11+
control-plane: patch-operator
1112
replicas: {{ .Values.replicaCount }}
1213
template:
1314
metadata:
@@ -17,7 +18,7 @@ spec:
1718
{{- end }}
1819
labels:
1920
{{- include "patch-operator.selectorLabels" . | nindent 8 }}
20-
operator: patch-operator
21+
control-plane: patch-operator
2122
spec:
2223
serviceAccountName: controller-manager
2324
{{- with .Values.imagePullSecrets }}
@@ -39,7 +40,7 @@ spec:
3940
name: https
4041
volumeMounts:
4142
- mountPath: /etc/certs/tls
42-
name: tls-cert
43+
name: patch-operator-certs
4344
imagePullPolicy: {{ .Values.kube_rbac_proxy.image.pullPolicy }}
4445
resources:
4546
{{- toYaml .Values.kube_rbac_proxy.resources | nindent 10 }}
@@ -50,7 +51,7 @@ spec:
5051
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
5152
imagePullPolicy: {{ .Values.image.pullPolicy }}
5253
volumeMounts:
53-
- name: cert
54+
- name: webhook-server-cert
5455
readOnly: true
5556
mountPath: /tmp/k8s-webhook-server/serving-certs
5657
{{- with .Values.env }}
@@ -85,11 +86,11 @@ spec:
8586
{{- toYaml . | nindent 8 }}
8687
{{- end }}
8788
volumes:
88-
- name: tls-cert
89+
- name: patch-operator-certs
8990
secret:
9091
defaultMode: 420
9192
secretName: patch-operator-certs
92-
- name: cert
93+
- name: webhook-server-cert
9394
secret:
9495
secretName: webhook-server-cert
9596
defaultMode: 420

config/manager/manager.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
labels:
5-
control-plane: controller-manager
5+
control-plane: patch-operator
66
openshift.io/cluster-monitoring: "true"
77
name: system
88
---
@@ -12,16 +12,16 @@ metadata:
1212
name: controller-manager
1313
namespace: system
1414
labels:
15-
control-plane: controller-manager
15+
control-plane: patch-operator
1616
spec:
1717
selector:
1818
matchLabels:
19-
control-plane: controller-manager
19+
control-plane: patch-operator
2020
replicas: 1
2121
template:
2222
metadata:
2323
labels:
24-
control-plane: controller-manager
24+
control-plane: patch-operator
2525
spec:
2626
securityContext:
2727
runAsNonRoot: true
@@ -38,12 +38,14 @@ spec:
3838
httpGet:
3939
path: /healthz
4040
port: 8081
41+
scheme: HTTP
4142
initialDelaySeconds: 15
4243
periodSeconds: 20
4344
readinessProbe:
4445
httpGet:
4546
path: /readyz
4647
port: 8081
48+
scheme: HTTP
4749
initialDelaySeconds: 5
4850
periodSeconds: 10
4951
resources:

0 commit comments

Comments
 (0)