From 9311595d17276de74be7fc2a85385c412281049b Mon Sep 17 00:00:00 2001 From: Wahab Ali Date: Thu, 22 Aug 2024 01:45:40 -0400 Subject: [PATCH 1/4] Use CAPI capability of Flux's HelmRelease to install apps into target cluster --- templates/aws-standalone-cp/README.md | 11 +++++ .../templates/apps/cert-manager.yaml | 40 +++++++++++++++++++ .../templates/apps/nginx-ingress.yaml | 34 ++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 templates/aws-standalone-cp/README.md create mode 100644 templates/aws-standalone-cp/templates/apps/cert-manager.yaml create mode 100644 templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml diff --git a/templates/aws-standalone-cp/README.md b/templates/aws-standalone-cp/README.md new file mode 100644 index 000000000..c653998ec --- /dev/null +++ b/templates/aws-standalone-cp/README.md @@ -0,0 +1,11 @@ +## Install applications into Target Cluster + +To install applications into the target cluster created using Cluster API (CAPI) upon creation, a Flux `HelmRelease` object is to be made such that its `.spec.KubeConfig` references the kubeconfig of the target cluster. + +**Reference:** https://fluxcd.io/flux/components/helm/helmreleases/#remote-clusters--cluster-api + +This chart/template already defines the following applications under `templates/apps` to be installed into the target cluster: +1. cert-manager +2. nginx-ingress + +**Important:** The Flux objects added to `templates/apps` to install custom applications must have the `hmc.mirantis.com/managed: "true"` label to be reconciled by HMC. diff --git a/templates/aws-standalone-cp/templates/apps/cert-manager.yaml b/templates/aws-standalone-cp/templates/apps/cert-manager.yaml new file mode 100644 index 000000000..59e4df9c0 --- /dev/null +++ b/templates/aws-standalone-cp/templates/apps/cert-manager.yaml @@ -0,0 +1,40 @@ +apiVersion: source.toolkit.fluxcd.io/v1 +kind: HelmRepository +metadata: + name: cert-manager + labels: + hmc.mirantis.com/managed: "true" +spec: + interval: 24h + url: https://charts.jetstack.io +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: {{ include "cluster.name" . }}-cert-manager + labels: + hmc.mirantis.com/managed: "true" +spec: + chart: + metadata: + labels: + hmc.mirantis.com/managed: "true" + spec: + chart: cert-manager + version: ">=v1.12.3" + sourceRef: + kind: HelmRepository + name: cert-manager + install: + createNamespace: true + remediation: + retries: -1 + interval: 10m + kubeConfig: + secretRef: + name: {{ include "cluster.name" . }}-kubeconfig + releaseName: cert-manager + targetNamespace: cert-manager + storageNamespace: cert-manager + values: + installCRDs: true diff --git a/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml b/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml new file mode 100644 index 000000000..0d3017c6a --- /dev/null +++ b/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml @@ -0,0 +1,34 @@ +apiVersion: source.toolkit.fluxcd.io/v1beta2 +kind: OCIRepository +metadata: + name: nginx-ingress + labels: + hmc.mirantis.com/managed: "true" +spec: + interval: 24h + url: oci://ghcr.io/nginxinc/charts/nginx-ingress + ref: + semver: "1.3.2" +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: {{ include "cluster.name" . }}-nginx-ingress + labels: + hmc.mirantis.com/managed: "true" +spec: + targetNamespace: nginx-ingress + storageNamespace: nginx-ingress + kubeConfig: + secretRef: + name: {{ include "cluster.name" . }}-kubeconfig + interval: 10m + chartRef: + kind: OCIRepository + name: nginx-ingress + install: + createNamespace: true + remediation: + retries: -1 + values: + fullnameOverride: nginx-ingress From 8206e8c435361d525baf232a306d003fd2ae87ae Mon Sep 17 00:00:00 2001 From: Wahab Ali Date: Mon, 26 Aug 2024 17:32:33 -0400 Subject: [PATCH 2/4] Make installation into target cluster optional via .Values.installApps --- templates/aws-standalone-cp/README.md | 2 +- templates/aws-standalone-cp/templates/apps/cert-manager.yaml | 4 +++- templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml | 2 ++ templates/aws-standalone-cp/values.yaml | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/aws-standalone-cp/README.md b/templates/aws-standalone-cp/README.md index c653998ec..83a39630c 100644 --- a/templates/aws-standalone-cp/README.md +++ b/templates/aws-standalone-cp/README.md @@ -4,7 +4,7 @@ To install applications into the target cluster created using Cluster API (CAPI) **Reference:** https://fluxcd.io/flux/components/helm/helmreleases/#remote-clusters--cluster-api -This chart/template already defines the following applications under `templates/apps` to be installed into the target cluster: +This chart/template already defines the following applications under `templates/apps` which can be be installed into the target cluster by setting `.Values.installApps=true`: 1. cert-manager 2. nginx-ingress diff --git a/templates/aws-standalone-cp/templates/apps/cert-manager.yaml b/templates/aws-standalone-cp/templates/apps/cert-manager.yaml index 59e4df9c0..cf25e1f81 100644 --- a/templates/aws-standalone-cp/templates/apps/cert-manager.yaml +++ b/templates/aws-standalone-cp/templates/apps/cert-manager.yaml @@ -1,3 +1,4 @@ +{{- if .Values.installApps }} apiVersion: source.toolkit.fluxcd.io/v1 kind: HelmRepository metadata: @@ -21,7 +22,7 @@ spec: hmc.mirantis.com/managed: "true" spec: chart: cert-manager - version: ">=v1.12.3" + version: "v1.12.3" sourceRef: kind: HelmRepository name: cert-manager @@ -38,3 +39,4 @@ spec: storageNamespace: cert-manager values: installCRDs: true +{{- end }} diff --git a/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml b/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml index 0d3017c6a..118994fe2 100644 --- a/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml +++ b/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml @@ -1,3 +1,4 @@ +{{- if .Values.installApps }} apiVersion: source.toolkit.fluxcd.io/v1beta2 kind: OCIRepository metadata: @@ -32,3 +33,4 @@ spec: retries: -1 values: fullnameOverride: nginx-ingress +{{- end }} diff --git a/templates/aws-standalone-cp/values.yaml b/templates/aws-standalone-cp/values.yaml index 79c8e7ee1..3dd4409ad 100644 --- a/templates/aws-standalone-cp/values.yaml +++ b/templates/aws-standalone-cp/values.yaml @@ -44,3 +44,7 @@ worker: # K0s parameters k0s: version: v1.30.2+k0s.0 + +# Optionally install apps defined under +# templates/apps into target cluster +installApps: false From 0859873c23bf81f48441e98561e573fe12a28df1 Mon Sep 17 00:00:00 2001 From: Wahab Ali Date: Tue, 27 Aug 2024 09:24:33 -0400 Subject: [PATCH 3/4] Enable installation of apps into target cluster true for dev --- config/dev/deployment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/dev/deployment.yaml b/config/dev/deployment.yaml index 58ba18e32..c764f5450 100644 --- a/config/dev/deployment.yaml +++ b/config/dev/deployment.yaml @@ -15,3 +15,4 @@ spec: worker: amiID: ami-02f3416038bdb17fb instanceType: t3.small + installApps: true From a5de0c3af9c187b3a00d3547e7829a9eea6f5d65 Mon Sep 17 00:00:00 2001 From: Wahab Ali Date: Tue, 27 Aug 2024 15:10:49 -0400 Subject: [PATCH 4/4] Rename installApps to installBeachHeadServices --- config/dev/deployment.yaml | 1 - templates/aws-standalone-cp/README.md | 4 ++-- .../templates/{apps => beachheadservices}/cert-manager.yaml | 2 +- .../{apps => beachheadservices}/nginx-ingress.yaml | 2 +- templates/aws-standalone-cp/values.yaml | 6 +++--- 5 files changed, 7 insertions(+), 8 deletions(-) rename templates/aws-standalone-cp/templates/{apps => beachheadservices}/cert-manager.yaml (95%) rename templates/aws-standalone-cp/templates/{apps => beachheadservices}/nginx-ingress.yaml (94%) diff --git a/config/dev/deployment.yaml b/config/dev/deployment.yaml index c764f5450..58ba18e32 100644 --- a/config/dev/deployment.yaml +++ b/config/dev/deployment.yaml @@ -15,4 +15,3 @@ spec: worker: amiID: ami-02f3416038bdb17fb instanceType: t3.small - installApps: true diff --git a/templates/aws-standalone-cp/README.md b/templates/aws-standalone-cp/README.md index 83a39630c..268e26297 100644 --- a/templates/aws-standalone-cp/README.md +++ b/templates/aws-standalone-cp/README.md @@ -4,8 +4,8 @@ To install applications into the target cluster created using Cluster API (CAPI) **Reference:** https://fluxcd.io/flux/components/helm/helmreleases/#remote-clusters--cluster-api -This chart/template already defines the following applications under `templates/apps` which can be be installed into the target cluster by setting `.Values.installApps=true`: +This chart/template already defines the following applications under `templates/beachheadservices` which can be be installed into the target cluster by setting `.Values.installBeachHeadServices=true`: 1. cert-manager 2. nginx-ingress -**Important:** The Flux objects added to `templates/apps` to install custom applications must have the `hmc.mirantis.com/managed: "true"` label to be reconciled by HMC. +**Important:** The Flux objects added to `templates/beachheadservices` to install custom applications must have the `hmc.mirantis.com/managed: "true"` label to be reconciled by HMC. diff --git a/templates/aws-standalone-cp/templates/apps/cert-manager.yaml b/templates/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml similarity index 95% rename from templates/aws-standalone-cp/templates/apps/cert-manager.yaml rename to templates/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml index cf25e1f81..36c6b8f33 100644 --- a/templates/aws-standalone-cp/templates/apps/cert-manager.yaml +++ b/templates/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml @@ -1,4 +1,4 @@ -{{- if .Values.installApps }} +{{- if .Values.installBeachHeadServices }} apiVersion: source.toolkit.fluxcd.io/v1 kind: HelmRepository metadata: diff --git a/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml b/templates/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml similarity index 94% rename from templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml rename to templates/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml index 118994fe2..73c329159 100644 --- a/templates/aws-standalone-cp/templates/apps/nginx-ingress.yaml +++ b/templates/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml @@ -1,4 +1,4 @@ -{{- if .Values.installApps }} +{{- if .Values.installBeachHeadServices }} apiVersion: source.toolkit.fluxcd.io/v1beta2 kind: OCIRepository metadata: diff --git a/templates/aws-standalone-cp/values.yaml b/templates/aws-standalone-cp/values.yaml index 3dd4409ad..e7ac91c8a 100644 --- a/templates/aws-standalone-cp/values.yaml +++ b/templates/aws-standalone-cp/values.yaml @@ -45,6 +45,6 @@ worker: k0s: version: v1.30.2+k0s.0 -# Optionally install apps defined under -# templates/apps into target cluster -installApps: false +# Optionally install applications defined under +# templates/beachheadservices into target cluster +installBeachHeadServices: true