Initial commit from kro/examples/aws/eks-cluster-mgmt

This commit is contained in:
2026-04-21 09:55:53 -03:00
parent 0585444299
commit 7d11fd5889
66 changed files with 3667 additions and 0 deletions
@@ -0,0 +1,58 @@
{{/*
Template to generate additional resources configuration
*/}}
{{- define "application-sets.additionalResources" -}}
{{- $chartName := .chartName -}}
{{- $chartConfig := .chartConfig -}}
{{- $valueFiles := .valueFiles -}}
{{- $additionalResourcesType := .additionalResourcesType -}}
{{- $additionalResourcesPath := .path -}}
{{- $values := .values -}}
{{- if $chartConfig.additionalResources.path }}
- repoURL: {{ $values.repoURLGit | squote }}
targetRevision: {{ $values.repoURLGitRevision | squote }}
path: {{- if eq $additionalResourcesType "manifests" }}
'{{ $values.repoURLGitBasePath }}{{ if $values.useValuesFilePrefix }}{{ $values.valuesFilePrefix }}{{ end }}clusters/{{`{{.nameNormalized}}`}}/{{ $chartConfig.additionalResources.manifestPath }}'
{{- else }}
{{ $chartConfig.additionalResources.path | squote }}
{{- end}}
{{- end }}
{{- if $chartConfig.additionalResources.chart }}
- repoURL: '{{$chartConfig.additionalResources.repoURL}}'
chart: '{{$chartConfig.additionalResources.chart}}'
targetRevision: '{{$chartConfig.additionalResources.chartVersion }}'
{{- end }}
{{- if $chartConfig.additionalResources.helm }}
helm:
releaseName: '{{`{{ .name }}`}}-{{ $chartConfig.additionalResources.helm.releaseName }}'
{{- if $chartConfig.additionalResources.helm.valuesObject }}
valuesObject:
{{- $chartConfig.additionalResources.helm.valuesObject | toYaml | nindent 6 }}
{{- end }}
ignoreMissingValueFiles: true
valueFiles:
{{- include "application-sets.valueFiles" (dict
"nameNormalize" $chartName
"valueFiles" $valueFiles
"values" $values
"chartType" $additionalResourcesType) | nindent 6 }}
{{- end }}
{{- end }}
{{/*
Define the values path for reusability
*/}}
{{- define "application-sets.valueFiles" -}}
{{- $nameNormalize := .nameNormalize -}}
{{- $chartConfig := .chartConfig -}}
{{- $valueFiles := .valueFiles -}}
{{- $chartType := .chartType -}}
{{- $values := .values -}}
{{- with .valueFiles }}
{{- range . }}
- $values/{{ $values.repoURLGitBasePath }}{{ . }}/{{ $nameNormalize }}{{ if $chartType }}/{{ $chartType }}{{ end }}/{{ if $chartConfig.valuesFileName }}{{ $chartConfig.valuesFileName }}{{ else }}values.yaml{{ end }}
- $values/{{ $values.repoURLGitBasePath }}{{ if $values.useValuesFilePrefix }}{{ $values.valuesFilePrefix }}{{ end }}{{ . }}/{{ $nameNormalize }}{{ if $chartType }}/{{ $chartType }}{{ end }}/{{ if $chartConfig.valuesFileName }}{{ $chartConfig.valuesFileName }}{{ else }}values.yaml{{ end }}
{{- end }}
{{- end }}
{{- end }}
@@ -0,0 +1,37 @@
# {{/*
# Template creating git matrix generator
# */}}
# {{- define "application-sets.git-matrix" -}}
# {{- $chartName := .chartName -}}
# {{- $chartConfig := .chartConfig -}}
# {{- $repoURLGit := .repoURLGit -}}
# {{- $repoURLGitRevision := .repoURLGitRevision -}}
# {{- $selectors := .selectors -}}
# {{- $useSelectors := .useSelectors -}}
# generators:
# - matrix:
# generators:
# - clusters:
# selector:
# matchLabels:
# argocd.argoproj.io/secret-type: cluster
# {{- if $selectors }}
# {{- toYaml $selectors | nindent 16 }}
# - key: fleet_member
# operator: NotIn
# values: ['control-plane']
# {{- end }}
# {{- if $chartConfig.selectorMatchLabels }}
# {{- toYaml $chartConfig.selectorMatchLabels | nindent 18 }}
# {{- end }}
# {{- if and $chartConfig.selector $useSelectors }}
# {{- toYaml $chartConfig.selector | nindent 16 }}
# {{- end }}
# values:
# chart: {{ $chartConfig.chartName | default $chartName | quote }}
# - git:
# repoURL: {{ $repoURLGit | squote }}
# revision: {{ $repoURLGitRevision | squote }}
# files:
# - path: {{ $chartConfig.matrixPath | squote }}
# {{- end }}
@@ -0,0 +1,48 @@
{{/*
Expand the name of the chart. Defaults to `.Chart.Name` or `nameOverride`.
*/}}
{{- define "application-sets.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Generate a fully qualified app name.
If `fullnameOverride` is defined, it uses that; otherwise, it constructs the name based on `Release.Name` and chart name.
*/}}
{{- define "application-sets.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name (default .Chart.Name .Values.nameOverride) | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{/*
Create chart name and version, useful for labels.
*/}}
{{- define "application-sets.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels for the ApplicationSet, including version and managed-by labels.
*/}}
{{- define "application-sets.labels" -}}
helm.sh/chart: {{ include "application-sets.chart" . }}
app.kubernetes.io/name: {{ include "application-sets.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Common Helm and Kubernetes Annotations
*/}}
{{- define "application-sets.annotations" -}}
helm.sh/chart: {{ include "application-sets.chart" . }}
{{- if .Values.annotations }}
{{ toYaml .Values.annotations }}
{{- end }}
{{- end }}
@@ -0,0 +1,27 @@
{{/*
Template to generate pod-identity configuration
*/}}
{{- define "application-sets.pod-identity" -}}
{{- $chartName := .chartName -}}
{{- $chartConfig := .chartConfig -}}
{{- $valueFiles := .valueFiles -}}
{{- $values := .values -}}
- repoURL: '{{ $values.repoURLGit }}'
targetRevision: '{{ $values.repoURLGitRevision }}'
path: 'charts/pod-identity'
helm:
releaseName: '{{`{{ .name }}`}}-{{ $chartConfig.chartName | default $chartName }}'
valuesObject:
create: '{{`{{default "`}}{{ $chartConfig.enableACK }}{{`" (index .metadata.annotations "ack_create")}}`}}'
region: '{{`{{ .metadata.annotations.aws_region }}`}}'
accountId: '{{`{{ .metadata.annotations.aws_account_id}}`}}'
podIdentityAssociation:
clusterName: '{{`{{ .name }}`}}'
namespace: '{{ default $chartConfig.namespace .namespace }}'
ignoreMissingValueFiles: true
valueFiles:
{{- include "application-sets.valueFiles" (dict
"nameNormalize" $chartName
"valueFiles" $valueFiles
"values" $values "chartType" "pod-identity") | nindent 6 }}
{{- end }}
@@ -0,0 +1,177 @@
{{- $values := .Values }}
{{- $chartType := .Values.chartType }}
{{- $namespace := .Values.namespace }}
{{- $syncPolicy := .Values.syncPolicy -}}
{{- $syncPolicyAppSet := .Values.syncPolicyAppSet -}}
{{- $goTemplateOptions := .Values.goTemplateOptions -}}
{{- $repoURLGit := .Values.repoURLGit -}}
{{- $repoURLGitRevision := .Values.repoURLGitRevision -}}
{{- $repoURLGitBasePath := .Values.repoURLGitBasePath -}}
{{- $valueFiles := .Values.valueFiles -}}
{{- $valuesFilePrefix := .Values.valuesFilePrefix -}}
{{- $useValuesFilePrefix := (default false .Values.useValuesFilePrefix ) -}}
{{- $useSelectors:= .Values.useSelectors -}}
{{- $globalSelectors := .Values.globalSelectors -}}
{{- range $chartName, $chartConfig := .Values }}
{{- if and (kindIs "map" $chartConfig) (hasKey $chartConfig "enabled") }}
{{- if eq (toString $chartConfig.enabled) "true" }}
{{- $nameNormalize := printf "%s" $chartName | replace "_" "-" | trunc 63 | trimSuffix "-" -}}
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: {{ $nameNormalize }}
namespace: {{ default "argocd" $namespace }}
annotations:
{{- include "application-sets.annotations" $ | nindent 4 }}
{{- if $chartConfig.annotationsAppSet }}{{- toYaml $chartConfig.annotationsAppSet | nindent 4 }}{{- end }}
labels:
{{- include "application-sets.labels" $ | nindent 4 }}
{{- if $chartConfig.labelsAppSet }}{{- toYaml $chartConfig.labelsAppSet | nindent 4 }}{{- end }}
spec:
goTemplate: true
{{- if $chartConfig.goTemplateOptions }}
goTemplateOptions:
{{ toYaml $chartConfig.goTemplateOptions | nindent 2 }}
{{- else }}
goTemplateOptions: {{ default (list "missingkey=error") $goTemplateOptions }}
{{- end }}
{{- if $chartConfig.syncPolicyAppSet }}
syncPolicy:
{{- toYaml $chartConfig.syncPolicyAppSet | nindent 4 }}
{{- else }}
syncPolicy:
{{- toYaml $syncPolicyAppSet | nindent 4 }}
{{- end }}
{{- if $chartConfig.gitMatrix }}
{{ include "application-sets.git-matrix" (dict
"chartName" $nameNormalize "chartConfig" $chartConfig
"repoURLGit" $repoURLGit "repoURLGitRevision" $repoURLGitRevision
"selectors" $globalSelectors "useSelectors" $useSelectors
) | nindent 2 }}
{{- else }}
generators:
{{- if $chartConfig.environments }}
- merge:
mergeKeys: [server]
generators:
{{- end }}
- clusters:
selector:
matchLabels:
argocd.argoproj.io/secret-type: cluster
{{- if $globalSelectors }}
{{- toYaml $globalSelectors | nindent 18 }}
{{- end }}
{{- if $chartConfig.selectorMatchLabels }}
{{- toYaml $chartConfig.selectorMatchLabels | nindent 18 }}
{{- end }}
{{- if and $chartConfig.selector $useSelectors }}
{{- toYaml $chartConfig.selector | nindent 16 }}
# If you want you can excluste some clusters based on their membership
# - key: fleet_member
# operator: NotIn
# values: ['control-plane']
{{- end }}
{{- if not $chartConfig.resourceGroup }}
values:
addonChart: {{ $chartConfig.chartName | default $nameNormalize | quote }}
{{- if $chartConfig.defaultVersion }}
addonChartVersion: {{ $chartConfig.defaultVersion | quote }}
{{- end }}
{{- if $chartConfig.chartRepository }}
addonChartRepository: {{ $chartConfig.chartRepository | quote }}
{{- end }}
{{- if $chartConfig.chartNamespace }}
addonChartRepositoryNamespace: {{ $chartConfig.chartNamespace | quote }}
chart: {{ printf "%s/%s" $chartConfig.chartNamespace ($chartConfig.chartName | default $nameNormalize) | quote }}
{{- else }}
chart: {{ $chartConfig.chartName | default $nameNormalize | quote }}
{{- end }}
{{- end }}
{{- if $chartConfig.environments }}
{{- range $chartConfig.environments }}
- clusters:
selector:
matchLabels:
{{- toYaml .selector | nindent 18 }}
values:
addonChartVersion: {{ .chartVersion | default $chartConfig.defaultVersion | quote }}
{{- end }}
{{- end }}
{{- end }}
template:
metadata:
{{- if $chartConfig.appSetName }}
name: {{ $chartConfig.appSetName }}
{{- else }}
name: '{{ $nameNormalize }}-{{`{{ .name }}`}}'
{{- end }}
spec:
project: default
sources:
- repoURL: {{ $repoURLGit | squote}}
targetRevision: {{ $repoURLGitRevision | squote }}
ref: values
{{- if eq (toString $chartConfig.enableACK ) "true" }}
{{ include "application-sets.pod-identity" (dict
"chartName" ($chartConfig.chartName | default $nameNormalize)
"valueFiles" $valueFiles
"chartConfig" $chartConfig "values" $values ) | nindent 6 }}
{{- end }}
{{- if $chartConfig.path }}
- repoURL: {{ $repoURLGit | squote }}
path: {{$chartConfig.path | squote }}
targetRevision: {{ $repoURLGitRevision | squote }}
{{- else }}
- repoURL: '{{`{{ .values.addonChartRepository }}`}}'
chart: '{{`{{ .values.chart }}`}}'
targetRevision: '{{`{{.values.addonChartVersion }}`}}'
{{- end }}
{{- if ne (default "" $chartConfig.type) "manifest" }}
helm:
releaseName: {{ default "{{ .values.addonChart }}" $chartConfig.releaseName | squote }}
ignoreMissingValueFiles: true
{{- if $chartConfig.valuesObject }}
valuesObject:
{{- $chartConfig.valuesObject | toYaml | nindent 12 }}
{{- end }}
{{- if $valueFiles }}
valueFiles:
{{- include "application-sets.valueFiles" (dict
"nameNormalize" ($chartConfig.chartName | default $nameNormalize)
"chartConfig" $chartConfig
"valueFiles" $valueFiles "values" $values) | nindent 12 }}
{{- end }}
{{- if $chartConfig.additionalResources}}
{{ include "application-sets.additionalResources" (dict
"chartName" ($chartConfig.chartName | default $nameNormalize)
"valueFiles" $valueFiles
"chartConfig" $chartConfig
"values" $values
"additionalResourcesType" $chartConfig.additionalResources.type
"additionalResourcesPath" $chartConfig.additionalResources.path ) | nindent 6 }}
{{- end}}
{{- end }}
destination:
namespace: '{{ $chartConfig.namespace }}'
name: '{{`{{ .name }}`}}'
{{- if $chartConfig.syncPolicy }}
syncPolicy:
{{- toYaml $chartConfig.syncPolicy | nindent 8 }}
{{ else }}
syncPolicy:
{{- toYaml $syncPolicy | nindent 8 }}
{{- end }}
{{- with $chartConfig.ignoreDifferences }}
ignoreDifferences:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if $chartConfig.ignoreDifferences}}
ignoreDifferences:
{{- $chartConfig.ignoreDifferences | toYaml | nindent 8 }}
{{- end }}
---
{{- end }}
{{- end }}
{{- end }}