Skip to content

Commit

Permalink
add upgrade crds hook and stripped down crds
Browse files Browse the repository at this point in the history
Signed-off-by: frezes <[email protected]>
  • Loading branch information
frezes committed Feb 28, 2024
1 parent 42d537c commit 56a5b40
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 17,733 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ all: build

manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=charts/whizard/crds

# stripped-down-crds is a version of the whizard CRDs with all
# description fields being removed. It is meant as a workaround for the issue
# that `kubectl apply -f ...` might fail with the full version of the CRDs
# because of too long annotations field.
# See https://github.com/prometheus-operator/prometheus-operator/issues/4355
stripped-down-crds: manifests
cd config/crd/bases && \
for f in *.yaml; do \
gojsontoyaml -yamltojson < $$f | jq 'walk(if type == "object" then with_entries(if .value|type=="object" then . else select(.key | test("description") | not) end) else . end)' | gojsontoyaml > ../../../charts/whizard/crds/$$f; \
done;


generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down
1,073 changes: 2 additions & 1,071 deletions charts/whizard/crds/monitoring.whizard.io_compactors.yaml

Large diffs are not rendered by default.

830 changes: 2 additions & 828 deletions charts/whizard/crds/monitoring.whizard.io_gateways.yaml

Large diffs are not rendered by default.

1,093 changes: 2 additions & 1,091 deletions charts/whizard/crds/monitoring.whizard.io_ingesters.yaml

Large diffs are not rendered by default.

860 changes: 1 addition & 859 deletions charts/whizard/crds/monitoring.whizard.io_queries.yaml

Large diffs are not rendered by default.

832 changes: 1 addition & 831 deletions charts/whizard/crds/monitoring.whizard.io_queryfrontends.yaml

Large diffs are not rendered by default.

826 changes: 2 additions & 824 deletions charts/whizard/crds/monitoring.whizard.io_routers.yaml

Large diffs are not rendered by default.

1,207 changes: 1 addition & 1,206 deletions charts/whizard/crds/monitoring.whizard.io_rulers.yaml

Large diffs are not rendered by default.

8,706 changes: 1 addition & 8,705 deletions charts/whizard/crds/monitoring.whizard.io_services.yaml

Large diffs are not rendered by default.

931 changes: 0 additions & 931 deletions charts/whizard/crds/monitoring.whizard.io_storages.yaml

Large diffs are not rendered by default.

1,379 changes: 1 addition & 1,378 deletions charts/whizard/crds/monitoring.whizard.io_stores.yaml

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions charts/whizard/crds/monitoring.whizard.io_tenants.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand All @@ -17,17 +16,10 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Tenant is the Schema for the monitoring Tenant API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down
112 changes: 112 additions & 0 deletions charts/whizard/templates/upgrade-crds-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{{- if .Values.hook.enabled }}
{{- $crdFiles := .Files.Glob "crds/**" }}
{{- $i := 0 }}
{{- range $path, $_ := $crdFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "whizard.name" $ }}-crds-{{ $i }}
namespace: {{ include "whizard.namespace" $ }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
data:
{{ $path | base }}: |
{{- $.Files.Get $path | nindent 4 }}
---
{{- $i = add1 $i }}
{{- end }}

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "whizard.name" . }}-update-crds
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "2"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "whizard.name" . }}-update-crds
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "3"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
rules:
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- update
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "whizard.name" . }}-update-crds
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "4"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "whizard.name" . }}-update-crds
subjects:
- kind: ServiceAccount
name: {{ include "whizard.name" . }}-update-crds
namespace: {{ include "whizard.namespace" . }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "whizard.name" . }}-update-crds
namespace: {{ include "whizard.namespace" . }}
annotations:
"helm.sh/hook": post-delete
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
spec:
template:
spec:
restartPolicy: Never
serviceAccountName: {{ include "whizard.name" . }}-update-crds
volumes:
{{- $i = 0 }}
{{- range $path, $_ := $crdFiles }}
- name: crds-{{ $i }}
configMap:
name: {{ include "whizard.name" $ }}-crds-{{ $i }}
items:
- key: {{ $path | base }}
path: {{ $path | base }}
{{- $i = add1 $i }}
{{- end }}
containers:
- name: update-crds
image: {{ .Values.global.imageRegistry | default .Values.hook.image.registry }}/{{ .Values.hook.image.repository }}:{{ .Values.hook.image.tag }}
command:
- /bin/bash
- -c
- |
kubectl apply -f /data/crds 2>&1
{{- $i = 0 }}
volumeMounts:
{{- range $path, $_ := $crdFiles }}
- name: crds-{{ $i }}
mountPath: /data/crds/{{ $path | base }}
subPath: {{ $path | base }}
{{- $i = add1 $i }}
{{- end }}
{{- with .Values.hook.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions charts/whizard/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ hook:
repository: kubesphere/kubectl
tag: v1.21.0
pullPolicy: IfNotPresent
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
backoffLimit: 3

monitoring:
Expand Down

0 comments on commit 56a5b40

Please sign in to comment.