-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PTEUDO-1693 automation of CRD disabling flux and helm pruning (#346)
- Loading branch information
Showing
6 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Installed the CRDs for this application. Check the status of these CRDs. | ||
|
||
kubectl api-resources --api-group=persistance.atlas.infoblox.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "db-controller-crds.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "db-controller-crds.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "db-controller-crds.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "db-controller-crds.labels" -}} | ||
helm.sh/chart: {{ include "db-controller-crds.chart" . }} | ||
{{ include "db-controller-crds.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "db-controller-crds.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "db-controller-crds.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "db-controller-crds.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "db-controller-crds.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{- define "db-controller-crds.getCRDNames" -}} | ||
{{- range $path, $content := .Files.Glob "crds/*" }} | ||
{{- $crd := fromYaml (toString $content) }} {{ $crd.metadata.name }} | ||
{{- end }} | ||
{{- end }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ .Release.Name }}-hooks | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "db-controller-crds.labels" . | nindent 4 }} | ||
annotations: | ||
helm.sh/hook: "pre-install,pre-upgrade" | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: {{ .Release.Name }}-hooks | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "db-controller-crds.labels" . | nindent 4 }} | ||
annotations: | ||
helm.sh/hook: "pre-install,pre-upgrade" | ||
rules: | ||
- apiGroups: | ||
- "apiextensions.k8s.io" | ||
resources: | ||
- customresourcedefinitions | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- update | ||
- patch | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- "customresourcedefinitions/status" | ||
verbs: | ||
- update | ||
- patch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: {{ .Release.Name }}-hooks | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "db-controller-crds.labels" . | nindent 4 }} | ||
annotations: | ||
helm.sh/hook: "pre-install,pre-upgrade" | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: {{ .Release.Name }}-hooks | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ .Release.Name }}-hooks | ||
namespace: {{ .Release.Namespace }} | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: {{ .Release.Name }}-pre | ||
namespace: {{ .Release.Namespace }} | ||
labels: | ||
{{- include "db-controller-crds.labels" . | nindent 4 }} | ||
annotations: | ||
helm.sh/hook: "pre-install,pre-upgrade" | ||
spec: | ||
serviceAccountName: {{ .Release.Name }}-hooks | ||
containers: | ||
- name: wait | ||
image: {{ .Values.tools.kubectl.repository }}:{{ .Values.tools.kubectl.tag }} | ||
command: | ||
- /bin/bash | ||
- -cxe | ||
- | | ||
# Tell Flux not to delete the CRDs | ||
# https://fluxcd.io/flux/components/kustomize/kustomizations/#prune | ||
kubectl label crd | ||
{{- include "db-controller-crds.getCRDNames" . }} 'kustomize.toolkit.fluxcd.io/prune=disabled' | ||
# Tell Helm not to delete the CRDs | ||
# https://helm.sh/docs/howto/charts_tips_and_tricks/#tell-helm-not-to-uninstall-a-resource | ||
kubectl annotate crd | ||
{{- include "db-controller-crds.getCRDNames" . }} 'helm.sh/resource-policy=keep' | ||
restartPolicy: Never | ||
--- |
17 changes: 17 additions & 0 deletions
17
helm/db-controller-crds/templates/tests/test-connection.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{- if false }} | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: "{{ include "db-controller-crds.fullname" . }}-test-connection" | ||
labels: | ||
{{- include "db-controller-crds.labels" . | nindent 4 }} | ||
annotations: | ||
"helm.sh/hook": test | ||
spec: | ||
containers: | ||
- name: wget | ||
image: busybox | ||
command: ['wget'] | ||
args: ['{{ include "db-controller-crds.fullname" . }}:{{ .Values.service.port }}'] | ||
restartPolicy: Never | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
crds: | ||
# This is a hack to render CRDs even if they're installed | ||
# Use this with caution as it will also uninstall CRDs | ||
# We can now do this with CreateReplace in flux so | ||
# this is being disabled. | ||
install: false | ||
tools: | ||
kubectl: | ||
repository: bitnami/kubectl | ||
pullPolicy: IfNotPresent | ||
tag: 1.28.5 |