Skip to content

Commit e4d5467

Browse files
Merge pull request #212 from james-milligan/helm-ns
fix: added namespace configuration for helm install using -n
2 parents afbb063 + 15f3901 commit e4d5467

File tree

9 files changed

+80
-31
lines changed

9 files changed

+80
-31
lines changed

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ jobs:
115115
make update-flagd
116116
go mod tidy
117117
make controller-gen
118-
make helm-package
118+
IMG=ghcr.io/open-feature/open-feature-operator:${{ needs.release-please.outputs.release_tag_name }} make helm-package
119119
IMG=ghcr.io/open-feature/open-feature-operator:${{ needs.release-please.outputs.release_tag_name }} make release-manifests
120120
121121
- uses: anchore/sbom-action@v0

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
4+
# customize overlay to be used in the build, DEFAULT or HELM
5+
KUSTOMIZE_OVERLAY ?= DEFAULT
46
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
57
FLAGD_VERSION=v0.2.5
68
CHART_VERSION=v0.2.16# x-release-please-version
9+
CHART_VERSION=v0.2.16# x-release-please-version
710
ENVTEST_K8S_VERSION = 1.23
811

912
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
@@ -105,7 +108,14 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
105108
release-manifests: manifests kustomize
106109
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
107110
mkdir -p config/rendered/
108-
$(KUSTOMIZE) build config/default > config/rendered/release.yaml
111+
@if [ ${KUSTOMIZE_OVERLAY} = DEFAULT ]; then\
112+
echo building default overlay;\
113+
$(KUSTOMIZE) build config/default > config/rendered/release.yaml;\
114+
fi
115+
@if [ ${KUSTOMIZE_OVERLAY} = HELM ]; then\
116+
echo building helm overlay;\
117+
$(KUSTOMIZE) build config/overlays/helm > chart/templates/rendered.yaml;\
118+
fi
109119

110120
.PHONY: deploy
111121
deploy: generate manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
@@ -166,8 +176,11 @@ $(HELM): $(LOCALBIN)
166176
[ -e "$(HELM)" ] && rm -rf "$(HELM)" || true
167177
cd $(LOCALBIN) && curl -s $(HELM_INSTALLER) | tar -xzf - -C $(LOCALBIN)
168178

169-
helm-package: generate release-manifests helm
170-
cp config/rendered/release.yaml chart/templates/rendered.yaml
179+
.PHONY: set-helm-overlay
180+
set-helm-overlay:
181+
${eval KUSTOMIZE_OVERLAY = HELM}
182+
183+
helm-package: set-helm-overlay generate release-manifests helm
171184
$(HELM) package --version $(CHART_VERSION) chart
172185
mkdir -p charts && mv ofo-*.tgz charts
173186
$(HELM) repo index --url https://open-feature.github.io/open-feature-operator/charts charts

chart/templates/_helpers.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{/*
2+
Define the chart.namespace variable. If no namespace is defined via the command line then the default value
3+
provided in .Values.defaultNamespace is used
4+
*/}}
5+
{{- define "chart.namespace" -}}
6+
{{- if eq .Release.Namespace "default" -}}
7+
{{- .Values.defaultNamespace -}}
8+
{{- else -}}
9+
{{- .Release.Namespace -}}
10+
{{- end -}}
11+
{{- end -}}

chart/templates/namespace.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Only deploy the namespace if the default is being used (helm install should fail if the namespace isnt present)
2+
# when one is defined with -n
3+
{{ if eq ( include "chart.namespace" . ) .Values.defaultNamespace }}
4+
apiVersion: v1
5+
kind: Namespace
6+
metadata:
7+
labels:
8+
control-plane: controller-manager
9+
name: '{{ include "chart.namespace" . }}'
10+
{{ end }}

