From 5b0784c7c2659069e651fb1a0019ffba3f0ddbda Mon Sep 17 00:00:00 2001
From: Lucas Cavalcante <lucasmedeiros.cavalcante@windriver.com>
Date: Fri, 8 Apr 2022 11:13:48 -0300
Subject: [PATCH] Add FluxCD version of platform-integ-app

Add new manifest files for the FluxCD version of platform-integ-apps

This creates two tarballs, one for aramada and one for FluxCD

* job-ceph-pools-audit.yaml change to support helmv3

Differences from armada-app:
 * Helm-toolkit release is disabled as it is included in other charts

Test (AIO-SX):

PASS: Application is applied

Story: 2009138
Task: 45118
Depends-on: https://review.opendev.org/c/starlingx/config/+/838321
Signed-off-by: Lucas Cavalcante <lucasmedeiros.cavalcante@windriver.com>
Change-Id: I417d6b7cf6a12968f36a1045dc98c2c26579a9b8
---
 centos_iso_image.inc                          |  2 +
 stx-platform-helm/centos/build_srpm.data      |  3 ++
 .../centos/stx-platform-helm.spec             | 45 ++++++++++++++++---
 .../fluxcd-manifests/base/helmrepository.yaml | 13 ++++++
 .../fluxcd-manifests/base/kustomization.yaml  |  8 ++++
 .../fluxcd-manifests/base/namespace.yaml      | 10 +++++
 .../ceph-pools-audit-static-overrides.yaml    | 10 +++++
 .../ceph-pools-audit-system-overrides.yaml    |  0
 .../ceph-pools-audit/helmrelease.yaml         | 36 +++++++++++++++
 .../ceph-pools-audit/kustomization.yaml       | 18 ++++++++
 .../cephfs-provisioner-static-overrides.yaml  | 11 +++++
 .../cephfs-provisioner-system-overrides.yaml  |  0
 .../cephfs-provisioner/helmrelease.yaml       | 36 +++++++++++++++
 .../cephfs-provisioner/kustomization.yaml     | 18 ++++++++
 .../fluxcd-manifests/kustomization.yaml       | 14 ++++++
 .../rbd-provisioner/helmrelease.yaml          | 36 +++++++++++++++
 .../rbd-provisioner/kustomization.yaml        | 18 ++++++++
 .../rbd-provisioner-static-overrides.yaml     | 11 +++++
 .../rbd-provisioner-system-overrides.yaml     |  0
 .../templates/job-ceph-pools-audit.yaml       |  2 +-
 20 files changed, 285 insertions(+), 6 deletions(-)
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/helmrepository.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/kustomization.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/namespace.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-static-overrides.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-system-overrides.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/helmrelease.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/kustomization.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-static-overrides.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-system-overrides.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/helmrelease.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/kustomization.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/kustomization.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/helmrelease.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/kustomization.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-static-overrides.yaml
 create mode 100644 stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-system-overrides.yaml

diff --git a/centos_iso_image.inc b/centos_iso_image.inc
index cf5f980..a5bea35 100644
--- a/centos_iso_image.inc
+++ b/centos_iso_image.inc
@@ -1 +1,3 @@
 stx-platform-helm
+stx-platform-helm-fluxcd
+
diff --git a/stx-platform-helm/centos/build_srpm.data b/stx-platform-helm/centos/build_srpm.data
index cc5c926..1c6078a 100644
--- a/stx-platform-helm/centos/build_srpm.data
+++ b/stx-platform-helm/centos/build_srpm.data
@@ -1,5 +1,8 @@
 SRC_DIR="stx-platform-helm"
 
+COPY_LIST="$PKG_BASE/$SRC_DIR/files/*"
+
+
 COPY_LIST_TO_TAR="\
     $STX_BASE/helm-charts/node-feature-discovery/node-feature-discovery/helm-charts \
 "
diff --git a/stx-platform-helm/centos/stx-platform-helm.spec b/stx-platform-helm/centos/stx-platform-helm.spec
index 8c264f5..09cab5b 100644
--- a/stx-platform-helm/centos/stx-platform-helm.spec
+++ b/stx-platform-helm/centos/stx-platform-helm.spec
@@ -31,6 +31,14 @@ BuildRequires: python-k8sapp-platform-wheels
 %description
 The StarlingX K8S application for platform integration
 
+%package fluxcd
+Summary: The StarlingX K8S Fluxcd application for platform integration
+Group: base
+License: Apache-2.0
+
+%description fluxcd
+The StarlingX K8S Fluxcd application for platform integration
+
 %prep
 %setup
 
@@ -57,7 +65,10 @@ kill %1
 
 # Create a chart tarball compliant with sysinv kube-app.py
 %define app_staging %{_builddir}/staging
-%define app_tarball %{app_name}-%{version}-%{tis_patch_ver}.tgz
+%define app_tarball_armada %{app_name}-%{version}-%{tis_patch_ver}.tgz
+%define app_tarball_fluxcd %{app_name}-fluxcd-%{version}-%{tis_patch_ver}.tgz
+%define armada_app_path %{_builddir}/%{app_tarball_armada}
+%define fluxcd_app_path %{_builddir}/%{app_tarball_fluxcd}
 
 # Setup staging
 mkdir -p %{app_staging}
