diff --git a/.github/ct-install-config/ct-lint.yaml b/.github/ct-install-config/ct-lint.yaml index a6a2e88c..67c6b681 100644 --- a/.github/ct-install-config/ct-lint.yaml +++ b/.github/ct-install-config/ct-lint.yaml @@ -1,6 +1,6 @@ remote: origin target-branch: master -helm-extra-args: --debug +helm-extra-args: --debug --set crd.verify.enabled=false chart-yaml-schema: .github/ct-install-config/chart_schema.yaml chart-dirs: - library diff --git a/.github/workflows/common_library_tests.yaml b/.github/workflows/common_library_tests.yaml index 6462a747..c6becbb8 100644 --- a/.github/workflows/common_library_tests.yaml +++ b/.github/workflows/common_library_tests.yaml @@ -92,7 +92,7 @@ jobs: # Run tests cd library/common-test/ helm dependency update - helm unittest -f "tests/**/*.yaml" . + helm unittest -f "tests/**/*.yaml" . -v ./unit-values.yaml install: needs: diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index acd5543b..91b87d01 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~18.0.0 + version: ~18.1.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common-test/unit-values.yaml b/library/common-test/unit-values.yaml new file mode 100644 index 00000000..18e98875 --- /dev/null +++ b/library/common-test/unit-values.yaml @@ -0,0 +1,3 @@ +crd: + verify: + enabled: false diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 491a8103..160b0984 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,7 +15,7 @@ maintainers: name: common sources: null type: library -version: 18.0.4 +version: 18.1.0 annotations: artifacthub.io/category: "integration-delivery" artifacthub.io/license: "BUSL-1.1" diff --git a/library/common/templates/class/cert-manager/_certificate.tpl b/library/common/templates/class/cert-manager/_certificate.tpl index b07bda2b..b2dd323d 100644 --- a/library/common/templates/class/cert-manager/_certificate.tpl +++ b/library/common/templates/class/cert-manager/_certificate.tpl @@ -13,6 +13,9 @@ objectData: {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "certificates.cert-manager.io" "missing" "Cert-Manager") }} + --- apiVersion: cert-manager.io/v1 kind: Certificate diff --git a/library/common/templates/class/cnpg/_backup.tpl b/library/common/templates/class/cnpg/_backup.tpl index 37f4e9ec..2c1b8200 100644 --- a/library/common/templates/class/cnpg/_backup.tpl +++ b/library/common/templates/class/cnpg/_backup.tpl @@ -17,6 +17,9 @@ {{- $globalBackupAnnotations := $objectData.backups.annotations | default dict -}} {{- $backupAnnotations := $objectData.backupAnnotations | default dict -}} {{- $backupAnnotations = mustMerge $backupAnnotations $objAnnotations $globalBackupAnnotations }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "backups.postgresql.cnpg.io" "missing" "CloudNative-PG") }} + --- apiVersion: postgresql.cnpg.io/v1 kind: Backup diff --git a/library/common/templates/class/cnpg/_cluster.tpl b/library/common/templates/class/cnpg/_cluster.tpl index 568c9912..ac1bc214 100644 --- a/library/common/templates/class/cnpg/_cluster.tpl +++ b/library/common/templates/class/cnpg/_cluster.tpl @@ -122,6 +122,9 @@ {{- with $objectData.cluster.walStorage.size -}} {{- $walSize = . -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "clusters.postgresql.cnpg.io" "missing" "CloudNative-PG") }} + --- apiVersion: postgresql.cnpg.io/v1 kind: Cluster diff --git a/library/common/templates/class/cnpg/_pooler.tpl b/library/common/templates/class/cnpg/_pooler.tpl index c83eeef2..4291d1b6 100644 --- a/library/common/templates/class/cnpg/_pooler.tpl +++ b/library/common/templates/class/cnpg/_pooler.tpl @@ -21,6 +21,9 @@ {{- if or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}} {{- $instances = 0 -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "poolers.postgresql.cnpg.io" "missing" "CloudNative-PG") }} + --- apiVersion: postgresql.cnpg.io/v1 kind: Pooler diff --git a/library/common/templates/class/cnpg/_scheduledBackup.tpl b/library/common/templates/class/cnpg/_scheduledBackup.tpl index 23556610..af107439 100644 --- a/library/common/templates/class/cnpg/_scheduledBackup.tpl +++ b/library/common/templates/class/cnpg/_scheduledBackup.tpl @@ -30,6 +30,9 @@ {{- if (hasKey $objectData.schedData "immediate") -}} {{- $immediate = $objectData.schedData.immediate -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "scheduledbackups.postgresql.cnpg.io" "missing" "CloudNative-PG") }} + --- apiVersion: postgresql.cnpg.io/v1 kind: ScheduledBackup diff --git a/library/common/templates/class/_podMonitor.tpl b/library/common/templates/class/metrics/_podMonitor.tpl similarity index 92% rename from library/common/templates/class/_podMonitor.tpl rename to library/common/templates/class/metrics/_podMonitor.tpl index 907bb3b2..35b2c8ff 100644 --- a/library/common/templates/class/_podMonitor.tpl +++ b/library/common/templates/class/metrics/_podMonitor.tpl @@ -14,6 +14,9 @@ {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- $podmonitorName = printf "%v-%v" $podmonitorName $values.nameOverride -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "crd" "podmonitors.monitoring.coreos.com" "missing" "Grafana-Agent-Operator or Prometheus-Operator") }} + --- apiVersion: {{ include "tc.v1.common.capabilities.podmonitor.apiVersion" $ }} kind: PodMonitor diff --git a/library/common/templates/class/_prometheusRule.tpl b/library/common/templates/class/metrics/_prometheusRule.tpl similarity index 93% rename from library/common/templates/class/_prometheusRule.tpl rename to library/common/templates/class/metrics/_prometheusRule.tpl index 34b0b47a..96d0c7e6 100644 --- a/library/common/templates/class/_prometheusRule.tpl +++ b/library/common/templates/class/metrics/_prometheusRule.tpl @@ -14,6 +14,9 @@ {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- $prometheusruleName = printf "%v-%v" $prometheusruleName $values.nameOverride -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "crd" "prometheusrules.monitoring.coreos.com" "missing" "Grafana-Agent-Operator or Prometheus-Operator") }} + --- apiVersion: {{ include "tc.v1.common.capabilities.prometheusrule.apiVersion" $ }} kind: PrometheusRule diff --git a/library/common/templates/class/_serviceMonitor.tpl b/library/common/templates/class/metrics/_serviceMonitor.tpl similarity index 92% rename from library/common/templates/class/_serviceMonitor.tpl rename to library/common/templates/class/metrics/_serviceMonitor.tpl index 17c2020e..beff69c2 100644 --- a/library/common/templates/class/_serviceMonitor.tpl +++ b/library/common/templates/class/metrics/_serviceMonitor.tpl @@ -14,6 +14,9 @@ {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} {{- $servicemonitorName = printf "%v-%v" $servicemonitorName $values.nameOverride -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "crd" "servicemonitors.monitoring.coreos.com" "missing" "Grafana-Agent-Operator or Prometheus-Operator") }} + --- apiVersion: {{ include "tc.v1.common.capabilities.servicemonitor.apiVersion" $ }} kind: ServiceMonitor diff --git a/library/common/templates/class/velero/_backupStorageLocation.tpl b/library/common/templates/class/velero/_backupStorageLocation.tpl index bbc68d55..2841411b 100644 --- a/library/common/templates/class/velero/_backupStorageLocation.tpl +++ b/library/common/templates/class/velero/_backupStorageLocation.tpl @@ -14,6 +14,9 @@ objectData: {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "backupstoragelocations.velero.io" "missing" "Velero") }} + --- apiVersion: velero.io/v1 kind: BackupStorageLocation diff --git a/library/common/templates/class/velero/_schedule.tpl b/library/common/templates/class/velero/_schedule.tpl index 2080fa9a..f6cfac86 100644 --- a/library/common/templates/class/velero/_schedule.tpl +++ b/library/common/templates/class/velero/_schedule.tpl @@ -25,6 +25,9 @@ objectData: */}} {{- $namespace = ($lookupBSL.items | first).metadata.namespace -}} {{- end }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "schedules.velero.io" "missing" "Velero") }} + --- apiVersion: velero.io/v1 kind: Schedule diff --git a/library/common/templates/class/velero/_volumeSnapshotLocation.tpl b/library/common/templates/class/velero/_volumeSnapshotLocation.tpl index 037e9013..6b416f9a 100644 --- a/library/common/templates/class/velero/_volumeSnapshotLocation.tpl +++ b/library/common/templates/class/velero/_volumeSnapshotLocation.tpl @@ -14,6 +14,9 @@ objectData: {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData }} + + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "volumesnapshotlocations.velero.io" "missing" "Velero") }} + --- apiVersion: velero.io/v1 kind: VolumeSnapshotLocation diff --git a/library/common/templates/lib/ingress/integrations/_traefik.tpl b/library/common/templates/lib/ingress/integrations/_traefik.tpl index ffacfcba..27ca3d3a 100644 --- a/library/common/templates/lib/ingress/integrations/_traefik.tpl +++ b/library/common/templates/lib/ingress/integrations/_traefik.tpl @@ -54,6 +54,8 @@ {{- fail (printf "Ingress - Combined traefik entrypoints contain duplicates [%s]" (join ", " $entrypoints)) -}} {{- end -}} + {{- include "tc.v1.common.lib.util.verifycrd" (dict "rootCtx" $rootCtx "crd" "middlewares.traefik.io" "missing" "Traefik") -}} + {{- $lookupMiddlewares := list -}} {{- $parsedMiddlewares := list -}} {{- if $middlewares -}} diff --git a/library/common/templates/lib/util/_verify_crd.tpl b/library/common/templates/lib/util/_verify_crd.tpl new file mode 100644 index 00000000..bcf241d5 --- /dev/null +++ b/library/common/templates/lib/util/_verify_crd.tpl @@ -0,0 +1,14 @@ +{{- define "tc.v1.common.lib.util.verifycrd" -}} + {{- $crd := .crd -}} + {{- $missing := .missing | default (printf "Missing CRDs for %s" $crd) -}} + {{- $rootCtx := .rootCtx -}} + + {{- if $rootCtx.Values.crd.verify.enabled -}} + {{- $lookupMiddlewares := (lookup "apiextensions.k8s.io/v1" "CustomResourceDefinition" "" $crd) -}} + {{/* If there are items, re-assign the variable */}} + {{- if $lookupMiddlewares -}} + {{- else -}} + {{- fail (printf "%s has to be installed first" $missing) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/templates/lib/util/_verify_operator.tpl b/library/common/templates/lib/util/_verify_operator.tpl index 054a46ff..ca465896 100644 --- a/library/common/templates/lib/util/_verify_operator.tpl +++ b/library/common/templates/lib/util/_verify_operator.tpl @@ -3,26 +3,6 @@ {{/* Go over all operators that need to be verified */}} {{- $operatorList := .Values.operator.verify.additionalOperators -}} - {{- $cnpg := false -}} - {{- range $opName := $.Values.cnpg -}} - {{- if .enabled -}} - {{- $cnpg = true -}} - {{- end -}} - {{- end -}} - {{- if $cnpg -}} - {{- $operatorList = mustAppend $operatorList "cloudnative-pg" -}} - {{- end -}} - - {{- $ingress := false -}} - {{- range $opName := $.Values.ingress -}} - {{- if .enabled -}} - {{- $ingress = true -}} - {{- end -}} - {{- end -}} - {{- if $ingress -}} - {{- $operatorList = mustAppend $operatorList "traefik" -}} - {{- end -}} - {{- $clusterCertificate := false -}} {{- if $.Values.clusterCertificates -}} {{- range $opName := $.Values.clusterCertificates.certificates -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index 38027a52..48dbfadd 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -855,6 +855,10 @@ metrics: # # list to support adding rules via the SCALE GUI without overwrithing the rules # additionalrules: [] +crd: + verify: + enabled: true + # -- Contains specific settings for helm charts containing or using operators operator: # -- Adds a configmap to the operator to register this chart as an operator