chart/templates/rendered.yaml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
apiVersion: v1
2-
kind: Namespace
3-
metadata:
4-
labels:
5-
control-plane: controller-manager
6-
name: open-feature-operator-system
7-
---
81
apiVersion: apiextensions.k8s.io/v1
92
kind: CustomResourceDefinition
103
metadata:
@@ -262,13 +255,13 @@ apiVersion: v1
262255
kind: ServiceAccount
263256
metadata:
264257
name: open-feature-operator-controller-manager
265-
namespace: open-feature-operator-system
258+
namespace: '{{ include "chart.namespace" . }}'
266259
---
267260
apiVersion: rbac.authorization.k8s.io/v1
268261
kind: Role
269262
metadata:
270263
name: open-feature-operator-leader-election-role
271-
namespace: open-feature-operator-system
264+
namespace: '{{ include "chart.namespace" . }}'
272265
rules:
273266
- apiGroups:
274267
- ""
@@ -419,15 +412,15 @@ apiVersion: rbac.authorization.k8s.io/v1
419412
kind: RoleBinding
420413
metadata:
421414
name: open-feature-operator-leader-election-rolebinding
422-
namespace: open-feature-operator-system
415+
namespace: '{{ include "chart.namespace" . }}'
423416
roleRef:
424417
apiGroup: rbac.authorization.k8s.io
425418
kind: Role
426419
name: open-feature-operator-leader-election-role
427420
subjects:
428421
- kind: ServiceAccount
429422
name: open-feature-operator-controller-manager
430-
namespace: open-feature-operator-system
423+
namespace: '{{ include "chart.namespace" . }}'
431424
---
432425
apiVersion: rbac.authorization.k8s.io/v1
433426
kind: ClusterRoleBinding
@@ -441,7 +434,7 @@ subjects:
441434
- apiGroup: ""
442435
kind: ServiceAccount
443436
name: open-feature-operator-controller-manager
444-
namespace: system
437+
namespace: '{{ include "chart.namespace" . }}'
445438
---
446439
apiVersion: rbac.authorization.k8s.io/v1
447440
kind: ClusterRoleBinding
@@ -454,7 +447,7 @@ roleRef:
454447
subjects:
455448
- kind: ServiceAccount
456449
name: open-feature-operator-controller-manager
457-
namespace: open-feature-operator-system
450+
namespace: '{{ include "chart.namespace" . }}'
458451
---
459452
apiVersion: rbac.authorization.k8s.io/v1
460453
kind: ClusterRoleBinding
@@ -467,7 +460,7 @@ roleRef:
467460
subjects:
468461
- kind: ServiceAccount
469462
name: open-feature-operator-controller-manager
470-
namespace: open-feature-operator-system
463+
namespace: '{{ include "chart.namespace" . }}'
471464
---
472465
apiVersion: v1
473466
data:
@@ -486,15 +479,15 @@ data:
486479
kind: ConfigMap
487480
metadata:
488481
name: open-feature-operator-manager-config
489-
namespace: open-feature-operator-system
482+
namespace: '{{ include "chart.namespace" . }}'
490483
---
491484
apiVersion: v1
492485
kind: Service
493486
metadata:
494487
labels:
495488
control-plane: controller-manager
496489
name: open-feature-operator-controller-manager-metrics-service
497-
namespace: open-feature-operator-system
490+
namespace: '{{ include "chart.namespace" . }}'
498491
spec:
499492
ports:
500493
- name: https
@@ -510,7 +503,7 @@ metadata:
510503
annotations:
511504
cert-manager.io/inject-ca-from: open-feature-operator-system/webhook-cert
512505
name: open-feature-operator-webhook-service
513-
namespace: open-feature-operator-system
506+
namespace: '{{ include "chart.namespace" . }}'
514507
spec:
515508
ports:
516509
- port: 443
@@ -525,7 +518,7 @@ metadata:
525518
labels:
526519
control-plane: controller-manager
527520
name: open-feature-operator-controller-manager
528-
namespace: open-feature-operator-system
521+
namespace: '{{ include "chart.namespace" . }}'
529522
spec:
530523
replicas: 1
531524
selector:
@@ -612,11 +605,11 @@ apiVersion: cert-manager.io/v1
612605
kind: Certificate
613606
metadata:
614607
name: open-feature-operator-serving-cert
615-
namespace: open-feature-operator-system
608+
namespace: '{{ include "chart.namespace" . }}'
616609
spec:
617610
dnsNames:
618-
- open-feature-operator-webhook-service.open-feature-operator-system.svc
619-
- open-feature-operator-webhook-service.open-feature-operator-system.svc.cluster.local
611+
- open-feature-operator-webhook-service.{{ include "chart.namespace" . }}.svc
612+
- open-feature-operator-webhook-service.{{ include "chart.namespace" . }}.svc.cluster.local
620613
issuerRef:
621614
kind: Issuer
622615
name: open-feature-operator-selfsigned-issuer
@@ -626,23 +619,23 @@ apiVersion: cert-manager.io/v1
626619
kind: Issuer
627620
metadata:
628621
name: open-feature-operator-selfsigned-issuer
629-
namespace: open-feature-operator-system
622+
namespace: '{{ include "chart.namespace" . }}'
630623
spec:
631624
selfSigned: {}
632625
---
633626
apiVersion: admissionregistration.k8s.io/v1
634627
kind: MutatingWebhookConfiguration
635628
metadata:
636629
annotations:
637-
cert-manager.io/inject-ca-from: open-feature-operator-system/open-feature-operator-serving-cert
630+
cert-manager.io/inject-ca-from: '{{ include "chart.namespace" . }}/open-feature-operator-serving-cert'
638631
name: open-feature-operator-mutating-webhook-configuration
639632
webhooks:
640633
- admissionReviewVersions:
641634
- v1
642635
clientConfig:
643636
service:
644637
name: open-feature-operator-webhook-service
645-
namespace: open-feature-operator-system
638+
namespace: '{{ include "chart.namespace" . }}'
646639
path: /mutate-v1-pod
647640
failurePolicy: Ignore
648641
name: mutate.openfeature.dev
@@ -662,15 +655,15 @@ apiVersion: admissionregistration.k8s.io/v1
662655
kind: ValidatingWebhookConfiguration
663656
metadata:
664657
annotations:
665-
cert-manager.io/inject-ca-from: open-feature-operator-system/open-feature-operator-serving-cert
658+
cert-manager.io/inject-ca-from: '{{ include "chart.namespace" . }}/open-feature-operator-serving-cert'
666659
name: open-feature-operator-validating-webhook-configuration
667660
webhooks:
668661
- admissionReviewVersions:
669662
- v1
670663
clientConfig:
671664
service:
672665
name: open-feature-operator-webhook-service
673-
namespace: open-feature-operator-system
666+
namespace: '{{ include "chart.namespace" . }}'
674667
path: /validate-v1alpha1-featureflagconfiguration
675668
failurePolicy: Fail
676669
name: validate.featureflagconfiguration.openfeature.dev

chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# If this namespace is changed the value must be reflected in /chart/values.yaml
2+
defaultNamespace: open-feature-operator-system
13
controllerManager:
24
kubeRbacProxy:
35
image:

config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adds namespace to all resources.
1+
# Adds namespace to all resources. If this namespace is changed the value must be reflected in /chart/values.yaml
22
namespace: open-feature-operator-system
33

44
# Value of this field is prepended to the
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$patch: delete
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: system
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# import the default deployment as the base
2+
bases:
3+
- ../../default
4+
5+
# replace the default namespace with {{ include "chart.namespace" . }}
6+
# .Release.Namespace has not been used so that a custom _helpers.tpl file can maintain the expected behaviour of
7+
# helm install -n
8+
namespace: |-
9+
{{ include "chart.namespace" . }}
10+
11+
# merge the exclude-ns.yaml with the existing namespace definition, this contains the `$patch: delete` directive allowing
12+
# for the helm chart to define the namespace conditionally (only deploys when no namespace is provided and the default
13+
# (open-feature-operator-system) is used
14+
patchesStrategicMerge:
15+
- exclude-ns.yaml

0 commit comments

Comments
 (0)