@@ -76,21 +87,45 @@ sed -i 's/@HELM_REPO@/%{helm_repo}/g' %{app_staging}/metadata.yaml
 mkdir -p %{app_staging}/plugins
 cp /plugins/%{app_name}/*.whl %{app_staging}/plugins
 
-# package it up
+# calculate checksum
 find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5
-tar -zcf %{_builddir}/%{app_tarball} -C %{app_staging}/ .
+
+# package armada app
+tar -zcf %armada_app_path -C %{app_staging}/ .
+
+# switch back to source root
+cd -
+
+# Prepare app_staging for fluxcd package
+rm -f %{app_staging}/manifest.yaml
+
+cp -R fluxcd-manifests %{app_staging}/
+
+# calculate checksum of all files in app_staging
+cd %{app_staging}
+find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5
+# package fluxcd app
+tar -zcf %fluxcd_app_path -C %{app_staging}/ .
+
+# switch back to source root
+cd -
 
 # Cleanup staging
 rm -fr %{app_staging}
 
 %install
 install -d -m 755 %{buildroot}/%{app_folder}
-install -p -D -m 755 %{_builddir}/%{app_tarball} %{buildroot}/%{app_folder}
+install -p -D -m 755 %armada_app_path %{buildroot}/%{app_folder}
+install -p -D -m 755 %fluxcd_app_path %{buildroot}/%{app_folder}
 install -d -m 755 ${RPM_BUILD_ROOT}/opt/extracharts
 # TODO (rchurch): remove
 install -p -D -m 755 helm-charts/node-feature-discovery-*.tgz ${RPM_BUILD_ROOT}/opt/extracharts
 
 %files
 %defattr(-,root,root,-)
-%{app_folder}/*
+%{app_folder}/%{app_tarball_armada}
 /opt/extracharts/*
+
+%files fluxcd
+%defattr(-,root,root,-)
+%{app_folder}/%{app_tarball_fluxcd}
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/helmrepository.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/helmrepository.yaml
new file mode 100644
index 0000000..4c4adfe
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/helmrepository.yaml
@@ -0,0 +1,13 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: source.toolkit.fluxcd.io/v1beta1
+kind: HelmRepository
+metadata:
+  name: stx-platform
+spec:
+  url: http://192.168.206.1:8080/helm_charts/stx-platform
+  interval: 60m
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/kustomization.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/kustomization.yaml
new file mode 100644
index 0000000..c0f37cd
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/kustomization.yaml
@@ -0,0 +1,8 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+resources:
+  - helmrepository.yaml
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/namespace.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/namespace.yaml
new file mode 100644
index 0000000..6726614
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/base/namespace.yaml
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: kube-system
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-static-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-static-overrides.yaml
new file mode 100644
index 0000000..739c95f
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-static-overrides.yaml
@@ -0,0 +1,10 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+tolerations:
+- key: "node-role.kubernetes.io/master"
+  operator: "Exists"
+  effect: "NoSchedule"
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-system-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/ceph-pools-audit-system-overrides.yaml
new file mode 100644
index 0000000..e69de29
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/helmrelease.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/helmrelease.yaml
new file mode 100644
index 0000000..49e9b7d
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/helmrelease.yaml
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: "helm.toolkit.fluxcd.io/v2beta1"
+kind: HelmRelease
+metadata:
+  name: ceph-pools-audit
+  labels:
+    chart_group: starlingx-ceph-charts
+spec:
+  releaseName: stx-ceph-pools-audit
+  chart:
+    spec:
+      chart: ceph-pools-audit
+      version: 0.1.0
+      sourceRef:
+        kind: HelmRepository
+        name: stx-platform
+  interval: 5m
+  timeout: 30m
+  test:
+    enable: false
+  install:
+    disableHooks: false
+  upgrade:
+    disableHooks: false
+  valuesFrom:
+    - kind: Secret
+      name: ceph-pools-audit-static-overrides
+      valuesKey: ceph-pools-audit-static-overrides.yaml
+    - kind: Secret
+      name: ceph-pools-audit-system-overrides
+      valuesKey: ceph-pools-audit-system-overrides.yaml
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/kustomization.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/kustomization.yaml
new file mode 100644
index 0000000..741f875
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/ceph-pools-audit/kustomization.yaml
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+namespace: kube-system
+resources:
+  - helmrelease.yaml
+secretGenerator:
+  - name: ceph-pools-audit-static-overrides
+    files:
+      - ceph-pools-audit-static-overrides.yaml
+  - name: ceph-pools-audit-system-overrides
+    files:
+      - ceph-pools-audit-system-overrides.yaml
+generatorOptions:
+  disableNameSuffixHash: true
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-static-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-static-overrides.yaml
new file mode 100644
index 0000000..ced9442
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-static-overrides.yaml
@@ -0,0 +1,11 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+global:
+  tolerations:
+  - key: "node-role.kubernetes.io/master"
+    operator: "Exists"
+    effect: "NoSchedule"
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-system-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/cephfs-provisioner-system-overrides.yaml
new file mode 100644
index 0000000..e69de29
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/helmrelease.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/helmrelease.yaml
new file mode 100644
index 0000000..ca4323a
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/helmrelease.yaml
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: "helm.toolkit.fluxcd.io/v2beta1"
+kind: HelmRelease
+metadata:
+  name: cephfs-provisioner
+  labels:
+    chart_group: starlingx-ceph-charts
+spec:
+  releaseName: stx-cephfs-provisioner
+  chart:
+    spec:
+      chart: cephfs-provisioner
+      version: 0.1.0
+      sourceRef:
+        kind: HelmRepository
+        name: stx-platform
+  interval: 5m
+  timeout: 30m
+  test:
+    enable: false
+  install:
+    disableHooks: false
+  upgrade:
+    disableHooks: false
+  valuesFrom:
+    - kind: Secret
+      name: cephfs-provisioner-static-overrides
+      valuesKey: cephfs-provisioner-static-overrides.yaml
+    - kind: Secret
+      name: cephfs-provisioner-system-overrides
+      valuesKey: cephfs-provisioner-system-overrides.yaml
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/kustomization.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/kustomization.yaml
new file mode 100644
index 0000000..e635ad6
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/cephfs-provisioner/kustomization.yaml
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+namespace: kube-system
+resources:
+  - helmrelease.yaml
+secretGenerator:
+  - name: cephfs-provisioner-static-overrides
+    files:
+      - cephfs-provisioner-static-overrides.yaml
+  - name: cephfs-provisioner-system-overrides
+    files:
+      - cephfs-provisioner-system-overrides.yaml
+generatorOptions:
+  disableNameSuffixHash: true
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/kustomization.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/kustomization.yaml
new file mode 100644
index 0000000..5571a1e
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/kustomization.yaml
@@ -0,0 +1,14 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: kube-system
+resources:
+  - base
+  - cephfs-provisioner
+  - ceph-pools-audit
+  - rbd-provisioner
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/helmrelease.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/helmrelease.yaml
new file mode 100644
index 0000000..2d3de16
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/helmrelease.yaml
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+apiVersion: "helm.toolkit.fluxcd.io/v2beta1"
+kind: HelmRelease
+metadata:
+  name: rbd-provisioner
+  labels:
+    chart_group: starlingx-ceph-charts
+spec:
+  releaseName: stx-rbd-provisioner
+  chart:
+    spec:
+      chart: rbd-provisioner
+      version: 0.1.0
+      sourceRef:
+        kind: HelmRepository
+        name: stx-platform
+  interval: 5m
+  timeout: 30m
+  test:
+        enable: false
+  install:
+    disableHooks: false
+  upgrade:
+    disableHooks: false
+  valuesFrom:
+    - kind: Secret
+      name: rbd-provisioner-static-overrides
+      valuesKey: rbd-provisioner-static-overrides.yaml
+    - kind: Secret
+      name: rbd-provisioner-system-overrides
+      valuesKey: rbd-provisioner-system-overrides.yaml
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/kustomization.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/kustomization.yaml
new file mode 100644
index 0000000..f260f3c
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/kustomization.yaml
@@ -0,0 +1,18 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+namespace: kube-system
+resources:
+  - helmrelease.yaml
+secretGenerator:
+  - name: rbd-provisioner-static-overrides
+    files:
+      - rbd-provisioner-static-overrides.yaml
+  - name: rbd-provisioner-system-overrides
+    files:
+      - rbd-provisioner-system-overrides.yaml
+generatorOptions:
+  disableNameSuffixHash: true
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-static-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-static-overrides.yaml
new file mode 100644
index 0000000..ced9442
--- /dev/null
+++ b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-static-overrides.yaml
@@ -0,0 +1,11 @@
+#
+# Copyright (c) 2022 Wind River Systems, Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+global:
+  tolerations:
+  - key: "node-role.kubernetes.io/master"
+    operator: "Exists"
+    effect: "NoSchedule"
diff --git a/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-system-overrides.yaml b/stx-platform-helm/stx-platform-helm/fluxcd-manifests/rbd-provisioner/rbd-provisioner-system-overrides.yaml
new file mode 100644
index 0000000..e69de29
diff --git a/stx-platform-helm/stx-platform-helm/helm-charts/ceph-pools-audit/templates/job-ceph-pools-audit.yaml b/stx-platform-helm/stx-platform-helm/helm-charts/ceph-pools-audit/templates/job-ceph-pools-audit.yaml
index 85efe57..1ef3788 100644
--- a/stx-platform-helm/stx-platform-helm/helm-charts/ceph-pools-audit/templates/job-ceph-pools-audit.yaml
+++ b/stx-platform-helm/stx-platform-helm/helm-charts/ceph-pools-audit/templates/job-ceph-pools-audit.yaml
@@ -47,7 +47,7 @@ spec:
           serviceAccountName: {{ $serviceAccountName }}
           restartPolicy: OnFailure
           nodeSelector:
-            {{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }}
+            {{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value | toString | quote }}
 {{- with .Values.tolerations }}
           tolerations:
 {{ toYaml . | indent 12 }}