From a1b26bfdabf3545e002507b40c3b624a23fc261e Mon Sep 17 00:00:00 2001 From: Lishen Yao Date: Tue, 5 Sep 2023 11:18:00 +0800 Subject: [PATCH 1/3] Add sn-platform-slim chart ArgoCD hook test --- .../argocd-hook/argocd-hook-rbac.yaml | 65 +++++++++++++++++++ .../argocd-hook/test-pulsar-producer.yaml | 23 +++++++ charts/sn-platform-slim/values.yaml | 8 +++ 3 files changed, 96 insertions(+) create mode 100644 charts/sn-platform-slim/templates/argocd-hook/argocd-hook-rbac.yaml create mode 100644 charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml diff --git a/charts/sn-platform-slim/templates/argocd-hook/argocd-hook-rbac.yaml b/charts/sn-platform-slim/templates/argocd-hook/argocd-hook-rbac.yaml new file mode 100644 index 000000000..d279e6fbc --- /dev/null +++ b/charts/sn-platform-slim/templates/argocd-hook/argocd-hook-rbac.yaml @@ -0,0 +1,65 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +{{- if .Values.argocd_hook.enabled }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "{{ template "pulsar.fullname" . }}-argocd-hook-serviceaccount" + namespace: {{ template "pulsar.namespace" . }} + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: "{{ template "pulsar.fullname" . }}-argocd-hook-role" + namespace: {{ template "pulsar.namespace" . }} + labels: + app: {{ template "pulsar.name" . }} + chart: {{ template "pulsar.chart" . }} + release: {{ .Release.Name }} +rules: + - apiGroups: [ "" ] + resources: [ "pods/exec" ] + verbs: [ "create" ] + - apiGroups: [ "" ] + resources: + - pods + verbs: + - list + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: "{{ template "pulsar.fullname" . }}-argocd-hook-role-binding" + namespace: {{ template "pulsar.namespace" . }} + labels: + app: {{ template "pulsar.name" . }} + chart: {{ template "pulsar.chart" . }} + release: {{ .Release.Name }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: "{{ template "pulsar.fullname" . }}-argocd-hook-role" +subjects: + - kind: ServiceAccount + name: "{{ template "pulsar.fullname" . }}-argocd-hook-serviceaccount" + namespace: {{ template "pulsar.namespace" . }} +{{- end }} diff --git a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml new file mode 100644 index 000000000..a32cc16d3 --- /dev/null +++ b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml @@ -0,0 +1,23 @@ +{{- if .Values.argocd_hook.tests.test_pulsar_producer }} +apiVersion: batch/v1 +kind: Job +metadata: + generateName: test-pulsar-producer- + annotations: + argocd.argoproj.io/hook: PostSync +spec: + template: + spec: + serviceAccountName: {{ template "pulsar.fullname" . }}-argocd-hook-serviceaccount + containers: + - name: pulsar-producer + image: "bitnami/kubectl" + command: + - | + kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-admin clusters list + kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-admin namespaces create public/test + kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsarctl clusters list + kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-client produce -m "test-message" public/test/test-topic + restartPolicy: Never + backoffLimit: 2 +{{- end }} diff --git a/charts/sn-platform-slim/values.yaml b/charts/sn-platform-slim/values.yaml index 8fabbca96..0d0438bc4 100644 --- a/charts/sn-platform-slim/values.yaml +++ b/charts/sn-platform-slim/values.yaml @@ -114,6 +114,14 @@ monitoring: # monitoring - datadog datadog: false +### ArgoCD Hook +## +## Control what hooks to run after deploying sn-platform-slim chart +argocd_hook: + tests: + test_pulsar_producer: false + enabled: false + ## Images ## ## Control what images to use for each component From aaa25b974394f98500a013d4e3efcb7ada27ef3f Mon Sep 17 00:00:00 2001 From: Lishen Yao Date: Tue, 5 Sep 2023 11:23:11 +0800 Subject: [PATCH 2/3] Add sn-platform-slim chart ArgoCD hook test --- .../argocd-hook/test-pulsar-producer.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml index a32cc16d3..cf630378d 100644 --- a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml +++ b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml @@ -1,3 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + {{- if .Values.argocd_hook.tests.test_pulsar_producer }} apiVersion: batch/v1 kind: Job From 8e7a0002cd99afd11aec146a9da4ac6535db9dc7 Mon Sep 17 00:00:00 2001 From: Lishen Yao Date: Tue, 5 Sep 2023 12:27:32 +0800 Subject: [PATCH 3/3] Separate ArgoCD hook test cases --- ...r-producer.yaml => test-pulsar-admin.yaml} | 12 +++--- .../argocd-hook/test-pulsar-pulsarctl.yaml | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) rename charts/sn-platform-slim/templates/argocd-hook/{test-pulsar-producer.yaml => test-pulsar-admin.yaml} (68%) create mode 100644 charts/sn-platform-slim/templates/argocd-hook/test-pulsar-pulsarctl.yaml diff --git a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-admin.yaml similarity index 68% rename from charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml rename to charts/sn-platform-slim/templates/argocd-hook/test-pulsar-admin.yaml index cf630378d..d67f3c47b 100644 --- a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-producer.yaml +++ b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-admin.yaml @@ -21,7 +21,7 @@ apiVersion: batch/v1 kind: Job metadata: - generateName: test-pulsar-producer- + generateName: test-pulsar-admin- annotations: argocd.argoproj.io/hook: PostSync spec: @@ -32,11 +32,9 @@ spec: - name: pulsar-producer image: "bitnami/kubectl" command: - - | - kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-admin clusters list - kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-admin namespaces create public/test - kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsarctl clusters list - kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-client produce -m "test-message" public/test/test-topic + - "bin/bash" + - "-c" + - "kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsar-admin clusters list" restartPolicy: Never - backoffLimit: 2 + backoffLimit: 1 {{- end }} diff --git a/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-pulsarctl.yaml b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-pulsarctl.yaml new file mode 100644 index 000000000..7a17d5c64 --- /dev/null +++ b/charts/sn-platform-slim/templates/argocd-hook/test-pulsar-pulsarctl.yaml @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +{{- if .Values.argocd_hook.tests.test_pulsar_producer }} +apiVersion: batch/v1 +kind: Job +metadata: + generateName: test-pulsar-pulsarctl- + annotations: + argocd.argoproj.io/hook: PostSync +spec: + template: + spec: + serviceAccountName: {{ template "pulsar.fullname" . }}-argocd-hook-serviceaccount + containers: + - name: pulsar-producer + image: "bitnami/kubectl" + command: + - "bin/bash" + - "-c" + - "kubectl exec -n sn-platform-test sn-platform-slim-toolset-0 -- bin/pulsarctl clusters list" + restartPolicy: Never + backoffLimit: 1 +{{- end }}