From de2a44e446126e7d76fd7d95a3c8bd4b9939fe5d Mon Sep 17 00:00:00 2001 From: weixiao-huang Date: Thu, 1 Sep 2022 21:58:30 +0800 Subject: [PATCH] feat(deploy): use sed for hacking generate helm manifests --- .../templates/virt-controller/manifests.yaml | 41 ++++++++++--------- hack/generate.sh | 13 ++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/deploy/helm/virtink/templates/virt-controller/manifests.yaml b/deploy/helm/virtink/templates/virt-controller/manifests.yaml index 1d7742c..78c7a2e 100644 --- a/deploy/helm/virtink/templates/virt-controller/manifests.yaml +++ b/deploy/helm/virtink/templates/virt-controller/manifests.yaml @@ -1,16 +1,18 @@ +--- apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: - name: {{ include "virtink.fullname" . }} + creationTimestamp: null + name: virt-controller annotations: - cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.virtController.name }}-cert + cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/virt-controller-cert webhooks: - admissionReviewVersions: - v1 - v1beta1 clientConfig: service: - name: {{ .Values.virtController.name }} + name: virt-controller namespace: {{ .Release.Namespace }} path: /mutate-v1alpha1-virtualmachine failurePolicy: Fail @@ -30,16 +32,17 @@ webhooks: apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - name: {{ include "virtink.fullname" . }} + creationTimestamp: null + name: virt-controller annotations: - cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.virtController.name }}-cert + cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/virt-controller-cert webhooks: - admissionReviewVersions: - v1 - v1beta1 clientConfig: service: - name: {{ .Values.virtController.name }} + name: virt-controller namespace: {{ .Release.Namespace }} path: /validate-v1alpha1-virtualmachine failurePolicy: Fail @@ -56,23 +59,23 @@ webhooks: - virtualmachines sideEffects: None - admissionReviewVersions: - - v1 - - v1beta1 + - v1 + - v1beta1 clientConfig: service: - name: {{ .Values.virtController.name }} + name: virt-controller namespace: {{ .Release.Namespace }} path: /validate-v1alpha1-virtualmachinemigration failurePolicy: Fail name: validate.virtualmachinemigration.v1alpha1.virt.virtink.smartx.com rules: - - apiGroups: - - virt.virtink.smartx.com - apiVersions: - - v1alpha1 - operations: - - CREATE - - UPDATE - resources: - - virtualmachinemigrations - sideEffects: None \ No newline at end of file + - apiGroups: + - virt.virtink.smartx.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - virtualmachinemigrations + sideEffects: None diff --git a/hack/generate.sh b/hack/generate.sh index 99de9c0..8b0075d 100755 --- a/hack/generate.sh +++ b/hack/generate.sh @@ -18,4 +18,17 @@ controller-gen paths=./cmd/virt-controller/... paths=./pkg/controller/... rbac:r controller-gen paths=./cmd/virt-daemon/... paths=./pkg/daemon/... rbac:roleName=virt-daemon \ output:rbac:artifacts:config="$dir"/virt-daemon +# TODO: should use a more elegant way for editing generated manifests.yaml +replace=" name: virt-controller + annotations: + cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/virt-controller-cert" + +# Replace newlines with literal \n, replace \ -> \/ for sed replace below +replace="$(echo "${replace//$'\n'/\\n}" | sed "s/\//\\\\\//g")" + +sed -i "s/ name: mutating-webhook-configuration/$replace/g; + s/ name: validating-webhook-configuration/$replace/g; + s/name: webhook-service/name: virt-controller/g; + s/namespace: system/namespace: {{ .Release.Namespace }}/g" "$dir"/virt-controller/manifests.yaml + go generate ./...