From a01a89cb134d9dcb961a897fb6248f7c994a9287 Mon Sep 17 00:00:00 2001 From: Bernd Schorgers Date: Fri, 16 May 2025 08:40:39 +0200 Subject: [PATCH] feat(common): Release common 4.0.0 (#398) Co-authored-by: lab-assistant[bot] <180935599+lab-assistant[bot]@users.noreply.github.com> --- .ci/mkdocs/mkdocs.yml | 4 + .github/renovate/custom-managers.json5 | 1 - .github/workflows/chart-release-steps.yaml | 2 - .github/workflows/charts-release.yaml | 2 +- .github/workflows/charts-test.yaml | 2 + .taskfiles/charts.yaml | 1 + .taskfiles/docs.yaml | 17 + .taskfiles/precommit.yaml | 23 - Taskfile.yaml | 2 +- charts/library/common/Chart.yaml | 49 +- charts/library/common/README.md | 10 +- charts/library/common/schemas/configmap.json | 73 +-- .../library/common/schemas/controllers.json | 447 +++++++++--------- .../library/common/schemas/definitions.json | 25 + charts/library/common/schemas/ingress.json | 84 ++-- .../library/common/schemas/networkpolicy.json | 79 ++-- .../library/common/schemas/persistence.json | 96 ++-- charts/library/common/schemas/pod.json | 3 + .../library/common/schemas/rawResource.json | 58 +-- charts/library/common/schemas/rbac.json | 118 +++++ charts/library/common/schemas/route.json | 214 +++++---- charts/library/common/schemas/secret.json | 63 +-- charts/library/common/schemas/service.json | 177 +++---- .../common/schemas/serviceAccount.json | 59 +-- .../common/schemas/serviceMonitor.json | 103 ++-- .../common/templates/classes/_configmap.tpl | 4 +- .../common/templates/classes/_cronjob.tpl | 11 +- .../common/templates/classes/_daemonset.tpl | 8 +- .../common/templates/classes/_deployment.tpl | 8 +- .../common/templates/classes/_ingress.tpl | 6 +- .../library/common/templates/classes/_job.tpl | 6 +- .../templates/classes/_networkpolicy.tpl | 6 +- .../library/common/templates/classes/_pvc.tpl | 5 +- .../common/templates/classes/_rawResource.tpl | 4 +- .../common/templates/classes/_role.tpl | 17 +- .../common/templates/classes/_rolebinding.tpl | 14 +- .../common/templates/classes/_route.tpl | 67 ++- .../common/templates/classes/_secret.tpl | 4 +- .../common/templates/classes/_service.tpl | 6 +- .../templates/classes/_serviceAccount.tpl | 6 +- .../templates/classes/_serviceMonitor.tpl | 4 +- .../common/templates/classes/_statefulset.tpl | 8 +- .../_determineResourceNameFromValues.tpl | 38 ++ .../templates/lib/common/_valuesToObject.tpl | 19 +- .../lib/configMap/_enabled_configmaps.tpl | 23 + .../lib/configMap/_getByIdentifier.tpl | 7 +- .../templates/lib/configMap/_validate.tpl | 3 +- .../lib/container/fields/_volumeMounts.tpl | 14 +- .../lib/controller/_getByIdentifier.tpl | 15 +- .../lib/controller/_valuesToObject.tpl | 35 -- .../templates/lib/cronjob/_valuesToObject.tpl | 7 +- .../lib/ingress/_getByIdentifier.tpl | 30 ++ .../templates/lib/ingress/_validate.tpl | 18 +- .../templates/lib/ingress/_valuesToObject.tpl | 30 -- .../_enabled_networkpolicies.tpl | 2 +- .../lib/networkpolicy/_getByIdentifier.tpl | 13 + .../lib/networkpolicy/_valuesToObject.tpl | 30 -- .../common/templates/lib/pod/_getOption.tpl | 10 +- .../common/templates/lib/pod/_spec.tpl | 5 + .../lib/pod/fields/_serviceAccountName.tpl | 18 +- .../templates/lib/pod/fields/_volumes.tpl | 11 +- .../templates/lib/pod/metadata/_labels.tpl | 2 +- .../templates/lib/pvc/_enabled_pvcs.tpl | 23 + .../templates/lib/pvc/_enabled_roles.tpl | 23 + .../templates/lib/pvc/_getByIdentifier.tpl | 13 + .../common/templates/lib/pvc/_validate.tpl | 7 - .../templates/lib/pvc/_valuesToObject.tpl | 26 - .../lib/rawResource/_enabled_rawResources.tpl | 23 + .../lib/rawResource/_getByIdentifier.tpl | 13 + .../templates/lib/rawResource/_validate.tpl | 7 - .../templates/lib/role/_enabled_roles.tpl | 23 + .../templates/lib/role/_getByIdentifier.tpl | 7 +- .../common/templates/lib/role/_validate.tpl | 6 - .../lib/rolebinding/_enabled_roleBindings.tpl | 23 + .../lib/rolebinding/_getByIdentifier.tpl | 7 +- .../templates/lib/rolebinding/_validate.tpl | 32 -- .../templates/lib/routes/_getByIdentifier.tpl | 13 + .../templates/lib/routes/_valuesToObject.tpl | 30 -- .../templates/lib/secret/_enabled_secrets.tpl | 23 + .../templates/lib/secret/_getByIdentifier.tpl | 7 +- .../common/templates/lib/secret/_validate.tpl | 7 - .../lib/service/_enabled_services.tpl | 2 + .../lib/service/_getByIdentifier.tpl | 15 +- .../lib/service/_primaryForController.tpl | 22 +- .../templates/lib/service/_validate.tpl | 13 +- .../templates/lib/service/_valuesToObject.tpl | 30 -- .../_enabled_serviceaccounts.tpl | 23 + .../lib/serviceAccount/_getByIdentifier.tpl | 18 +- .../lib/serviceAccount/_valuesToObject.tpl | 25 - .../_enabled_servicemonitors.tpl | 8 +- .../lib/serviceMonitor/_getByIdentifier.tpl | 13 + .../lib/serviceMonitor/_valuesToObject.tpl | 30 -- .../lib/statefulset/_valuesToObject.tpl | 7 +- .../common/templates/loader/_generate.tpl | 30 +- .../common/templates/render/_configmaps.tpl | 58 ++- .../common/templates/render/_controllers.tpl | 61 ++- .../common/templates/render/_ingresses.tpl | 27 +- .../templates/render/_networkpolicies.tpl | 27 +- .../library/common/templates/render/_pvcs.tpl | 28 +- .../common/templates/render/_rawResources.tpl | 24 +- .../library/common/templates/render/_rbac.tpl | 54 +-- .../common/templates/render/_routes.tpl | 16 +- .../common/templates/render/_secrets.tpl | 23 +- .../templates/render/_serviceMonitors.tpl | 29 +- .../templates/render/_serviceaccount.tpl | 49 +- .../common/templates/render/_services.tpl | 16 +- charts/library/common/test-chart/Chart.yaml | 2 +- .../common/test-chart/ci/advanced-values.yaml | 8 +- .../common/test-chart/ci/basic-values.yaml | 6 +- .../common/test-chart/ci/cronjob-values.yaml | 2 +- .../common/test-chart/ci/no-service.yaml | 2 +- .../test-chart/ci/vaultwarden-example.yaml | 2 +- .../unittests/_values/rbac_values.yaml | 2 +- .../unittests/chart/validations_test.yaml | 2 +- .../configmap/metadata_annotations_test.yaml | 117 +++++ ...ta_test.yaml => metadata_labels_test.yaml} | 141 ++---- .../configmap/metadata_name_test.yaml | 183 +++++++ .../unittests/configmap/names_test.yaml | 196 -------- .../configmap/pod_metadata_test.yaml | 73 --- .../unittests/configmap/presence_test.yaml | 85 ++++ .../unittests/configmap/validation_test.yaml | 20 + .../unittests/container/field_args_test.yaml | 65 ++- .../container/field_command_test.yaml | 65 ++- .../unittests/container/field_env_test.yaml | 134 +++--- .../container/field_envfrom_test.yaml | 97 ++-- .../unittests/container/field_image_test.yaml | 47 +- ...test.yaml => field_nameOverride_test.yaml} | 29 +- ...{ports_test.yaml => field_ports_test.yaml} | 21 +- ...robes_test.yaml => field_probes_test.yaml} | 74 ++- .../container/field_resources_test.yaml | 59 +-- .../container/field_restartpolicy_test.yaml | 21 +- .../container/field_securityContext_test.yaml | 29 +- .../unittests/container/field_stdin_test.yaml | 20 +- .../unittests/container/field_tty_test.yaml | 20 +- ...test.yaml => field_volumemounts_test.yaml} | 140 +++--- ...r_test.yaml => field_workingdir_test.yaml} | 29 +- .../unittests/container/validations_test.yaml | 2 +- .../unittests/controller/cronjob_test.yaml | 95 ---- ...> field_defaultContainerOptions_test.yaml} | 59 +-- .../field_revisionhistorylimit_test.yaml | 130 ----- .../unittests/controller/job_test.yaml | 65 --- .../controller/metadata_cronjob_test.yaml | 123 ----- .../controller/metadata_daemonset_test.yaml | 92 ---- .../controller/metadata_deployment_test.yaml | 92 ---- .../controller/metadata_job_test.yaml | 120 ----- .../controller/metadata_statefulset_test.yaml | 92 ---- .../unittests/controller/presence_test.yaml | 47 ++ .../unittests/controller/type_test.yaml | 140 ++---- .../cronjob/field_concurrencyPolicy_test.yaml | 30 ++ .../cronjob/field_failedJobsHistory_test.yaml | 30 ++ .../cronjob/field_parallelism_test.yaml | 29 ++ .../cronjob/field_restartPolicy_test.yaml | 30 ++ .../field_successfulJobsHistory_test.yaml | 30 ++ .../unittests/cronjob/field_suspend_test.yaml | 30 ++ .../field_ttlSecondsAfterFinished_test.yaml | 29 ++ .../cronjob/metadata_annotations_test.yaml | 49 ++ ...metadata_jobTemplate_annotations_test.yaml | 25 + .../metadata_jobTemplate_labels_test.yaml | 28 ++ .../cronjob/metadata_labels_test.yaml | 65 +++ .../unittests/cronjob/metadata_name_test.yaml | 219 +++++++++ .../field_revisionhistorylimit_test.yaml | 42 ++ .../daemonset/metadata_annotations_test.yaml | 47 ++ .../daemonset/metadata_labels_test.yaml | 63 +++ .../daemonset/metadata_name_test.yaml | 206 ++++++++ .../field_revisionhistorylimit_test.yaml | 42 ++ .../deployment/metadata_annotations_test.yaml | 47 ++ .../deployment/metadata_labels_test.yaml | 63 +++ .../deployment/metadata_name_test.yaml | 199 ++++++++ .../ingress/field_hosts_host_test.yaml | 53 +++ .../ingress/field_hosts_paths_path_test.yaml | 52 ++ ...ml => field_hosts_paths_service_test.yaml} | 122 +++-- .../{tls_test.yaml => field_tls_test.yaml} | 51 +- .../ingress/fiield_defaultBackend_test.yaml | 31 ++ .../ingress/metadata_annotations_test.yaml | 61 +++ .../ingress/metadata_labels_test.yaml | 74 +++ .../unittests/ingress/metadata_name_test.yaml | 211 +++++++++ .../unittests/ingress/metadata_test.yaml | 115 ----- .../unittests/ingress/presence_test.yaml | 97 ++-- .../unittests/ingress/validations_test.yaml | 55 +++ .../unittests/ingress/values_test.yaml | 132 ------ .../job/field_backoffLimit_test.yaml | 29 ++ .../unittests/job/field_parallelism_test.yaml | 28 ++ .../job/field_restartPolicy_test.yaml | 29 ++ .../unittests/job/field_suspend_test.yaml | 29 ++ .../field_ttlSecondsAfterFinished_test.yaml | 28 ++ .../job/metadata_annotations_test.yaml | 47 ++ ...metadata_jobTemplate_annotations_test.yaml | 23 + .../job/metadata_jobTemplate_labels_test.yaml | 26 + .../unittests/job/metadata_labels_test.yaml | 63 +++ .../unittests/job/metadata_name_test.yaml | 206 ++++++++ .../unittests/misc/nameoverride_test.yaml | 26 +- .../networkpolicy/field_podselector_test.yaml | 46 ++ .../networkpolicy/field_rules_test.yaml | 33 ++ .../metadata_annotations_test.yaml | 51 ++ .../networkpolicy/metadata_labels_test.yaml | 64 +++ .../networkpolicy/metadata_name_test.yaml | 201 ++++++++ .../networkpolicy/metadata_test.yaml | 94 ---- .../unittests/networkpolicy/names_test.yaml | 85 ---- .../networkpolicy/presence_test.yaml | 57 +++ .../networkpolicy/validations_test.yaml | 14 +- .../unittests/networkpolicy/values_test.yaml | 103 ---- .../unittests/persistence/secret_test.yaml | 77 --- .../persistence/validations_test.yaml | 27 ++ .../unittests/pod/field_affinity_test.yaml | 22 +- ...ml => field_containers_multiple_test.yaml} | 58 +-- ....yaml => field_containers_order_test.yaml} | 41 +- .../unittests/pod/field_dnsConfig_test.yaml | 29 +- .../unittests/pod/field_dnsPolicy_test.yaml | 29 +- .../pod/field_enableServiceLinks_test.yaml | 29 +- .../unittests/pod/field_hostAliases_test.yaml | 29 +- .../unittests/pod/field_hostIPC_test.yaml | 26 +- .../unittests/pod/field_hostNetwork_test.yaml | 26 +- .../unittests/pod/field_hostPID_test.yaml | 29 +- .../unittests/pod/field_hostUsers_test.yaml | 22 +- .../pod/field_imagePullSecrets_test.yaml | 29 +- ...st.yaml => field_initcontainers_test.yaml} | 63 +-- .../pod/field_nodeSelector_test.yaml | 26 +- .../unittests/pod/field_replicas_test.yaml | 23 +- .../unittests/pod/field_resources_test.yaml | 110 +++++ .../pod/field_securityContext_test.yaml | 29 +- .../pod/field_serviceAccount_test.yaml | 176 ++----- .../pod/field_shareProcessNamespace_test.yaml | 14 +- .../unittests/pod/field_tolerations_test.yaml | 29 +- .../field_topologySpreadConstraints_test.yaml | 26 +- .../field_volumes_configmap_test.yaml} | 61 +-- .../field_volumes_custom_test.yaml} | 11 +- .../field_volumes_emptydir_test.yaml} | 42 +- .../field_volumes_hostpath_test.yaml} | 42 +- .../field_volumes_nfs_test.yaml} | 12 +- .../field_volumes_pvc_test.yaml} | 47 +- .../pod/field_volumes_secret_test.yaml | 63 +++ .../field_volumes_test.yaml} | 37 +- .../pod/metadata_annotations_test.yaml | 130 ++++- .../unittests/pod/metadata_labels_test.yaml | 42 +- .../unittests/pvc/datasource_test.yaml | 112 ----- .../pvc/field_datasourceRef_test.yaml | 60 +++ .../unittests/pvc/field_datasource_test.yaml | 60 +++ ...lass_test.yaml => field_storageclass.yaml} | 29 +- .../pvc/metadata_annotations_test.yaml | 50 ++ .../unittests/pvc/metadata_labels_test.yaml | 63 +++ .../unittests/pvc/metadata_name_test.yaml | 189 ++++++++ .../unittests/pvc/metadata_test.yaml | 110 ----- .../test-chart/unittests/pvc/names_test.yaml | 67 --- .../unittests/pvc/presence_test.yaml | 52 ++ .../test-chart/unittests/pvc/values_test.yaml | 56 --- .../metadata_annotations_test.yaml | 51 ++ ...ta_test.yaml => metadata_labels_test.yaml} | 54 +-- .../rawResource/metadata_name_test.yaml | 195 ++++++++ .../{values_test.yaml => presence_test.yaml} | 40 +- .../rbac/metadata_annotations_test.yaml | 44 ++ .../unittests/rbac/metadata_labels_test.yaml | 57 +++ .../unittests/rbac/metadata_test.yaml | 60 --- .../test-chart/unittests/rbac/names_test.yaml | 58 --- .../unittests/rbac/presence_test.yaml | 72 +++ .../unittests/rbac/validations_test.yaml | 32 +- .../unittests/rbac/values_test.yaml | 52 -- ..._test.yaml => field_backendRefs_test.yaml} | 82 ++-- .../unittests/route/field_hostnames_test.yaml | 68 +++ .../route/field_parentRefs_test.yaml | 67 +++ .../route/field_rules_filters_test.yaml | 134 ++++++ .../route/field_rules_matches_test.yaml | 120 +++++ .../field_rules_sessionpersistence_test.yaml | 118 +++++ .../route/field_rules_timeouts_test.yaml | 49 ++ .../route/metadata_annotations_test.yaml | 48 ++ .../unittests/route/metadata_labels_test.yaml | 61 +++ .../unittests/route/metadata_name_test.yaml | 189 ++++++++ .../unittests/route/metadata_test.yaml | 94 ---- .../unittests/route/names_test.yaml | 74 --- .../unittests/route/presence_test.yaml | 38 +- .../unittests/route/validations_test.yaml | 43 ++ .../unittests/route/values_test.yaml | 348 -------------- .../secret/metadata_annotations_test.yaml | 49 ++ .../secret/metadata_labels_test.yaml | 62 +++ .../unittests/secret/metadata_name_test.yaml | 183 +++++++ .../unittests/secret/metadata_test.yaml | 118 ----- .../unittests/secret/names_test.yaml | 93 ---- .../unittests/secret/pod_metadata_test.yaml | 35 -- .../unittests/secret/presence_test.yaml | 64 +++ ...ld_allocateLoadBalancerNodePorts_test.yaml | 36 ++ .../service/field_externalName_test.yaml | 22 + .../field_externalTrafficPolicy_test.yaml | 36 ++ .../field_internalTrafficPolicy_test.yaml | 21 + .../service/field_ports_appProtocol_test.yaml | 19 + ...st.yaml => field_ports_protocol_test.yaml} | 60 +-- .../service/field_ports_targetPort_test.yaml | 23 + ...{ports_test.yaml => field_ports_test.yaml} | 49 +- .../service/metadata_annotations_test.yaml | 45 ++ .../service/metadata_labels_test.yaml | 61 +++ .../unittests/service/metadata_name_test.yaml | 195 ++++++++ .../unittests/service/metadata_test.yaml | 84 ---- .../unittests/service/names_test.yaml | 64 --- .../unittests/service/presence_test.yaml | 64 +++ .../unittests/service/validations_test.yaml | 43 +- .../unittests/service/values_test.yaml | 122 ----- .../serviceAccount/field_secrets_test.yaml | 56 +++ .../metadata_annotations_test.yaml | 47 ++ .../serviceAccount/metadata_labels_test.yaml | 60 +++ .../serviceAccount/metadata_name_test.yaml | 171 +++++++ .../serviceAccount/presence_test.yaml | 65 +++ .../serviceAccount/serviceaccount_test.yaml | 256 ---------- .../serviceMonitor/field_endpoints_test.yaml | 96 ++++ .../serviceMonitor/field_selector_test.yaml | 31 ++ .../field_serviceName_test.yaml | 29 ++ .../field_targetLabels_test.yaml | 31 ++ .../metadata_annotations_test.yaml | 54 +++ .../serviceMonitor/metadata_labels_test.yaml | 67 +++ .../serviceMonitor/metadata_name_test.yaml | 213 +++++++++ .../serviceMonitor/presence_test.yaml | 30 ++ .../serviceMonitor/servicemonitor_test.yaml | 218 --------- .../field_revisionhistorylimit_test.yaml | 42 ++ .../field_volumeclaimtemplates_test.yaml} | 47 +- .../metadata_annotations_test.yaml | 47 ++ .../statefulset/metadata_labels_test.yaml | 63 +++ .../statefulset/metadata_name_test.yaml | 206 ++++++++ charts/library/common/values.schema.json | 71 ++- charts/library/common/values.yaml | 41 +- charts/other/app-template/Chart.yaml | 18 +- charts/other/app-template/README.md | 17 +- charts/other/app-template/README.md.gotmpl | 9 + .../schemas/helmrelease-helm-v2.schema.json | 2 +- .../helmrelease-helm-v2beta2.schema.json | 2 +- charts/other/app-template/values.schema.json | 2 +- docs/app-template/index.md | 337 +------------ docs/app-template/upgrade-instructions.md | 375 +++++++++++++++ .../howto/default-pod-options.md | 84 ++++ docs/common-library/resources/names.md | 42 ++ docs/common-library/storage/globalOptions.md | 8 + 327 files changed, 11181 insertions(+), 7330 deletions(-) create mode 100644 .taskfiles/docs.yaml delete mode 100644 .taskfiles/precommit.yaml create mode 100644 charts/library/common/schemas/rbac.json create mode 100644 charts/library/common/templates/lib/common/_determineResourceNameFromValues.tpl create mode 100644 charts/library/common/templates/lib/configMap/_enabled_configmaps.tpl delete mode 100644 charts/library/common/templates/lib/controller/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/ingress/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/ingress/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/networkpolicy/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/pvc/_enabled_pvcs.tpl create mode 100644 charts/library/common/templates/lib/pvc/_enabled_roles.tpl create mode 100644 charts/library/common/templates/lib/pvc/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/pvc/_validate.tpl delete mode 100644 charts/library/common/templates/lib/pvc/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/rawResource/_enabled_rawResources.tpl create mode 100644 charts/library/common/templates/lib/rawResource/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/rawResource/_validate.tpl create mode 100644 charts/library/common/templates/lib/role/_enabled_roles.tpl create mode 100644 charts/library/common/templates/lib/rolebinding/_enabled_roleBindings.tpl delete mode 100644 charts/library/common/templates/lib/rolebinding/_validate.tpl create mode 100644 charts/library/common/templates/lib/routes/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/routes/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/secret/_enabled_secrets.tpl delete mode 100644 charts/library/common/templates/lib/secret/_validate.tpl delete mode 100644 charts/library/common/templates/lib/service/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/serviceAccount/_enabled_serviceaccounts.tpl delete mode 100644 charts/library/common/templates/lib/serviceAccount/_valuesToObject.tpl create mode 100644 charts/library/common/templates/lib/serviceMonitor/_getByIdentifier.tpl delete mode 100644 charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl create mode 100644 charts/library/common/test-chart/unittests/configmap/metadata_annotations_test.yaml rename charts/library/common/test-chart/unittests/configmap/{metadata_test.yaml => metadata_labels_test.yaml} (54%) create mode 100644 charts/library/common/test-chart/unittests/configmap/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/configmap/names_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/configmap/pod_metadata_test.yaml create mode 100644 charts/library/common/test-chart/unittests/configmap/presence_test.yaml create mode 100644 charts/library/common/test-chart/unittests/configmap/validation_test.yaml rename charts/library/common/test-chart/unittests/container/{name_test.yaml => field_nameOverride_test.yaml} (74%) rename charts/library/common/test-chart/unittests/container/{ports_test.yaml => field_ports_test.yaml} (72%) rename charts/library/common/test-chart/unittests/container/{probes_test.yaml => field_probes_test.yaml} (87%) rename charts/library/common/test-chart/unittests/container/{volumemounts_test.yaml => field_volumemounts_test.yaml} (74%) rename charts/library/common/test-chart/unittests/container/{workingdir_test.yaml => field_workingdir_test.yaml} (64%) delete mode 100644 charts/library/common/test-chart/unittests/controller/cronjob_test.yaml rename charts/library/common/test-chart/unittests/controller/{default_container_options_test.yaml => field_defaultContainerOptions_test.yaml} (79%) delete mode 100644 charts/library/common/test-chart/unittests/controller/field_revisionhistorylimit_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/job_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/metadata_cronjob_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/metadata_daemonset_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/metadata_deployment_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/metadata_job_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/controller/metadata_statefulset_test.yaml create mode 100644 charts/library/common/test-chart/unittests/controller/presence_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_concurrencyPolicy_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_failedJobsHistory_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_parallelism_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_restartPolicy_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_successfulJobsHistory_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_suspend_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/field_ttlSecondsAfterFinished_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/cronjob/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/daemonset/field_revisionhistorylimit_test.yaml create mode 100644 charts/library/common/test-chart/unittests/daemonset/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/daemonset/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/daemonset/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/deployment/field_revisionhistorylimit_test.yaml create mode 100644 charts/library/common/test-chart/unittests/deployment/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/deployment/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/deployment/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/field_hosts_host_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/field_hosts_paths_path_test.yaml rename charts/library/common/test-chart/unittests/ingress/{service_reference_test.yaml => field_hosts_paths_service_test.yaml} (55%) rename charts/library/common/test-chart/unittests/ingress/{tls_test.yaml => field_tls_test.yaml} (63%) create mode 100644 charts/library/common/test-chart/unittests/ingress/fiield_defaultBackend_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/ingress/metadata_test.yaml create mode 100644 charts/library/common/test-chart/unittests/ingress/validations_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/ingress/values_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/field_backoffLimit_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/field_parallelism_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/field_restartPolicy_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/field_suspend_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/field_ttlSecondsAfterFinished_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/metadata_jobTemplate_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/metadata_jobTemplate_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/job/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/field_podselector_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/field_rules_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/networkpolicy/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/networkpolicy/names_test.yaml create mode 100644 charts/library/common/test-chart/unittests/networkpolicy/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/networkpolicy/values_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/persistence/secret_test.yaml create mode 100644 charts/library/common/test-chart/unittests/persistence/validations_test.yaml rename charts/library/common/test-chart/unittests/pod/{additional_containers_test.yaml => field_containers_multiple_test.yaml} (69%) rename charts/library/common/test-chart/unittests/pod/{container_order_test.yaml => field_containers_order_test.yaml} (69%) rename charts/library/common/test-chart/unittests/pod/{initcontainers_test.yaml => field_initcontainers_test.yaml} (67%) create mode 100644 charts/library/common/test-chart/unittests/pod/field_resources_test.yaml rename charts/library/common/test-chart/unittests/{persistence/configmap_test.yaml => pod/field_volumes_configmap_test.yaml} (53%) rename charts/library/common/test-chart/unittests/{persistence/custom.yaml => pod/field_volumes_custom_test.yaml} (83%) rename charts/library/common/test-chart/unittests/{persistence/emptydir_test.yaml => pod/field_volumes_emptydir_test.yaml} (64%) rename charts/library/common/test-chart/unittests/{persistence/hostpath_test.yaml => pod/field_volumes_hostpath_test.yaml} (50%) rename charts/library/common/test-chart/unittests/{persistence/nfs_test.yaml => pod/field_volumes_nfs_test.yaml} (78%) rename charts/library/common/test-chart/unittests/{persistence/claimnames_test.yaml => pod/field_volumes_pvc_test.yaml} (67%) create mode 100644 charts/library/common/test-chart/unittests/pod/field_volumes_secret_test.yaml rename charts/library/common/test-chart/unittests/{persistence/volumes_test.yaml => pod/field_volumes_test.yaml} (80%) delete mode 100644 charts/library/common/test-chart/unittests/pvc/datasource_test.yaml create mode 100644 charts/library/common/test-chart/unittests/pvc/field_datasourceRef_test.yaml create mode 100644 charts/library/common/test-chart/unittests/pvc/field_datasource_test.yaml rename charts/library/common/test-chart/unittests/pvc/{storageclass_test.yaml => field_storageclass.yaml} (55%) create mode 100644 charts/library/common/test-chart/unittests/pvc/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/pvc/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/pvc/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/pvc/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/pvc/names_test.yaml create mode 100644 charts/library/common/test-chart/unittests/pvc/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/pvc/values_test.yaml create mode 100644 charts/library/common/test-chart/unittests/rawResource/metadata_annotations_test.yaml rename charts/library/common/test-chart/unittests/rawResource/{metadata_test.yaml => metadata_labels_test.yaml} (56%) create mode 100644 charts/library/common/test-chart/unittests/rawResource/metadata_name_test.yaml rename charts/library/common/test-chart/unittests/rawResource/{values_test.yaml => presence_test.yaml} (62%) create mode 100644 charts/library/common/test-chart/unittests/rbac/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/rbac/metadata_labels_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/rbac/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/rbac/names_test.yaml create mode 100644 charts/library/common/test-chart/unittests/rbac/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/rbac/values_test.yaml rename charts/library/common/test-chart/unittests/route/{service_reference_test.yaml => field_backendRefs_test.yaml} (67%) create mode 100644 charts/library/common/test-chart/unittests/route/field_hostnames_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/field_parentRefs_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/field_rules_filters_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/field_rules_matches_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/field_rules_sessionpersistence_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/field_rules_timeouts_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/route/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/route/names_test.yaml create mode 100644 charts/library/common/test-chart/unittests/route/validations_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/route/values_test.yaml create mode 100644 charts/library/common/test-chart/unittests/secret/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/secret/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/secret/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/secret/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/secret/names_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/secret/pod_metadata_test.yaml create mode 100644 charts/library/common/test-chart/unittests/secret/presence_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/field_allocateLoadBalancerNodePorts_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/field_externalName_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/field_externalTrafficPolicy_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/field_internalTrafficPolicy_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/field_ports_appProtocol_test.yaml rename charts/library/common/test-chart/unittests/service/{port_protocols_test.yaml => field_ports_protocol_test.yaml} (56%) create mode 100644 charts/library/common/test-chart/unittests/service/field_ports_targetPort_test.yaml rename charts/library/common/test-chart/unittests/service/{ports_test.yaml => field_ports_test.yaml} (59%) create mode 100644 charts/library/common/test-chart/unittests/service/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/metadata_name_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/service/metadata_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/service/names_test.yaml create mode 100644 charts/library/common/test-chart/unittests/service/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/service/values_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceAccount/field_secrets_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceAccount/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceAccount/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceAccount/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceAccount/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/serviceAccount/serviceaccount_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/field_endpoints_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/field_selector_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/field_serviceName_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/field_targetLabels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/metadata_name_test.yaml create mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/presence_test.yaml delete mode 100644 charts/library/common/test-chart/unittests/serviceMonitor/servicemonitor_test.yaml create mode 100644 charts/library/common/test-chart/unittests/statefulset/field_revisionhistorylimit_test.yaml rename charts/library/common/test-chart/unittests/{persistence/volumeclaimtemplates_test.yaml => statefulset/field_volumeclaimtemplates_test.yaml} (72%) create mode 100644 charts/library/common/test-chart/unittests/statefulset/metadata_annotations_test.yaml create mode 100644 charts/library/common/test-chart/unittests/statefulset/metadata_labels_test.yaml create mode 100644 charts/library/common/test-chart/unittests/statefulset/metadata_name_test.yaml create mode 100644 docs/app-template/upgrade-instructions.md create mode 100644 docs/common-library/howto/default-pod-options.md create mode 100644 docs/common-library/resources/names.md diff --git a/.ci/mkdocs/mkdocs.yml b/.ci/mkdocs/mkdocs.yml index 952b11f9..e4f299d3 100644 --- a/.ci/mkdocs/mkdocs.yml +++ b/.ci/mkdocs/mkdocs.yml @@ -64,6 +64,8 @@ nav: - index.md - Common Library: - common-library/index.md + - Generated Resources: + - common-library/resources/names.md - Storage: - Permissions: common-library/storage/permissions.md - Global options: common-library/storage/globalOptions.md @@ -78,8 +80,10 @@ nav: - How To...: - common-library/howto/index.md - Default container options: common-library/howto/default-container-options.md + - Default Pod options: common-library/howto/default-pod-options.md - App Template: - app-template/index.md + - Upgrade instructions: app-template/upgrade-instructions.md - How To...: - app-template/howto/index.md - Helm templates: app-template/howto/helm-templates.md diff --git a/.github/renovate/custom-managers.json5 b/.github/renovate/custom-managers.json5 index e1e64486..d57295a8 100644 --- a/.github/renovate/custom-managers.json5 +++ b/.github/renovate/custom-managers.json5 @@ -6,7 +6,6 @@ description: "Process common lib json schema references", fileMatch: ["\\.json$"], matchStrings: [ - // https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.0.3/charts/library/common/values.schema.json "https:\\/\\/raw.githubusercontent.com\\/bjw-s-labs\\/helm-charts\\/(?\\S+?)-(?[\\d\\.]+?)\\/\\S+", ], datasourceTemplate: "helm", diff --git a/.github/workflows/chart-release-steps.yaml b/.github/workflows/chart-release-steps.yaml index 4d7be56a..c1f03908 100644 --- a/.github/workflows/chart-release-steps.yaml +++ b/.github/workflows/chart-release-steps.yaml @@ -63,7 +63,6 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: path: src - persist-credentials: false - name: Install Helm uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 @@ -160,7 +159,6 @@ jobs: with: path: gh-pages ref: gh-pages - persist-credentials: false - name: Copy package to gh-pages structure id: copy-package diff --git a/.github/workflows/charts-release.yaml b/.github/workflows/charts-release.yaml index 94a9f595..7208588c 100644 --- a/.github/workflows/charts-release.yaml +++ b/.github/workflows/charts-release.yaml @@ -53,7 +53,7 @@ jobs: patterns: | library/** - - name: Get changed library charts + - name: Get changed charts id: changed-charts if: ${{ github.event_name != 'workflow_dispatch' }} uses: bjw-s-labs/action-changed-files@930cef8463348e168cab7235c47fe95a7a235f65 # v0.3.3 diff --git a/.github/workflows/charts-test.yaml b/.github/workflows/charts-test.yaml index 83ee84c7..273dc506 100644 --- a/.github/workflows/charts-test.yaml +++ b/.github/workflows/charts-test.yaml @@ -30,10 +30,12 @@ jobs: chart: ${{ fromJSON(inputs.charts) }} k8s_version: [ + "v1.28.15", "v1.29.13", "v1.30.11", "v1.31.7", "v1.32.3", + "v1.33.0", ] fail-fast: false steps: diff --git a/.taskfiles/charts.yaml b/.taskfiles/charts.yaml index e4ffac23..720ca4fe 100644 --- a/.taskfiles/charts.yaml +++ b/.taskfiles/charts.yaml @@ -1,4 +1,5 @@ --- +# yaml-language-server: $schema=https://taskfile.dev/schema.json version: "3" vars: diff --git a/.taskfiles/docs.yaml b/.taskfiles/docs.yaml new file mode 100644 index 00000000..504fd34e --- /dev/null +++ b/.taskfiles/docs.yaml @@ -0,0 +1,17 @@ +--- +# yaml-language-server: $schema=https://taskfile.dev/schema.json +version: "3" + +tasks: + serve: + desc: Serve documentation locally + deps: + - install_prerequisies + cmds: + - mkdocs serve -c -f .ci/mkdocs/mkdocs.yml + + install_prerequisies: + desc: Install prerequisites + internal: true + cmds: + - pip install -r docs/requirements.txt diff --git a/.taskfiles/precommit.yaml b/.taskfiles/precommit.yaml deleted file mode 100644 index b591861f..00000000 --- a/.taskfiles/precommit.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -version: "3" - -tasks: - init: - desc: Install pre-commit hooks - cmds: - - pre-commit install --install-hooks --config .ci/pre-commit/config.yaml - - update: - desc: Update pre-commit hooks - cmds: - - pre-commit autoupdate --config .ci/pre-commit/config.yaml - - run: - desc: Run pre-commit - cmds: - - pre-commit run --config .ci/pre-commit/config.yaml - - run-all: - desc: Run pre-commit on all files - cmds: - - pre-commit run --all-files --config .ci/pre-commit/config.yaml diff --git a/Taskfile.yaml b/Taskfile.yaml index fb79f7a5..0c0b4887 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -7,7 +7,7 @@ vars: includes: charts: .taskfiles/charts.yaml - precommit: .taskfiles/precommit.yaml + docs: .taskfiles/docs.yaml tasks: default: diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index b627f89c..3c575cb9 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -3,8 +3,8 @@ apiVersion: v2 name: common description: Function library for Helm charts type: library -version: 3.7.3 -kubeVersion: ">=1.22.0-0" +version: 4.0.0 +kubeVersion: ">=1.28.0-0" keywords: - common - library @@ -16,9 +16,48 @@ sources: - https://github.com/bjw-s-labs/helm-charts annotations: artifacthub.io/changes: |- + - kind: removed + description: |- + Individual `valuesToObject` functions have been removed in favor of a centralized `bjw-s.common.lib.valuesToObject` function. - kind: fixed description: |- - Fixed name suffix for HTTPRoute - - kind: fixed + Fixed empty backendRefs in HTTPRoute leading to invalid spec + - kind: added description: |- - Fixed incorrect default backendRefs values in HTTPRoute + Added support for setting `parentRefs[].port` in HTTPRoute + - kind: added + description: |- + Added support for setting `sessionPersistence` in HTTPRoute + - kind: added + description: |- + Added support for setting `resources` on the Pod Level in Kubernetes >= 1.32 + - kind: added + description: |- + Added explicit JSON schema for `rbac` root key + - kind: added + description: |- + Allow configuring the merge strategy for `defaultPodOptions` + - kind: added + description: |- + Added support for setting `subPathExpr` on globalMounts and advancedMounts persistence items + - kind: added + description: |- + Added support for automatically determining the target controller for Services if there is only one enabled controller + - kind: added + description: |- + Added support for automatically determining the target service for Ingress paths if there is only one enabled Service + - kind: changed + description: |- + **Breaking**: Standardized resource name logic for all resources. This may cause changes in the generated resource names. + links: + - name: Documentation + url: https://bjw-s-labs.github.io/helm-charts/docs/common-library/resources/names/ + - kind: changed + description: |- + **Breaking**: Increased the minimum supported Kubernetes version to 1.28.0 + - kind: changed + description: |- + **Breaking**: ServiceAccounts no longer create a static token by default. This is now controlled by the `staticToken` field in the `serviceAccount` object. + - kind: changed + description: |- + **Breaking**: Renamed the hardcoded app.kubernetes.io/component label to app.kubernetes.io/controller diff --git a/charts/library/common/README.md b/charts/library/common/README.md index 681efa26..ec2b539b 100644 --- a/charts/library/common/README.md +++ b/charts/library/common/README.md @@ -1,12 +1,16 @@ # common -![Version: 3.7.3](https://img.shields.io/badge/Version-3.7.3-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 4.0.0](https://img.shields.io/badge/Version-4.0.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) Function library for Helm charts +## Source Code + +* + ## Requirements -Kubernetes: `>=1.22.0-0` +Kubernetes: `>=1.28.0-0` ## Dependencies @@ -27,7 +31,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g. # Chart.yaml dependencies: - name: common - version: 3.7.3 + version: 4.0.0 repository: https://bjw-s-labs.github.io/helm-charts/ ``` diff --git a/charts/library/common/schemas/configmap.json b/charts/library/common/schemas/configmap.json index bf6387e2..3ef44a3f 100644 --- a/charts/library/common/schemas/configmap.json +++ b/charts/library/common/schemas/configmap.json @@ -1,41 +1,46 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "includeInChecksum": { - "type": "boolean", - "default": true - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "data": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "binaryData": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "includeInChecksum": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "data": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "binaryData": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "oneOf": [ + {"required": ["data"]}, + {"required": ["binaryData"]} + ] } - }, - "oneOf": [ - {"required": ["data"]}, - {"required": ["binaryData"]} ] } } diff --git a/charts/library/common/schemas/controllers.json b/charts/library/common/schemas/controllers.json index 6ca1fbd3..21f60f45 100644 --- a/charts/library/common/schemas/controllers.json +++ b/charts/library/common/schemas/controllers.json @@ -1,206 +1,136 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "type": { - "type": "string", - "enum": [ - "deployment", - "statefulset", - "daemonset", - "cronjob", - "job" - ], - "default": "deployment" - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "pod": { - "$ref": "pod.json#/options" - }, - "replicas": { - "type": [ - "integer", - "null" - ], - "default": 1 - }, - "revisionHistoryLimit": { - "type": "integer" - }, - "rollingUpdate": { - "type": "object" - }, - "strategy": { - "type": "string" - }, - "cronjob": { - "$ref": "#/cronjob" - }, - "job": { - "$ref": "#/job" - }, - "statefulset": { - "$ref": "#/statefulset" - }, - "applyDefaultContainerOptionsToInitContainers": { - "type": "boolean", - "default": true - }, - "defaultContainerOptionsStrategy": { - "type": "string", - "default": "overwrite", - "enum": [ - "overwrite", - "merge" - ] - }, - "defaultContainerOptions": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", "additionalProperties": false, "properties": { - "args": { - "$ref": "containers.json#/args" + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true }, - "command": { - "$ref": "containers.json#/command" + "type": { + "type": "string", + "enum": [ + "deployment", + "statefulset", + "daemonset", + "cronjob", + "job" + ], + "default": "deployment" }, - "env": { - "$ref": "containers.json#/env" + "annotations": { + "$ref": "definitions.json#/annotations" }, - "envFrom": { - "$ref": "containers.json#/envFrom" + "labels": { + "$ref": "definitions.json#/labels" }, - "image": { - "$ref": "containers.json#/image" + "pod": { + "$ref": "pod.json#/options" }, - "resources": { - "$ref": "k8s-api.json#/core.v1.ResourceRequirements" + "replicas": { + "type": [ + "integer", + "null" + ], + "default": 1 }, - "securityContext": { - "$ref": "k8s-api.json#/core.v1.ContainerSecurityContext" - } - } - }, - "initContainers": { - "type": "object", - "additionalProperties": { - "$ref": "containers.json#/container" - } - }, - "containers": { - "type": "object", - "additionalProperties": { - "$ref": "containers.json#/container" - } - }, - "serviceAccount": { - "type": "object", - "properties": { - "name": { + "revisionHistoryLimit": { + "type": "integer" + }, + "rollingUpdate": { + "type": "object" + }, + "strategy": { "type": "string" }, - "identifier": { - "type": "string" - } - } - } - }, - "allOf": [ - { - "if": { - "properties": { - "type": { - "const": "deployment" - } - } - }, - "then": { - "not": { - "anyOf": [ - { - "required": [ - "statefulset" - ] - }, - { - "required": [ - "cronjob" - ] - }, - { - "required": [ - "job" - ] - }, - { - "required": [ - "daemonset" - ] - } + "cronjob": { + "$ref": "#/cronjob" + }, + "job": { + "$ref": "#/job" + }, + "statefulset": { + "$ref": "#/statefulset" + }, + "applyDefaultContainerOptionsToInitContainers": { + "type": "boolean", + "default": true + }, + "defaultContainerOptionsStrategy": { + "type": "string", + "default": "overwrite", + "enum": [ + "overwrite", + "merge" ] - } - } - }, - { - "if": { - "properties": { - "type": { - "const": "statefulset" + }, + "defaultContainerOptions": { + "type": "object", + "additionalProperties": false, + "properties": { + "args": { + "$ref": "containers.json#/args" + }, + "command": { + "$ref": "containers.json#/command" + }, + "env": { + "$ref": "containers.json#/env" + }, + "envFrom": { + "$ref": "containers.json#/envFrom" + }, + "image": { + "$ref": "containers.json#/image" + }, + "resources": { + "$ref": "k8s-api.json#/core.v1.ResourceRequirements" + }, + "securityContext": { + "$ref": "k8s-api.json#/core.v1.ContainerSecurityContext" + } } }, - "required": [ - "type" - ] - }, - "then": { - "not": { - "anyOf": [ - { - "required": [ - "cronjob" - ] - }, - { - "required": [ - "job" - ] - }, - { - "required": [ - "daemonset" - ] - } - ] - } - } - }, - { - "if": { - "properties": { - "type": { - "const": "cronjob" + "initContainers": { + "type": "object", + "additionalProperties": { + "$ref": "containers.json#/container" } }, - "required": [ - "type" - ] + "containers": { + "type": "object", + "additionalProperties": { + "$ref": "containers.json#/container" + } + }, + "serviceAccount": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "identifier": { + "type": "string" + } + } + } }, - "then": { - "allOf": [ - { + "allOf": [ + { + "if": { + "properties": { + "type": { + "const": "deployment" + } + } + }, + "then": { "not": { "anyOf": [ { @@ -208,6 +138,11 @@ "statefulset" ] }, + { + "required": [ + "cronjob" + ] + }, { "required": [ "job" @@ -220,50 +155,121 @@ } ] } - }, - { - "required": [ - "cronjob" - ] - } - ] - } - }, - { - "if": { - "properties": { - "type": { - "const": "job" } }, - "required": [ - "type" - ] - }, - "then": { - "not": { - "anyOf": [ - { - "required": [ - "statefulset" - ] + { + "if": { + "properties": { + "type": { + "const": "statefulset" + } }, - { - "required": [ - "cronjob" - ] - }, - { - "required": [ - "daemonset" + "required": [ + "type" + ] + }, + "then": { + "not": { + "anyOf": [ + { + "required": [ + "cronjob" + ] + }, + { + "required": [ + "job" + ] + }, + { + "required": [ + "daemonset" + ] + } ] } - ] + } + }, + { + "if": { + "properties": { + "type": { + "const": "cronjob" + } + }, + "required": [ + "type" + ] + }, + "then": { + "allOf": [ + { + "not": { + "anyOf": [ + { + "required": [ + "statefulset" + ] + }, + { + "required": [ + "job" + ] + }, + { + "required": [ + "daemonset" + ] + } + ] + } + }, + { + "required": [ + "cronjob" + ] + } + ] + } + }, + { + "if": { + "properties": { + "type": { + "const": "job" + } + }, + "required": [ + "type" + ] + }, + "then": { + "not": { + "anyOf": [ + { + "required": [ + "statefulset" + ] + }, + { + "required": [ + "cronjob" + ] + }, + { + "required": [ + "daemonset" + ] + } + ] + } + } } - } + ] } ] }, + "statefulset": { "type": "object", "additionalProperties": false, @@ -301,6 +307,7 @@ } } }, + "statefulset.volumeClaimTemplate": { "type": "object", "additionalProperties": false, @@ -348,6 +355,7 @@ "size" ] }, + "cronjob": { "type": "object", "additionalProperties": false, @@ -396,6 +404,7 @@ "schedule" ] }, + "job": { "type": "object", "additionalProperties": false, diff --git a/charts/library/common/schemas/definitions.json b/charts/library/common/schemas/definitions.json index 9f4b4e90..e7951769 100644 --- a/charts/library/common/schemas/definitions.json +++ b/charts/library/common/schemas/definitions.json @@ -1,4 +1,29 @@ { + "resourceIdentifier": { + "type": "object", + "properties": { + "forceRename": { + "type": "string", + "description": "Override the default resource name. This field is mutually exclusive with the prefix and suffix fields." + }, + "prefix": { + "type": "string", + "description": "Prefix to prepend to the resource name. This field is mutually exclusive with the forceRename field.", + "default": "" + }, + "suffix": { + "type": "string", + "description": "Suffix to append to the resource name. Defaults to the resource identifier if there are multiple items, otherwise it defaults to empty. This field is mutually exclusive with the forceRename field." + } + }, + "not" : { + "anyOf" : [ + {"required" : ["forceRename", "suffix"]}, + {"required" : ["forceRename", "prefix"]} + ] + } + }, + "annotations": { "type": ["object", "null"], "additionalProperties": { diff --git a/charts/library/common/schemas/ingress.json b/charts/library/common/schemas/ingress.json index 69225a43..5d016658 100644 --- a/charts/library/common/schemas/ingress.json +++ b/charts/library/common/schemas/ingress.json @@ -1,48 +1,45 @@ { "instance": { - "type": "object", - "additionalProperties": false, - - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - - "annotations": { - "$ref": "definitions.json#/annotations" - }, - - "className": { - "type": "string" - }, - - "defaultBackend": { - "$ref": "k8s-api.json#/networking.v1.ingressBackend" - }, - - "hosts": { - "type": "array", - "items": { - "$ref": "#/hostEntry" - } - }, - - "labels": { - "$ref": "definitions.json#/labels" - }, - - "nameOverride": { - "type": "string" - }, - - "tls": { - "type": "array", - "items": { - "$ref": "#/tlsEntry" + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "className": { + "type": "string" + }, + "defaultBackend": { + "$ref": "k8s-api.json#/networking.v1.ingressBackend" + }, + "hosts": { + "type": "array", + "items": { + "$ref": "#/hostEntry" + } + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "tls": { + "type": "array", + "items": { + "$ref": "#/tlsEntry" + } + } } } - } + ] }, "hostEntry": { @@ -70,7 +67,7 @@ ] } }, - "required": ["path", "service"] + "required": ["path"] }, "title": "paths", "type": "array" @@ -119,7 +116,6 @@ "port": { "type": ["string", "integer"] } - }, - "required": ["identifier"] + } } } diff --git a/charts/library/common/schemas/networkpolicy.json b/charts/library/common/schemas/networkpolicy.json index e4662e49..f30ce1e2 100644 --- a/charts/library/common/schemas/networkpolicy.json +++ b/charts/library/common/schemas/networkpolicy.json @@ -1,52 +1,57 @@ { "instance": { - "type": "object", - "additionalProperties": false, - - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "controller": { - "type": "string" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "podSelector": {}, - "policyTypes": { - "type": "array", - "items": { - "type": "string" - } - }, - "rules": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", "additionalProperties": false, "properties": { - "ingress": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "controller": { + "type": "string" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "podSelector": {}, + "policyTypes": { "type": "array", "items": { - "$ref": "k8s-api.json#/networking.v1.NetworkPolicyIngressRule" + "type": "string" } }, - "egress": { - "type": "array", - "items": { - "$ref": "k8s-api.json#/networking.v1.NetworkPolicyEgressRule" + "rules": { + "type": "object", + "additionalProperties": false, + + "properties": { + "ingress": { + "type": "array", + "items": { + "$ref": "k8s-api.json#/networking.v1.NetworkPolicyIngressRule" + } + }, + "egress": { + "type": "array", + "items": { + "$ref": "k8s-api.json#/networking.v1.NetworkPolicyEgressRule" + } + } } } - } + }, + "required": ["rules"] } - }, - "required": ["rules"] + ] } } diff --git a/charts/library/common/schemas/persistence.json b/charts/library/common/schemas/persistence.json index 50f2f919..0cb52a8f 100644 --- a/charts/library/common/schemas/persistence.json +++ b/charts/library/common/schemas/persistence.json @@ -13,51 +13,56 @@ }, "persistentVolumeClaimItem": { - "type": "object", - "additionalProperties": false, + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, - "properties": { - "type": { - "const": "persistentVolumeClaim" - }, - "enabled": { - "type": "boolean", - "default": true - }, - "accessMode": { - "type": "string" - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "dataSource": { - "$ref": "#/dataSourceReference" - }, - "dataSourceRef": { - "$ref": "#/dataSourceReference" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "retain": { - "type": "boolean" - }, - "size": { - "type": "string" - }, - "storageClass": { - "type": "string" - }, - "volumeName": { - "type": "string" - }, - "advancedMounts": {"$ref": "#/advancedMounts"}, - "globalMounts": {"$ref": "#/globalMounts"} - }, - "required": ["accessMode", "size"] + "properties": { + "type": { + "const": "persistentVolumeClaim" + }, + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "accessMode": { + "type": "string" + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "dataSource": { + "$ref": "#/dataSourceReference" + }, + "dataSourceRef": { + "$ref": "#/dataSourceReference" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "retain": { + "type": "boolean" + }, + "size": { + "type": "string" + }, + "storageClass": { + "type": "string" + }, + "volumeName": { + "type": "string" + }, + "advancedMounts": {"$ref": "#/advancedMounts"}, + "globalMounts": {"$ref": "#/globalMounts"} + }, + "required": ["accessMode", "size"] + } + ] }, "persistentVolumeClaimWithExistingClaimItem": { @@ -330,6 +335,9 @@ "subPath": { "type": "string" }, + "subPathExpr": { + "type": "string" + }, "mountPropagation": { "type": "string" } diff --git a/charts/library/common/schemas/pod.json b/charts/library/common/schemas/pod.json index 33ed7ced..32474529 100644 --- a/charts/library/common/schemas/pod.json +++ b/charts/library/common/schemas/pod.json @@ -67,6 +67,9 @@ "priorityClassName": { "type": "string" }, + "resources": { + "$ref": "k8s-api.json#/core.v1.ResourceRequirements" + }, "restartPolicy": { "type": "string" }, diff --git a/charts/library/common/schemas/rawResource.json b/charts/library/common/schemas/rawResource.json index 30b12456..910ccddc 100644 --- a/charts/library/common/schemas/rawResource.json +++ b/charts/library/common/schemas/rawResource.json @@ -1,32 +1,34 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "apiVersion": { - "type": "string" - }, - "kind": { - "type": "string" - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "forceRename": { - "type": "string" - }, - "spec": {} - }, - "required": ["apiVersion", "kind", "spec"] + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "apiVersion": { + "type": "string" + }, + "kind": { + "type": "string" + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "spec": {} + }, + "required": ["apiVersion", "kind", "spec"] + } + ] } } diff --git a/charts/library/common/schemas/rbac.json b/charts/library/common/schemas/rbac.json new file mode 100644 index 00000000..cf565dbb --- /dev/null +++ b/charts/library/common/schemas/rbac.json @@ -0,0 +1,118 @@ +{ + "role": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "type": { + "type": "string", + "enum": [ + "Role", + "ClusterRole" + ], + "default": "Role" + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "rules": { + "type": "array" + } + }, + "required": ["type", "rules"] + } + ] + }, + + "roleBinding": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "type": { + "type": "string", + "enum": [ + "RoleBinding", + "ClusterRoleBinding" + ], + "default": "RoleBinding" + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "roleRef": { + "type": "object", + "properties": { + "identifier": { + "type": "string" + }, + "name": { + "type": "string" + }, + "kind": { + "type": "string", + "enum": [ + "Role", + "ClusterRole" + ] + } + }, + "oneOf": [ + {"required": ["identifier"]}, + {"required": ["name", "kind"]} + ] + }, + "subjects": { + "type": "array", + "items": { + "type": "object", + "properties": { + "identifier": { + "type": "string" + }, + "name": { + "type": "string" + }, + "kind": { + "type": "string" + }, + "namespace": { + "type": "string" + } + }, + "oneOf": [ + {"required": ["identifier"]}, + {"required": ["name", "kind", "namespace"]} + ] + } + } + }, + "required": ["type", "roleRef", "subjects"] + } + ] + } +} diff --git a/charts/library/common/schemas/route.json b/charts/library/common/schemas/route.json index d428ac3d..c63b31ce 100644 --- a/charts/library/common/schemas/route.json +++ b/charts/library/common/schemas/route.json @@ -1,126 +1,140 @@ { "instance": { - "type": "object", - "additionalProperties": false, + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, + "hostnames": { + "type": "array", + "items": {"type": "string"} + }, - "hostnames": { - "type": "array", - "items": {"type": "string"} - }, + "kind": { + "type": "string", + "enum": ["GRPCRoute", "HTTPRoute", "TCPRoute", "TLSRoute", "UDPRoute"] + }, - "kind": { - "type": "string", - "enum": ["GRPCRoute", "HTTPRoute", "TCPRoute", "TLSRoute", "UDPRoute"] - }, - - "labels": { - "$ref": "definitions.json#/labels" - }, - - "nameOverride": { - "type": "string" - }, - - "parentRefs": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "group": { - "type": "string" - }, - "kind": { - "type": "string" - }, - "namespace": { - "type": "string" - }, - "name": { - "type": "string" - }, - "sectionName": { - "type": "string" + "parentRefs": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "group": { + "type": "string" + }, + "kind": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "name": { + "type": "string" + }, + "sectionName": { + "type": "string" + }, + "port": { + "type": "integer" + } + }, + "required": ["name"] } }, - "required": ["name"] - } - }, - "rules": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "backendRefs": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "group": { - "type": "string" - }, - "kind": { - "type": "string" - }, - "namespace": { - "type": "string" - }, - "name": { - "type": "string" - }, - "port": { - "type": ["string", "integer"] - }, - "weight": { - "type": "integer" - } - } - } - }, - "matches": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "path": { + "rules": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "backendRefs": { + "type": "array", + "items": { "type": "object", "additionalProperties": false, "properties": { - "type": { + "group": { "type": "string" }, - "value": { + "kind": { "type": "string" + }, + "namespace": { + "type": "string" + }, + "name": { + "type": "string", + "description": "A reference to a backend Service name." + }, + "identifier": { + "type": "string", + "description": "A reference to a backend service that is defined within the chart values." + }, + "port": { + "type": ["string", "integer"] + }, + "weight": { + "type": "integer" } } } + }, + "matches": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "path": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { + "type": "string" + }, + "value": { + "type": "string" + } + } + } + } + } + }, + "filters": { + "type": "array", + "items": {} + }, + "sessionPersistence": { + "description": "SessionPersistence defines the desired state of SessionPersistence", + "type": "object" + }, + "timeouts": { + "type": "object" } } - }, - "filters": { - "type": "array", - "items": {} - }, - "timeouts": { - "type": "object" } } } } - } + ] } } diff --git a/charts/library/common/schemas/secret.json b/charts/library/common/schemas/secret.json index 37794cac..938fda35 100644 --- a/charts/library/common/schemas/secret.json +++ b/charts/library/common/schemas/secret.json @@ -1,35 +1,40 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "includeInChecksum": { - "type": "boolean", - "default": true - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "type": { - "type": "string" - }, - "stringData": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", - "additionalProperties": { - "type": "string" - } + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "includeInChecksum": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "type": { + "type": "string" + }, + "stringData": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "required": ["stringData"] } - }, - "required": ["stringData"] + ] } } diff --git a/charts/library/common/schemas/service.json b/charts/library/common/schemas/service.json index dab114a3..1d861cb5 100644 --- a/charts/library/common/schemas/service.json +++ b/charts/library/common/schemas/service.json @@ -1,92 +1,97 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "type": { - "type": "string" - }, - "clusterIP": { - "type": "string" - }, - "externalName": { - "type": "string" - }, - "loadBalancerIP": { - "type": "string" - }, - "loadBalancerSourceRanges": { - "type": "array", - "items": {"type": "string"} - }, - "loadBalancerClass": { - "type": "string" - }, - "internalTrafficPolicy": { - "type": "string", - "enum": ["Cluster", "Local"] - }, - "externalTrafficPolicy": { - "type": "string", - "enum": ["Cluster", "Local"] - }, - "allocateLoadBalancerNodePorts": { - "type": "boolean" - }, - "sessionAffinity": { - "type": "string", - "enum": ["None", "ClientIP"] - }, - "sessionAffinityConfig": { - "type": "object" - }, - "externalIPs": { - "type": "array", - "items": {"type": "string"} - }, - "publishNotReadyAddresses": { - "type": "boolean" - }, - "ipFamilyPolicy": { - "type": "string", - "enum": ["SingleStack", "PreferDualStack", "RequireDualStack"] - }, - "ipFamilies": { - "type": "array", - "items": { - "type": "string", - "enum": ["IPv4", "IPv6"] - } - }, - "ports": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", - "additionalProperties": { - "$ref": "#/servicePort" - } - }, - "primary": { - "type": "boolean", - "default": false - }, - "controller": { - "type": "string" - }, - "extraSelectorLabels": {} - }, - "required": ["controller"] + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "type": { + "type": "string" + }, + "clusterIP": { + "type": "string" + }, + "externalName": { + "type": "string" + }, + "loadBalancerIP": { + "type": "string" + }, + "loadBalancerSourceRanges": { + "type": "array", + "items": {"type": "string"} + }, + "loadBalancerClass": { + "type": "string" + }, + "internalTrafficPolicy": { + "type": "string", + "enum": ["Cluster", "Local"] + }, + "externalTrafficPolicy": { + "type": "string", + "enum": ["Cluster", "Local"] + }, + "allocateLoadBalancerNodePorts": { + "type": "boolean" + }, + "sessionAffinity": { + "type": "string", + "enum": ["None", "ClientIP"] + }, + "sessionAffinityConfig": { + "type": "object" + }, + "externalIPs": { + "type": "array", + "items": {"type": "string"} + }, + "publishNotReadyAddresses": { + "type": "boolean" + }, + "ipFamilyPolicy": { + "type": "string", + "enum": ["SingleStack", "PreferDualStack", "RequireDualStack"] + }, + "ipFamilies": { + "type": "array", + "items": { + "type": "string", + "enum": ["IPv4", "IPv6"] + } + }, + "ports": { + "type": "object", + "additionalProperties": { + "$ref": "#/servicePort" + } + }, + "primary": { + "type": "boolean", + "default": false + }, + "controller": { + "type": "string" + }, + "extraSelectorLabels": {} + }, + "required": [] + } + ] }, "servicePort": { diff --git a/charts/library/common/schemas/serviceAccount.json b/charts/library/common/schemas/serviceAccount.json index ec2e1344..06c345bf 100644 --- a/charts/library/common/schemas/serviceAccount.json +++ b/charts/library/common/schemas/serviceAccount.json @@ -1,43 +1,30 @@ { - "settings": { - "type": "object", - "additionalProperties": false, - "properties": { - "create": { - "type": "boolean", - "default": false - }, - "name": { - "type": "string" - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "extraServiceAccounts": { + "instance": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", - "additionalProperties": { - "type": "object", - "additionalProperties": false, - "properties": { - "create": { - "type": "boolean", - "default": false - }, - "name": { - "type": "string" - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - } + "additionalProperties": false, + "properties": { + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true + }, + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "staticToken": { + "type": "boolean", + "default": false } } } - } + ] } } diff --git a/charts/library/common/schemas/serviceMonitor.json b/charts/library/common/schemas/serviceMonitor.json index 2f2e74ef..b7ffe287 100644 --- a/charts/library/common/schemas/serviceMonitor.json +++ b/charts/library/common/schemas/serviceMonitor.json @@ -1,65 +1,70 @@ { "instance": { - "type": "object", - "additionalProperties": false, - "properties": { - "enabled": { - "type": "boolean", - "default": true - }, - "annotations": { - "$ref": "definitions.json#/annotations" - }, - "labels": { - "$ref": "definitions.json#/labels" - }, - "nameOverride": { - "type": "string" - }, - "endpoints": { - "type": "array", - "items": { - "type": "object" - } - }, - "selector": { + "allOf": [ + { "$ref": "definitions.json#/resourceIdentifier" }, + { "type": "object", "additionalProperties": false, "properties": { - "matchLabels": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "forceRename": {}, + "prefix": {}, + "suffix": {}, + "enabled": { + "type": "boolean", + "default": true }, - "matchExpressions": { + "annotations": { + "$ref": "definitions.json#/annotations" + }, + "labels": { + "$ref": "definitions.json#/labels" + }, + "endpoints": { "type": "array", "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "key": {"type": "string"}, - "operator": {"type": "string"}, - "values": { - "type": "array", - "items": {"type": "string"} + "type": "object" + } + }, + "selector": { + "type": "object", + "additionalProperties": false, + "properties": { + "matchLabels": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "matchExpressions": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "key": {"type": "string"}, + "operator": {"type": "string"}, + "values": { + "type": "array", + "items": {"type": "string"} + } + } } } } + }, + "serviceName": { + "type": "string" + }, + "targetLabels": { + "type": "array" } + }, + "oneOf": [{"required": ["serviceName"]}, {"required": ["selector"]}], + "dependencies": { + "selector": {"not": {"required": ["serviceName"]}}, + "serviceName": {"not": {"required": ["selector"]}} } - }, - "serviceName": { - "type": "string" - }, - "targetLabels": { - "type": "array" } - }, - "oneOf": [{"required": ["serviceName"]}, {"required": ["selector"]}], - "dependencies": { - "selector": {"not": {"required": ["serviceName"]}}, - "serviceName": {"not": {"required": ["selector"]}} - } + ] } } diff --git a/charts/library/common/templates/classes/_configmap.tpl b/charts/library/common/templates/classes/_configmap.tpl index 5726a380..3bca863e 100644 --- a/charts/library/common/templates/classes/_configmap.tpl +++ b/charts/library/common/templates/classes/_configmap.tpl @@ -22,13 +22,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_cronjob.tpl b/charts/library/common/templates/classes/_cronjob.tpl index 030fa737..2eb609e7 100644 --- a/charts/library/common/templates/classes/_cronjob.tpl +++ b/charts/library/common/templates/classes/_cronjob.tpl @@ -6,13 +6,10 @@ using the common library. {{- $rootContext := .rootContext -}} {{- $cronjobObject := .object -}} - {{- $timeZone := "" -}} - {{- if ge (int $rootContext.Capabilities.KubeVersion.Minor) 27 }} - {{- $timeZone = dig "cronjob" "timeZone" "" $cronjobObject -}} - {{- end -}} + {{- $timeZone := dig "cronjob" "timeZone" "" $cronjobObject -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $cronjobObject.identifier) + (dict "app.kubernetes.io/controller" $cronjobObject.identifier) ($cronjobObject.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml) -}} @@ -30,13 +27,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_daemonset.tpl b/charts/library/common/templates/classes/_daemonset.tpl index 59c77839..1f30d771 100644 --- a/charts/library/common/templates/classes/_daemonset.tpl +++ b/charts/library/common/templates/classes/_daemonset.tpl @@ -7,7 +7,7 @@ within the common library. {{- $daemonsetObject := .object -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $daemonsetObject.identifier) + (dict "app.kubernetes.io/controller" $daemonsetObject.identifier) ($daemonsetObject.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml) -}} @@ -23,13 +23,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} @@ -37,7 +37,7 @@ spec: revisionHistoryLimit: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" $daemonsetObject.revisionHistoryLimit "default" 3) }} selector: matchLabels: - app.kubernetes.io/component: {{ $daemonsetObject.identifier }} + app.kubernetes.io/controller: {{ $daemonsetObject.identifier }} {{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }} template: metadata: diff --git a/charts/library/common/templates/classes/_deployment.tpl b/charts/library/common/templates/classes/_deployment.tpl index b26f19eb..ebcbd904 100644 --- a/charts/library/common/templates/classes/_deployment.tpl +++ b/charts/library/common/templates/classes/_deployment.tpl @@ -7,7 +7,7 @@ using the common library. {{- $deploymentObject := .object -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $deploymentObject.identifier) + (dict "app.kubernetes.io/controller" $deploymentObject.identifier) ($deploymentObject.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml) -}} @@ -23,13 +23,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} @@ -57,7 +57,7 @@ spec: {{- end }} selector: matchLabels: - app.kubernetes.io/component: {{ $deploymentObject.identifier }} + app.kubernetes.io/controller: {{ $deploymentObject.identifier }} {{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }} template: metadata: diff --git a/charts/library/common/templates/classes/_ingress.tpl b/charts/library/common/templates/classes/_ingress.tpl index 1c43459c..ef214e99 100644 --- a/charts/library/common/templates/classes/_ingress.tpl +++ b/charts/library/common/templates/classes/_ingress.tpl @@ -23,13 +23,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} @@ -72,7 +72,7 @@ spec: {{ else if .service.identifier -}} {{ $service = (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .service.identifier) | fromYaml ) -}} {{ if not $service -}} - {{fail (printf "No service found with this identifier. (ingress: '%s', path: '%s', identifier: '%s')" $ingressObject.identifier .path .service.identifier)}} + {{fail (printf "No enabled Service found with this identifier. (ingress: '%s', path: '%s', identifier: '%s')" $ingressObject.identifier .path .service.identifier)}} {{ end -}} {{ $serviceName = $service.name -}} {{ end -}} diff --git a/charts/library/common/templates/classes/_job.tpl b/charts/library/common/templates/classes/_job.tpl index a4b4a30a..cead71d2 100644 --- a/charts/library/common/templates/classes/_job.tpl +++ b/charts/library/common/templates/classes/_job.tpl @@ -7,7 +7,7 @@ within the common library. {{- $jobObject := .object -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $jobObject.identifier) + (dict "app.kubernetes.io/controller" $jobObject.identifier) ($jobObject.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml) -}} @@ -25,13 +25,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_networkpolicy.tpl b/charts/library/common/templates/classes/_networkpolicy.tpl index 2c113092..6e093348 100644 --- a/charts/library/common/templates/classes/_networkpolicy.tpl +++ b/charts/library/common/templates/classes/_networkpolicy.tpl @@ -20,7 +20,7 @@ within the common library. {{- else -}} {{- $podSelector = dict "matchLabels" (merge ($networkPolicyObject.extraSelectorLabels | default dict) - (dict "app.kubernetes.io/component" $networkPolicyObject.controller) + (dict "app.kubernetes.io/controller" $networkPolicyObject.controller) (include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml) ) -}} {{- end -}} @@ -32,13 +32,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_pvc.tpl b/charts/library/common/templates/classes/_pvc.tpl index 1e38e0b4..2ae7fb5c 100644 --- a/charts/library/common/templates/classes/_pvc.tpl +++ b/charts/library/common/templates/classes/_pvc.tpl @@ -20,7 +20,6 @@ within the common library. $annotations -}} {{- end -}} - --- kind: PersistentVolumeClaim apiVersion: v1 @@ -29,13 +28,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_rawResource.tpl b/charts/library/common/templates/classes/_rawResource.tpl index 016519a4..108d97e3 100644 --- a/charts/library/common/templates/classes/_rawResource.tpl +++ b/charts/library/common/templates/classes/_rawResource.tpl @@ -22,13 +22,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $resourceObject.spec }} diff --git a/charts/library/common/templates/classes/_role.tpl b/charts/library/common/templates/classes/_role.tpl index 0c1b9a6d..c35d3987 100644 --- a/charts/library/common/templates/classes/_role.tpl +++ b/charts/library/common/templates/classes/_role.tpl @@ -25,16 +25,21 @@ kind: {{ . }} metadata: name: {{ $roleObject.name }} {{- with $labels }} - labels: {{- toYaml . | nindent 4 -}} + labels: + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- end }} {{- end }} {{- with $annotations }} - annotations: {{- toYaml . | nindent 4 -}} + annotations: + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- end }} {{- end }} - {{ if eq $roleObject.type "Role" -}} + {{- if eq $roleObject.type "Role" }} namespace: {{ $rootContext.Release.Namespace }} - {{- end -}} -{{ with $rules }} + {{- end }} +{{- with $rules }} rules: {{- tpl . $rootContext | nindent 2 }} {{- end }} - {{- end -}} diff --git a/charts/library/common/templates/classes/_rolebinding.tpl b/charts/library/common/templates/classes/_rolebinding.tpl index 076658f0..d913ad30 100644 --- a/charts/library/common/templates/classes/_rolebinding.tpl +++ b/charts/library/common/templates/classes/_rolebinding.tpl @@ -18,6 +18,9 @@ This template serves as a blueprint for generating RoleBinding objects in Kubern {{- range $subject := . -}} {{- if hasKey . "identifier" -}} {{- $subject := include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml -}} + {{- if not $subject }} + {{- fail (printf "No enabled ServiceAccount found with this identifier. (rolebinding: '%s', identifier: '%s')" $roleBindingObject.identifier .identifier) -}} + {{- end -}} {{- $subject = pick $subject "name" -}} {{- $_ := set $subject "kind" "ServiceAccount" -}} {{- $_ := set $subject "namespace" $rootContext.Release.Namespace -}} @@ -38,7 +41,6 @@ This template serves as a blueprint for generating RoleBinding objects in Kubern {{- $_ := set $role "name" .name -}} {{- $_ := set $role "type" .kind -}} {{- end -}} - {{- end -}} --- apiVersion: rbac.authorization.k8s.io/v1 @@ -48,10 +50,16 @@ kind: {{ . }} metadata: name: {{ $roleBindingObject.name }} {{- with $labels }} - labels: {{- toYaml . | nindent 4 -}} + labels: + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- end }} {{- end }} {{- with $annotations }} - annotations: {{- toYaml . | nindent 4 -}} + annotations: + {{- range $key, $value := . }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- end }} {{- end }} {{ if eq $roleBindingObject.type "RoleBinding" -}} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_route.tpl b/charts/library/common/templates/classes/_route.tpl index f57b70b0..0587fa7f 100644 --- a/charts/library/common/templates/classes/_route.tpl +++ b/charts/library/common/templates/classes/_route.tpl @@ -50,6 +50,9 @@ spec: {{- if .sectionName }} sectionName: {{ .sectionName | quote }} {{- end }} + {{- if .port }} + port: {{ .port }} + {{- end }} {{- end }} {{- if and (ne $routeKind "TCPRoute") (ne $routeKind "UDPRoute") $routeObject.hostnames }} hostnames: @@ -59,35 +62,47 @@ spec: {{- end }} rules: {{- range $routeObject.rules }} - - backendRefs: - {{- range .backendRefs }} - {{ $service := include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .name) | fromYaml -}} - {{ $servicePrimaryPort := dict -}} - {{ if $service -}} - {{ $servicePrimaryPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}} - {{- end }} - - group: {{ .group | default "" | quote}} - kind: {{ .kind | default "Service" }} - name: {{ $service.name | default .name }} - namespace: {{ .namespace | default $rootContext.Release.Namespace }} - port: {{ .port | default $servicePrimaryPort.port }} - weight: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" .weight "default" 1) }} - {{- end }} - {{- if or (eq $routeKind "HTTPRoute") (eq $routeKind "GRPCRoute") }} - {{- with .matches }} - matches: - {{- toYaml . | nindent 6 }} + - backendRefs: + {{- if empty .backendRefs }} + {{- printf " []" }} + {{- else }} + {{- range .backendRefs }} + {{- $service := dict }} + {{- $serviceName := "" }} + {{- $defaultServicePort := dict }} + {{- if .name }} + {{- $serviceName = tpl .name $rootContext }} + {{- else if .identifier }} + {{- $service = (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml ) }} + {{- if not $service }} + {{- fail (printf "No enabled Service found with this identifier. (route: '%s', identifier: '%s')" $routeObject.identifier .identifier) }} + {{- end }} + {{- $serviceName = $service.name }} + {{- $defaultServicePort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml }} + {{- end }} + - group: {{ .group | default "" | quote}} + kind: {{ .kind | default "Service" }} + name: {{ $serviceName }} + namespace: {{ .namespace | default $rootContext.Release.Namespace }} + port: {{ .port | default $defaultServicePort.port }} + weight: {{ include "bjw-s.common.lib.defaultKeepNonNullValue" (dict "value" .weight "default" 1) }} + {{- end }} {{- end }} + {{- if or (eq $routeKind "HTTPRoute") (eq $routeKind "GRPCRoute") }} + {{- with .matches }} + matches: {{- toYaml . | nindent 8 }} + {{- end }} {{- with .filters }} - filters: - {{- toYaml . | nindent 6 }} + filters: {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .sessionPersistence }} + sessionPersistence: {{- toYaml . | nindent 8 }} + {{- end }} {{- end }} - {{- end }} - {{- if (eq $routeKind "HTTPRoute") }} - {{- with .timeouts }} - timeouts: - {{- toYaml . | nindent 6 }} + {{- if (eq $routeKind "HTTPRoute") }} + {{- with .timeouts }} + timeouts: {{- toYaml . | nindent 8 }} + {{- end }} {{- end }} - {{- end }} {{- end }} {{- end }} diff --git a/charts/library/common/templates/classes/_secret.tpl b/charts/library/common/templates/classes/_secret.tpl index 0b1869e5..8d6822ec 100644 --- a/charts/library/common/templates/classes/_secret.tpl +++ b/charts/library/common/templates/classes/_secret.tpl @@ -30,13 +30,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_service.tpl b/charts/library/common/templates/classes/_service.tpl index 7d37072e..78b0de06 100644 --- a/charts/library/common/templates/classes/_service.tpl +++ b/charts/library/common/templates/classes/_service.tpl @@ -25,13 +25,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} @@ -114,7 +114,7 @@ spec: {{- end -}} {{- with (merge ($serviceObject.extraSelectorLabels | default dict) - (dict "app.kubernetes.io/component" $serviceObject.controller) + (dict "app.kubernetes.io/controller" $serviceObject.controller) (include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml) ) }} selector: {{- toYaml . | nindent 4 }} diff --git a/charts/library/common/templates/classes/_serviceAccount.tpl b/charts/library/common/templates/classes/_serviceAccount.tpl index 3eff9f9e..be9cae5a 100644 --- a/charts/library/common/templates/classes/_serviceAccount.tpl +++ b/charts/library/common/templates/classes/_serviceAccount.tpl @@ -22,16 +22,18 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} +{{- if $serviceAccountObject.staticToken }} secrets: - name: {{ get (include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" (printf "%s-sa-token" $serviceAccountObject.identifier) ) | fromYaml) "name"}} +{{- end }} {{- end -}} diff --git a/charts/library/common/templates/classes/_serviceMonitor.tpl b/charts/library/common/templates/classes/_serviceMonitor.tpl index 85a18b1b..f766089b 100644 --- a/charts/library/common/templates/classes/_serviceMonitor.tpl +++ b/charts/library/common/templates/classes/_serviceMonitor.tpl @@ -17,13 +17,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} diff --git a/charts/library/common/templates/classes/_statefulset.tpl b/charts/library/common/templates/classes/_statefulset.tpl index 6d3ea795..0dc3fea9 100644 --- a/charts/library/common/templates/classes/_statefulset.tpl +++ b/charts/library/common/templates/classes/_statefulset.tpl @@ -7,7 +7,7 @@ within the common library. {{- $statefulsetObject := .object -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $statefulsetObject.identifier) + (dict "app.kubernetes.io/controller" $statefulsetObject.identifier) ($statefulsetObject.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml) -}} @@ -23,13 +23,13 @@ metadata: {{- with $labels }} labels: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} {{- with $annotations }} annotations: {{- range $key, $value := . }} - {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} + {{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }} {{- end }} {{- end }} namespace: {{ $rootContext.Release.Namespace }} @@ -45,7 +45,7 @@ spec: {{- end }} selector: matchLabels: - app.kubernetes.io/component: {{ $statefulsetObject.identifier }} + app.kubernetes.io/controller: {{ $statefulsetObject.identifier }} {{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }} serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" $rootContext }} {{- with (dig "statefulset" "persistentVolumeClaimRetentionPolicy" nil $statefulsetObject) }} diff --git a/charts/library/common/templates/lib/common/_determineResourceNameFromValues.tpl b/charts/library/common/templates/lib/common/_determineResourceNameFromValues.tpl new file mode 100644 index 00000000..59532c78 --- /dev/null +++ b/charts/library/common/templates/lib/common/_determineResourceNameFromValues.tpl @@ -0,0 +1,38 @@ +{{/* +Determine a recourse name based on Helm values +*/}} +{{- define "bjw-s.common.lib.determineResourceNameFromValues" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $objectValues := .values -}} + {{- $itemCount := .itemCount -}} + + {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} + + {{- if $objectValues.forceRename -}} + {{- $objectName = tpl $objectValues.forceRename $rootContext -}} + {{- else -}} + {{- if not (empty $objectValues.prefix) -}} + {{- $renderedPrefix := (tpl $objectValues.prefix $rootContext) -}} + {{- if not (eq $objectName $renderedPrefix) -}} + {{- $objectName = printf "%s-%s" $renderedPrefix $objectName -}} + {{- end -}} + {{- end -}} + + {{- if not (empty $itemCount) -}} + {{- if (gt $itemCount 1) -}} + {{- if not (hasSuffix (printf "-%s" $identifier) $objectName) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- if not (empty $objectValues.suffix) -}} + {{- $renderedSuffix := (tpl $objectValues.suffix $rootContext) -}} + {{- if not (hasSuffix (printf "-%s" $renderedSuffix) $objectName) -}} + {{- $objectName = printf "%s-%s" $objectName $renderedSuffix -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- $objectName | lower -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/common/_valuesToObject.tpl b/charts/library/common/templates/lib/common/_valuesToObject.tpl index cec04530..9e50bf6b 100644 --- a/charts/library/common/templates/lib/common/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/common/_valuesToObject.tpl @@ -5,25 +5,12 @@ Convert values to an object {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} {{- $objectValues := .values -}} + {{- $itemCount := .itemCount -}} - {{- /* Determine and inject the name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.forceRename -}} - {{- $objectName = tpl $objectValues.forceRename $rootContext -}} - {{- else if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} + {{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}} {{- $_ := set $objectValues "name" $objectName -}} {{- $_ := set $objectValues "identifier" $identifier -}} - {{- /* Return the object */ -}} + {{- $objectValues | toYaml -}} {{- end -}} diff --git a/charts/library/common/templates/lib/configMap/_enabled_configmaps.tpl b/charts/library/common/templates/lib/configMap/_enabled_configmaps.tpl new file mode 100644 index 00000000..ab0f8c35 --- /dev/null +++ b/charts/library/common/templates/lib/configMap/_enabled_configmaps.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled configMaps. +*/}} +{{- define "bjw-s.common.lib.configMap.enabledConfigmaps" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledSecrets := dict -}} + + {{- range $identifier, $secret := $rootContext.Values.configMaps -}} + {{- if kindIs "map" $secret -}} + {{- /* Enable Secret by default, but allow override */ -}} + {{- $secretEnabled := true -}} + {{- if hasKey $secret "enabled" -}} + {{- $secretEnabled = $secret.enabled -}} + {{- end -}} + + {{- if $secretEnabled -}} + {{- $_ := set $enabledSecrets $identifier . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledSecrets | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/configMap/_getByIdentifier.tpl b/charts/library/common/templates/lib/configMap/_getByIdentifier.tpl index 395a086d..46cf9abc 100644 --- a/charts/library/common/templates/lib/configMap/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/configMap/_getByIdentifier.tpl @@ -4,9 +4,10 @@ Return a configMap Object by its Identifier. {{- define "bjw-s.common.lib.configMap.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledConfigMaps := (include "bjw-s.common.lib.configMap.enabledConfigmaps" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- $configMapValues := dig $identifier nil $rootContext.Values.configMaps -}} - {{- if not (empty $configMapValues) -}} - {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $configMapValues) -}} + {{- if (hasKey $enabledConfigMaps $identifier) -}} + {{- $objectValues := get $enabledConfigMaps $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledConfigMaps)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/configMap/_validate.tpl b/charts/library/common/templates/lib/configMap/_validate.tpl index 2433e2f1..4e780f37 100644 --- a/charts/library/common/templates/lib/configMap/_validate.tpl +++ b/charts/library/common/templates/lib/configMap/_validate.tpl @@ -6,9 +6,10 @@ Validate configMap values {{- $configMapValues := .object -}} {{- $identifier := .id -}} - {{- if empty $configMapValues -}} + {{- if eq (len (without (keys $configMapValues) "name" "identifier")) 0 -}} {{- fail (printf "There was an error loading ConfigMap: %s. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" $identifier) -}} {{- end -}} + {{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}} {{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }} {{- end -}} diff --git a/charts/library/common/templates/lib/container/fields/_volumeMounts.tpl b/charts/library/common/templates/lib/container/fields/_volumeMounts.tpl index 5139866b..2bac53a1 100644 --- a/charts/library/common/templates/lib/container/fields/_volumeMounts.tpl +++ b/charts/library/common/templates/lib/container/fields/_volumeMounts.tpl @@ -81,20 +81,22 @@ volumeMounts used by the container. {{- /* Use the specified subPath if provided */ -}} {{- with .subPath -}} - {{- $subPath := . -}} - {{- $_ := set $volumeMount "subPath" $subPath -}} + {{- $_ := set $volumeMount "subPath" . -}} + {{- end -}} + + {{- /* Use the specified subPathExpr if provided */ -}} + {{- with .subPathExpr -}} + {{- $_ := set $volumeMount "subPathExpr" . -}} {{- end -}} {{- /* Use the specified readOnly setting if provided */ -}} {{- with .readOnly -}} - {{- $readOnly := . -}} - {{- $_ := set $volumeMount "readOnly" $readOnly -}} + {{- $_ := set $volumeMount "readOnly" . -}} {{- end -}} {{- /* Use the specified mountPropagation setting if provided */ -}} {{- with .mountPropagation -}} - {{- $mountPropagation := . -}} - {{- $_ := set $volumeMount "mountPropagation" $mountPropagation -}} + {{- $_ := set $volumeMount "mountPropagation" . -}} {{- end -}} {{- $enabledVolumeMounts = append $enabledVolumeMounts $volumeMount -}} diff --git a/charts/library/common/templates/lib/controller/_getByIdentifier.tpl b/charts/library/common/templates/lib/controller/_getByIdentifier.tpl index b1faaa6a..e8657125 100644 --- a/charts/library/common/templates/lib/controller/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/controller/_getByIdentifier.tpl @@ -1,14 +1,19 @@ {{/* -Return a controller by its identifier. +Return a controller object by its Identifier. */}} {{- define "bjw-s.common.lib.controller.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- $enabledControllers := include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml -}} - {{- $controllerValues := get $enabledControllers $identifier -}} + {{- if (hasKey $enabledControllers $identifier) -}} + {{- $objectValues := get $enabledControllers $identifier -}} - {{- if not (empty $controllerValues) -}} - {{- include "bjw-s.common.lib.controller.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerValues) -}} + {{- /* Default the controller type to Deployment */ -}} + {{- if empty (dig "type" nil $objectValues) -}} + {{- $_ := set $objectValues "type" "deployment" -}} + {{- end -}} + + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledControllers)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/controller/_valuesToObject.tpl b/charts/library/common/templates/lib/controller/_valuesToObject.tpl deleted file mode 100644 index ef4be269..00000000 --- a/charts/library/common/templates/lib/controller/_valuesToObject.tpl +++ /dev/null @@ -1,35 +0,0 @@ -{{/* -Convert controller values to an object -*/}} -{{- define "bjw-s.common.lib.controller.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Default the controller type to Deployment */ -}} - {{- if empty (dig "type" nil $objectValues) -}} - {{- $_ := set $objectValues "type" "deployment" -}} - {{- end -}} - - {{- /* Determine and inject the controller name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if gt (len $enabledControllers) 1 -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the controller object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/cronjob/_valuesToObject.tpl b/charts/library/common/templates/lib/cronjob/_valuesToObject.tpl index 5657be59..21df2bcf 100644 --- a/charts/library/common/templates/lib/cronjob/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/cronjob/_valuesToObject.tpl @@ -5,6 +5,12 @@ Convert Cronjob values to an object {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} {{- $objectValues := .values -}} + {{- $itemCount := .itemCount -}} + + {{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}} + + {{- $_ := set $objectValues "name" $objectName -}} + {{- $_ := set $objectValues "identifier" $identifier -}} {{- if not (hasKey $objectValues "pod") -}} {{- $_ := set $objectValues "pod" dict -}} @@ -13,6 +19,5 @@ Convert Cronjob values to an object {{- $restartPolicy := default "Never" $objectValues.pod.restartPolicy -}} {{- $_ := set $objectValues.pod "restartPolicy" $restartPolicy -}} - {{- /* Return the CronJob object */ -}} {{- $objectValues | toYaml -}} {{- end -}} diff --git a/charts/library/common/templates/lib/ingress/_getByIdentifier.tpl b/charts/library/common/templates/lib/ingress/_getByIdentifier.tpl new file mode 100644 index 00000000..cdd018f4 --- /dev/null +++ b/charts/library/common/templates/lib/ingress/_getByIdentifier.tpl @@ -0,0 +1,30 @@ +{{/* +Return an Ingress Object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.ingress.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + + {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledIngresses $identifier) -}} + {{- $objectValues := get $enabledIngresses $identifier -}} + {{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledIngresses)) | fromYaml -}} + + {{- /* Try to automatically determine the default Service identifier if needed and possible */ -}} + {{- if eq 1 (len $enabledServices) -}} + {{- range $object.hosts -}} + {{- range .paths -}} + {{- if not (has "service" (keys .)) -}} + {{- $_ := set . "service" (dict "identifier" ($enabledServices | keys | first)) -}} + {{- else if and (not .service.name) (not .service.identifier) -}} + {{- $_ := set .service "identifier" ($enabledServices | keys | first) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $object | toYaml -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/ingress/_validate.tpl b/charts/library/common/templates/lib/ingress/_validate.tpl index b47bf3f0..95b931b9 100644 --- a/charts/library/common/templates/lib/ingress/_validate.tpl +++ b/charts/library/common/templates/lib/ingress/_validate.tpl @@ -3,5 +3,21 @@ Validate Ingress values */}} {{- define "bjw-s.common.lib.ingress.validate" -}} {{- $rootContext := .rootContext -}} - {{- $ingressValues := .object -}} + {{- $ingressObject := .object -}} + + {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}} + + {{/* Verify automatic service detection */}} + {{- if not (eq 1 (len $enabledServices)) -}} + {{- range $ingressObject.hosts -}} + {{- $host := . -}} + {{- range $host.paths -}} + {{- $path := . -}} + {{- if or (not (has "service" (keys .))) (and (not $path.service.name) (not $path.service.identifier)) -}} + {{- fail (printf "Either service.name or service.identifier is required because automatic Service detection is not possible. (ingress: %s, host: %s, path: %s)" $ingressObject.identifier $host.host $path.path ) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} diff --git a/charts/library/common/templates/lib/ingress/_valuesToObject.tpl b/charts/library/common/templates/lib/ingress/_valuesToObject.tpl deleted file mode 100644 index 0c798759..00000000 --- a/charts/library/common/templates/lib/ingress/_valuesToObject.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -Convert ingress values to an object -*/}} -{{- define "bjw-s.common.lib.ingress.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the ingress name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if gt (len $enabledIngresses) 1 -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the ingress object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/networkpolicy/_enabled_networkpolicies.tpl b/charts/library/common/templates/lib/networkpolicy/_enabled_networkpolicies.tpl index 74f40f43..0ff6ffeb 100644 --- a/charts/library/common/templates/lib/networkpolicy/_enabled_networkpolicies.tpl +++ b/charts/library/common/templates/lib/networkpolicy/_enabled_networkpolicies.tpl @@ -1,7 +1,7 @@ {{/* Return the enabled NetworkPolicies. */}} -{{- define "bjw-s.common.lib.networkPolicy.enabledNetworkPolicies" -}} +{{- define "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" -}} {{- $rootContext := .rootContext -}} {{- $enabledNetworkPolicies := dict -}} diff --git a/charts/library/common/templates/lib/networkpolicy/_getByIdentifier.tpl b/charts/library/common/templates/lib/networkpolicy/_getByIdentifier.tpl new file mode 100644 index 00000000..3d131a98 --- /dev/null +++ b/charts/library/common/templates/lib/networkpolicy/_getByIdentifier.tpl @@ -0,0 +1,13 @@ +{{/* +Return a NetworkPolicy object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.networkpolicy.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledNetworkPolicies $identifier) -}} + {{- $objectValues := get $enabledNetworkPolicies $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledNetworkPolicies)) -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl b/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl deleted file mode 100644 index fefd459e..00000000 --- a/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -Convert networkPolicy values to an object -*/}} -{{- define "bjw-s.common.lib.networkpolicy.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the networkPolicy name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkPolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if gt (len $enabledNetworkPolicies) 1 -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the networkPolicy object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/pod/_getOption.tpl b/charts/library/common/templates/lib/pod/_getOption.tpl index 70c7a19a..f18d7887 100644 --- a/charts/library/common/templates/lib/pod/_getOption.tpl +++ b/charts/library/common/templates/lib/pod/_getOption.tpl @@ -6,9 +6,10 @@ Returns the value for the specified field {{- $controllerObject := .ctx.controllerObject -}} {{- $option := .option -}} {{- $default := default "" .default -}} - {{- $value := $default -}} + {{- $defaultPodOptionsStrategy := dig "defaultPodOptionsStrategy" "overwrite" $rootContext.Values -}} + {{- /* Set to the default if it is set */ -}} {{- $defaultOption := dig $option nil (default dict $rootContext.Values.defaultPodOptions) -}} {{- if kindIs "bool" $defaultOption -}} @@ -19,8 +20,15 @@ Returns the value for the specified field {{- /* See if a pod-specific override is needed */ -}} {{- $podOption := dig $option nil (default dict $controllerObject.pod) -}} + {{- if kindIs "bool" $podOption -}} {{- $value = $podOption -}} + {{- else if kindIs "map" $podOption -}} + {{- if eq "merge" $defaultPodOptionsStrategy -}} + {{- $value = merge $podOption $value -}} + {{- else if eq "overwrite" $defaultPodOptionsStrategy -}} + {{- $value = $podOption -}} + {{- end -}} {{- else if not (empty $podOption) -}} {{- $value = $podOption -}} {{- end -}} diff --git a/charts/library/common/templates/lib/pod/_spec.tpl b/charts/library/common/templates/lib/pod/_spec.tpl index 4d9b7fd4..c6d69b9a 100644 --- a/charts/library/common/templates/lib/pod/_spec.tpl +++ b/charts/library/common/templates/lib/pod/_spec.tpl @@ -48,6 +48,11 @@ imagePullSecrets: {{ . | nindent 2 }} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "terminationGracePeriodSeconds")) }} terminationGracePeriodSeconds: {{ . | trim }} {{- end -}} + {{- if ge ($rootContext.Capabilities.KubeVersion.Minor | int) 32 }} + {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "resources")) }} +resources: {{ . | nindent 2 }} + {{- end -}} + {{- end -}} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "restartPolicy")) }} restartPolicy: {{ . | trim }} {{- end -}} diff --git a/charts/library/common/templates/lib/pod/fields/_serviceAccountName.tpl b/charts/library/common/templates/lib/pod/fields/_serviceAccountName.tpl index bb2303bd..b6c41898 100644 --- a/charts/library/common/templates/lib/pod/fields/_serviceAccountName.tpl +++ b/charts/library/common/templates/lib/pod/fields/_serviceAccountName.tpl @@ -4,24 +4,20 @@ Returns the value for serviceAccountName {{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}} {{- $rootContext := .ctx.rootContext -}} {{- $controllerObject := .ctx.controllerObject -}} - {{- $serviceAccountName := "default" -}} - {{- if $rootContext.Values.enforceServiceAccountCreation -}} - {{- if (get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "create") -}} - {{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "name" -}} - {{- end -}} - {{- else -}} - {{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" "default") | fromYaml) "name" -}} - {{- end -}} - {{- with $controllerObject.serviceAccount -}} {{- if hasKey . "identifier" -}} - {{- $serviceAccountName = get (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml) "name" -}} + {{- $subject := (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" .identifier) | fromYaml) -}} + + {{- if not $subject }} + {{- fail (printf "No enabled ServiceAccount found with this identifier. (controller: '%s', identifier: '%s')" $controllerObject.identifier .identifier) -}} + {{- end -}} + + {{- $serviceAccountName = get $subject "name" -}} {{- else if hasKey . "name" -}} {{- $serviceAccountName = .name -}} {{- end -}} {{- end -}} {{- $serviceAccountName -}} - {{- end -}} diff --git a/charts/library/common/templates/lib/pod/fields/_volumes.tpl b/charts/library/common/templates/lib/pod/fields/_volumes.tpl index 8bb09593..506a008f 100644 --- a/charts/library/common/templates/lib/pod/fields/_volumes.tpl +++ b/charts/library/common/templates/lib/pod/fields/_volumes.tpl @@ -46,15 +46,8 @@ Returns the value for volumes {{- $pvcName = $persistenceValues.existingClaim -}} {{- else -}} {{- /* Otherwise refer to the PVC name */ -}} - {{- if $persistenceValues.nameOverride -}} - {{- if not (eq $persistenceValues.nameOverride "-") -}} - {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $persistenceValues.nameOverride) -}} - {{- end -}} - {{- else -}} - {{- if not (eq $pvcName $identifier) -}} - {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}} - {{- end -}} - {{- end -}} + {{- $object := (include "bjw-s.common.lib.pvc.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} + {{- $pvcName = get $object "name" -}} {{- end -}} {{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}} diff --git a/charts/library/common/templates/lib/pod/metadata/_labels.tpl b/charts/library/common/templates/lib/pod/metadata/_labels.tpl index c6e43d39..b9da413c 100644 --- a/charts/library/common/templates/lib/pod/metadata/_labels.tpl +++ b/charts/library/common/templates/lib/pod/metadata/_labels.tpl @@ -7,7 +7,7 @@ Returns the value for labels {{- /* Default labels */ -}} {{- $labels := merge - (dict "app.kubernetes.io/component" $controllerObject.identifier) + (dict "app.kubernetes.io/controller" $controllerObject.identifier) -}} {{- /* Include global labels if specified */ -}} diff --git a/charts/library/common/templates/lib/pvc/_enabled_pvcs.tpl b/charts/library/common/templates/lib/pvc/_enabled_pvcs.tpl new file mode 100644 index 00000000..cae3eb12 --- /dev/null +++ b/charts/library/common/templates/lib/pvc/_enabled_pvcs.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled PVCs. +*/}} +{{- define "bjw-s.common.lib.pvc.enabledPVCs" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledPVCs := dict -}} + + {{- range $identifier, $persistenceItem := $rootContext.Values.persistence -}} + {{- if kindIs "map" $persistenceItem -}} + {{- /* Enable PVC by default, but allow override */ -}} + {{- $pvcEnabled := true -}} + {{- if hasKey $persistenceItem "enabled" -}} + {{- $pvcEnabled = $persistenceItem.enabled -}} + {{- end -}} + + {{- if and $pvcEnabled (eq (default "persistentVolumeClaim" $persistenceItem.type) "persistentVolumeClaim") (not $persistenceItem.existingClaim) -}} + {{- $_ := set $enabledPVCs $identifier . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledPVCs | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/pvc/_enabled_roles.tpl b/charts/library/common/templates/lib/pvc/_enabled_roles.tpl new file mode 100644 index 00000000..bd17d30b --- /dev/null +++ b/charts/library/common/templates/lib/pvc/_enabled_roles.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled roles. +*/}} +{{- define "bjw-s.common.lib.rbac.role.enabledRoles" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledRoles := dict -}} + + {{- range $name, $role := $rootContext.Values.rbac.roles -}} + {{- if kindIs "map" $role -}} + {{- /* Enable Role by default, but allow override */ -}} + {{- $roleEnabled := true -}} + {{- if hasKey $role "enabled" -}} + {{- $roleEnabled = $role.enabled -}} + {{- end -}} + + {{- if $roleEnabled -}} + {{- $_ := set $enabledRoles $name . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledRoles | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/pvc/_getByIdentifier.tpl b/charts/library/common/templates/lib/pvc/_getByIdentifier.tpl new file mode 100644 index 00000000..a223f6d4 --- /dev/null +++ b/charts/library/common/templates/lib/pvc/_getByIdentifier.tpl @@ -0,0 +1,13 @@ +{{/* +Return a PVC object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.pvc.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $enabledPVCs := (include "bjw-s.common.lib.pvc.enabledPVCs" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledPVCs $identifier) -}} + {{- $objectValues := get $enabledPVCs $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledPVCs)) -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/pvc/_validate.tpl b/charts/library/common/templates/lib/pvc/_validate.tpl deleted file mode 100644 index 23110faf..00000000 --- a/charts/library/common/templates/lib/pvc/_validate.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{{/* -Validate PVC values -*/}} -{{- define "bjw-s.common.lib.pvc.validate" -}} - {{- $rootContext := .rootContext -}} - {{- $pvcObject := .object -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/pvc/_valuesToObject.tpl b/charts/library/common/templates/lib/pvc/_valuesToObject.tpl deleted file mode 100644 index bfbf958e..00000000 --- a/charts/library/common/templates/lib/pvc/_valuesToObject.tpl +++ /dev/null @@ -1,26 +0,0 @@ -{{/* -Convert PVC values to an object -*/}} -{{- define "bjw-s.common.lib.pvc.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the PVC name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- if ne $objectValues.nameOverride "-" -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} - {{- end -}} - {{- else -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the PVC object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/rawResource/_enabled_rawResources.tpl b/charts/library/common/templates/lib/rawResource/_enabled_rawResources.tpl new file mode 100644 index 00000000..b8ba2447 --- /dev/null +++ b/charts/library/common/templates/lib/rawResource/_enabled_rawResources.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled raw resources. +*/}} +{{- define "bjw-s.common.lib.rawResource.enabledRawResources" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledRawResources := dict -}} + + {{- range $name, $resource := $rootContext.Values.rawResources -}} + {{- if kindIs "map" $resource -}} + {{- /* Enable Raw Resource by default, but allow override */ -}} + {{- $resourceEnabled := true -}} + {{- if hasKey $resource "enabled" -}} + {{- $resourceEnabled = $resource.enabled -}} + {{- end -}} + + {{- if $resourceEnabled -}} + {{- $_ := set $enabledRawResources $name . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledRawResources | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/rawResource/_getByIdentifier.tpl b/charts/library/common/templates/lib/rawResource/_getByIdentifier.tpl new file mode 100644 index 00000000..1a74dc99 --- /dev/null +++ b/charts/library/common/templates/lib/rawResource/_getByIdentifier.tpl @@ -0,0 +1,13 @@ +{{/* +Return a RawResource Object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.rawResource.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $enabledRawResources := (include "bjw-s.common.lib.rawResource.enabledRawResources" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledRawResources $identifier) -}} + {{- $objectValues := get $enabledRawResources $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRawResources)) -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/rawResource/_validate.tpl b/charts/library/common/templates/lib/rawResource/_validate.tpl deleted file mode 100644 index 241e3be3..00000000 --- a/charts/library/common/templates/lib/rawResource/_validate.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{{/* -Validate raw resource values -*/}} -{{- define "bjw-s.common.lib.rawResource.validate" -}} - {{- $rootContext := .rootContext -}} - {{- $resourceObject := .object -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/role/_enabled_roles.tpl b/charts/library/common/templates/lib/role/_enabled_roles.tpl new file mode 100644 index 00000000..bd17d30b --- /dev/null +++ b/charts/library/common/templates/lib/role/_enabled_roles.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled roles. +*/}} +{{- define "bjw-s.common.lib.rbac.role.enabledRoles" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledRoles := dict -}} + + {{- range $name, $role := $rootContext.Values.rbac.roles -}} + {{- if kindIs "map" $role -}} + {{- /* Enable Role by default, but allow override */ -}} + {{- $roleEnabled := true -}} + {{- if hasKey $role "enabled" -}} + {{- $roleEnabled = $role.enabled -}} + {{- end -}} + + {{- if $roleEnabled -}} + {{- $_ := set $enabledRoles $name . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledRoles | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/role/_getByIdentifier.tpl b/charts/library/common/templates/lib/role/_getByIdentifier.tpl index f1092ed1..79043eed 100644 --- a/charts/library/common/templates/lib/role/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/role/_getByIdentifier.tpl @@ -4,9 +4,10 @@ Return a Role Object by its Identifier. {{- define "bjw-s.common.lib.rbac.role.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledRoles := (include "bjw-s.common.lib.rbac.role.enabledRoles" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- $roleValues := dig $identifier nil $rootContext.Values.rbac.roles -}} - {{- if not (empty $roleValues) -}} - {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleValues) -}} + {{- if (hasKey $enabledRoles $identifier) -}} + {{- $objectValues := get $enabledRoles $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoles)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/role/_validate.tpl b/charts/library/common/templates/lib/role/_validate.tpl index 2516800d..9779cd91 100644 --- a/charts/library/common/templates/lib/role/_validate.tpl +++ b/charts/library/common/templates/lib/role/_validate.tpl @@ -4,15 +4,9 @@ Validate Role values {{- define "bjw-s.common.lib.rbac.role.validate" -}} {{- $rootContext := .rootContext -}} {{- $roleValues := .object -}} - {{- $type := required "The role needs to have an explicitly declared type" $roleValues.type -}} - {{- $typeList := list "Role" "ClusterRole" -}} {{- $rules := $roleValues.rules -}} - {{- if not (mustHas $type $typeList) -}} - {{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}} - {{- end -}} {{- if not $rules -}} {{- fail "Rules can't be empty" -}} {{- end -}} - {{- end -}} diff --git a/charts/library/common/templates/lib/rolebinding/_enabled_roleBindings.tpl b/charts/library/common/templates/lib/rolebinding/_enabled_roleBindings.tpl new file mode 100644 index 00000000..f4a0e275 --- /dev/null +++ b/charts/library/common/templates/lib/rolebinding/_enabled_roleBindings.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled RoleBindings. +*/}} +{{- define "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledRoleBindings := dict -}} + + {{- range $name, $role := $rootContext.Values.rbac.bindings -}} + {{- if kindIs "map" $role -}} + {{- /* Enable Role by default, but allow override */ -}} + {{- $roleEnabled := true -}} + {{- if hasKey $role "enabled" -}} + {{- $roleEnabled = $role.enabled -}} + {{- end -}} + + {{- if $roleEnabled -}} + {{- $_ := set $enabledRoleBindings $name . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledRoleBindings | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/rolebinding/_getByIdentifier.tpl b/charts/library/common/templates/lib/rolebinding/_getByIdentifier.tpl index e9a99d4c..5fd25c39 100644 --- a/charts/library/common/templates/lib/rolebinding/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/rolebinding/_getByIdentifier.tpl @@ -4,9 +4,10 @@ Return a RoleBinding Object by its Identifier. {{- define "bjw-s.common.lib.rbac.roleBinding.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledRoleBindings := (include "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- $roleBindingValues := dig $identifier nil $rootContext.Values.rbac.bindings -}} - {{- if not (empty $roleBindingValues) -}} - {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $roleBindingValues) -}} + {{- if (hasKey $enabledRoleBindings $identifier) -}} + {{- $objectValues := get $enabledRoleBindings $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoleBindings)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/rolebinding/_validate.tpl b/charts/library/common/templates/lib/rolebinding/_validate.tpl deleted file mode 100644 index 27113d64..00000000 --- a/charts/library/common/templates/lib/rolebinding/_validate.tpl +++ /dev/null @@ -1,32 +0,0 @@ -{{/* -Validate RoleBinding values -*/}} -{{- define "bjw-s.common.lib.rbac.roleBinding.validate" -}} - {{- $rootContext := .rootContext -}} - {{- $roleBindingValues := .object -}} - {{- $type := required "The binding needs to have an explicitly declared type" $roleBindingValues.type -}} - {{- $typeList := list "RoleBinding" "ClusterRoleBinding" -}} - {{- $subjects := $roleBindingValues.subjects -}} - {{- $roleRef := required "A roleRef is required" $roleBindingValues.roleRef -}} - - {{- if not (mustHas $type $typeList) -}} - {{- fail (printf "\nYou selected: `%s`. Type must be one of:\n%s\n" $type ($typeList|toYaml)) -}} - {{- end -}} - - {{- if not (hasKey $roleRef "identifier") -}} - {{- $name := required "If not using identifier roleRef must have a `name` key" $roleRef.name -}} - {{- $name := required "If not using identifier roleRef must have a `kind` key" $roleRef.kind -}} - {{- end -}} - - {{- range $subject := $subjects -}} - {{- if not (hasKey . "identifier") -}} - {{- if not (hasKey . "name") -}} - {{- $name := required "If not using identifier a subject must have a `name` key" .name -}} - {{- else if not (hasKey . "namespace") -}} - {{- $namespace := required "If not using identifier a subject must have a `namespace` key" .namespace -}} - {{- else if not (hasKey . "kind") -}} - {{- $kind := required "If not using identifier a subject must have a `kind` key" .kind -}} - {{- end -}} - {{- end -}} - {{- end -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/routes/_getByIdentifier.tpl b/charts/library/common/templates/lib/routes/_getByIdentifier.tpl new file mode 100644 index 00000000..de8d6caa --- /dev/null +++ b/charts/library/common/templates/lib/routes/_getByIdentifier.tpl @@ -0,0 +1,13 @@ +{{/* +Return a Route object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.route.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledRoutes $identifier) -}} + {{- $objectValues := get $enabledRoutes $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledRoutes)) -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/routes/_valuesToObject.tpl b/charts/library/common/templates/lib/routes/_valuesToObject.tpl deleted file mode 100644 index 61382bf1..00000000 --- a/charts/library/common/templates/lib/routes/_valuesToObject.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -Convert Route values to an object -*/}} -{{- define "bjw-s.common.lib.route.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the Route name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if and (not $objectValues.primary) (gt (len $enabledRoutes) 1) -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the Route object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/secret/_enabled_secrets.tpl b/charts/library/common/templates/lib/secret/_enabled_secrets.tpl new file mode 100644 index 00000000..2ba6b33f --- /dev/null +++ b/charts/library/common/templates/lib/secret/_enabled_secrets.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled secrets. +*/}} +{{- define "bjw-s.common.lib.secret.enabledSecrets" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledSecrets := dict -}} + + {{- range $identifier, $secret := $rootContext.Values.secrets -}} + {{- if kindIs "map" $secret -}} + {{- /* Enable Secret by default, but allow override */ -}} + {{- $secretEnabled := true -}} + {{- if hasKey $secret "enabled" -}} + {{- $secretEnabled = $secret.enabled -}} + {{- end -}} + + {{- if $secretEnabled -}} + {{- $_ := set $enabledSecrets $identifier . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledSecrets | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/secret/_getByIdentifier.tpl b/charts/library/common/templates/lib/secret/_getByIdentifier.tpl index ae797bf5..869b2d47 100644 --- a/charts/library/common/templates/lib/secret/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/secret/_getByIdentifier.tpl @@ -4,9 +4,10 @@ Return a secret Object by its Identifier. {{- define "bjw-s.common.lib.secret.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledSecrets := (include "bjw-s.common.lib.secret.enabledSecrets" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- $secretValues := dig $identifier nil $rootContext.Values.secrets -}} - {{- if not (empty $secretValues) -}} - {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $secretValues) -}} + {{- if (hasKey $enabledSecrets $identifier) -}} + {{- $objectValues := get $enabledSecrets $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledSecrets)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/secret/_validate.tpl b/charts/library/common/templates/lib/secret/_validate.tpl deleted file mode 100644 index 82603992..00000000 --- a/charts/library/common/templates/lib/secret/_validate.tpl +++ /dev/null @@ -1,7 +0,0 @@ -{{/* -Validate Secret values -*/}} -{{- define "bjw-s.common.lib.secret.validate" -}} - {{- $rootContext := .rootContext -}} - {{- $secretValues := .object -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/service/_enabled_services.tpl b/charts/library/common/templates/lib/service/_enabled_services.tpl index 74b4ea90..119711cf 100644 --- a/charts/library/common/templates/lib/service/_enabled_services.tpl +++ b/charts/library/common/templates/lib/service/_enabled_services.tpl @@ -14,6 +14,8 @@ Return the enabled services. {{- end -}} {{- if $serviceEnabled -}} + + {{- $_ := set $enabledServices $name . -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/service/_getByIdentifier.tpl b/charts/library/common/templates/lib/service/_getByIdentifier.tpl index c8335125..ce0dd7da 100644 --- a/charts/library/common/templates/lib/service/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/service/_getByIdentifier.tpl @@ -4,10 +4,19 @@ Return a service Object by its Identifier. {{- define "bjw-s.common.lib.service.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} + {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }} + {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}} - {{- range $name, $serviceValues := $rootContext.Values.service -}} - {{- if eq $name $identifier -}} - {{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceValues) -}} + {{- if (hasKey $enabledServices $identifier) -}} + {{- $objectValues := get $enabledServices $identifier -}} + {{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServices)) | fromYaml -}} + + {{- if eq 1 (len $enabledControllers) -}} + {{- if (empty (dig "controller" nil $object)) -}} + {{- $_ := set $object "controller" ($enabledControllers | keys | first) -}} + {{- end -}} {{- end -}} + + {{- $object | toYaml -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/service/_primaryForController.tpl b/charts/library/common/templates/lib/service/_primaryForController.tpl index 48a4586a..44f40f69 100644 --- a/charts/library/common/templates/lib/service/_primaryForController.tpl +++ b/charts/library/common/templates/lib/service/_primaryForController.tpl @@ -5,7 +5,7 @@ Return the primary service object for a controller {{- $rootContext := .rootContext -}} {{- $controllerIdentifier := .controllerIdentifier -}} - {{- $identifier := "" -}} + {{- $serviceIdentifier := "" -}} {{- $result := dict -}} {{- /* Loop over all enabled services */ -}} @@ -13,27 +13,29 @@ Return the primary service object for a controller {{- if $enabledServices -}} {{- /* We are only interested in services for the specified controller */ -}} {{- $enabledServicesForController := dict -}} - {{- range $name, $service := $enabledServices -}} - {{- if eq $service.controller $controllerIdentifier -}} - {{- $_ := set $enabledServicesForController $name $service -}} + {{- range $identifier, $serviceObject := $enabledServices -}} + {{- if eq $serviceObject.controller $controllerIdentifier -}} + {{- $_ := set $enabledServicesForController $identifier $serviceObject -}} {{- end -}} {{- end -}} - {{- range $name, $service := $enabledServicesForController -}} + {{- range $identifier, $serviceObject := $enabledServicesForController -}} {{- /* Determine the Service that has been marked as primary */ -}} - {{- if $service.primary -}} - {{- $identifier = $name -}} - {{- $result = $service -}} + {{- if $serviceObject.primary -}} + {{- $serviceIdentifier = $identifier -}} + {{- $result = $serviceObject -}} {{- end -}} {{- /* Return the first Service (alphabetically) if none has been explicitly marked as primary */ -}} {{- if not $result -}} {{- $firstServiceKey := keys $enabledServicesForController | sortAlpha | first -}} {{- $result = get $enabledServicesForController $firstServiceKey -}} - {{- $identifier = $result.identifier -}} + {{- $serviceIdentifier = $identifier -}} {{- end -}} {{- end -}} - {{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}} + {{- if not (empty $serviceIdentifier) -}} + {{- include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $serviceIdentifier) -}} + {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/service/_validate.tpl b/charts/library/common/templates/lib/service/_validate.tpl index 45fdbc4b..5763f3d6 100644 --- a/charts/library/common/templates/lib/service/_validate.tpl +++ b/charts/library/common/templates/lib/service/_validate.tpl @@ -5,6 +5,15 @@ Validate Service values {{- $rootContext := .rootContext -}} {{- $serviceObject := .object -}} + {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}} + + {{/* Verify automatic controller detection */}} + {{- if not (eq 1 (len $enabledControllers)) -}} + {{- if or (not (has "controller" (keys $serviceObject))) (empty (get $serviceObject "controller")) -}} + {{- fail (printf "controller field is required because automatic controller detection is not possible. (service: %s)" $serviceObject.identifier ) -}} + {{- end -}} + {{- end -}} + {{- if empty (get $serviceObject "controller") -}} {{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}} {{- end -}} @@ -29,13 +38,13 @@ Validate Service values {{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "rootContext" $rootContext "serviceObject" $serviceObject) | fromYaml }} {{- /* Validate at least one port is enabled */ -}} {{- if not $enabledPorts -}} - {{- fail (printf "no ports are enabled for Service with key \"%s\"" $serviceObject.identifier) -}} + {{- fail (printf "No ports are enabled for Service with this identifier. (service: '%s')" $serviceObject.identifier) -}} {{- end -}} {{- range $name, $port := $enabledPorts -}} {{- /* Validate a port number is configured */ -}} {{- if not $port.port -}} - {{- fail (printf "no port number is configured for port \"%s\" under Service with key \"%s\"" $name $serviceObject.identifier) -}} + {{- fail (printf "No port number is configured for this port. (port: '%s', service: '%s')" $name $serviceObject.identifier) -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/service/_valuesToObject.tpl b/charts/library/common/templates/lib/service/_valuesToObject.tpl deleted file mode 100644 index 85df0742..00000000 --- a/charts/library/common/templates/lib/service/_valuesToObject.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -Convert Service values to an object -*/}} -{{- define "bjw-s.common.lib.service.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the Service name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if and (not $objectValues.primary) (gt (len $enabledServices) 1) -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the Service object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/serviceAccount/_enabled_serviceaccounts.tpl b/charts/library/common/templates/lib/serviceAccount/_enabled_serviceaccounts.tpl new file mode 100644 index 00000000..b1b48998 --- /dev/null +++ b/charts/library/common/templates/lib/serviceAccount/_enabled_serviceaccounts.tpl @@ -0,0 +1,23 @@ +{{/* +Return the enabled serviceAccounts. +*/}} +{{- define "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" -}} + {{- $rootContext := .rootContext -}} + {{- $enabledServiceAccounts := dict -}} + + {{- range $identifier, $serviceAccount := $rootContext.Values.serviceAccount -}} + {{- if kindIs "map" $serviceAccount -}} + {{- /* Enable Service by default, but allow override */ -}} + {{- $serviceAccountEnabled := true -}} + {{- if hasKey $serviceAccount "enabled" -}} + {{- $serviceAccountEnabled = $serviceAccount.enabled -}} + {{- end -}} + + {{- if $serviceAccountEnabled -}} + {{- $_ := set $enabledServiceAccounts $identifier . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- $enabledServiceAccounts | toYaml -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/serviceAccount/_getByIdentifier.tpl b/charts/library/common/templates/lib/serviceAccount/_getByIdentifier.tpl index 3555390c..9769a4d1 100644 --- a/charts/library/common/templates/lib/serviceAccount/_getByIdentifier.tpl +++ b/charts/library/common/templates/lib/serviceAccount/_getByIdentifier.tpl @@ -4,18 +4,10 @@ Return a ServiceAccount Object by its Identifier. {{- define "bjw-s.common.lib.serviceAccount.getByIdentifier" -}} {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} - {{- if eq $identifier "default" -}} - {{- $serviceAccount := deepCopy $rootContext.Values.serviceAccount -}} - {{- if and (eq ($serviceAccount.name) "") (not $serviceAccount.create ) -}} - {{- $_ := set $serviceAccount "name" "default" -}} - {{- end -}} - {{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccount) -}} - {{- else -}} - {{- $serviceAccountValues := dig "extraServiceAccounts" $identifier nil $rootContext.Values.serviceAccount -}} - {{- if not (empty $serviceAccountValues) -}} - {{- include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceAccountValues) -}} - {{- else -}} - {{- fail (printf "No ServiceAccount configured with identifier: %s" $identifier) -}} - {{- end -}} + {{- $enabledServiceAccounts := (include "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledServiceAccounts $identifier) -}} + {{- $objectValues := get $enabledServiceAccounts $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServiceAccounts)) -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/serviceAccount/_valuesToObject.tpl b/charts/library/common/templates/lib/serviceAccount/_valuesToObject.tpl deleted file mode 100644 index 435a66b4..00000000 --- a/charts/library/common/templates/lib/serviceAccount/_valuesToObject.tpl +++ /dev/null @@ -1,25 +0,0 @@ -{{/* -Convert ServiceAccount values to an object -*/}} -{{- define "bjw-s.common.lib.serviceAccount.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the serviceAccount name */ -}} - {{- $defaultServiceAccountName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- $objectName := $defaultServiceAccountName -}} - - {{- with $objectValues.name -}} - {{- $objectName = . -}} - {{- end -}} - {{- if and (ne $identifier "default") (not $objectValues.name) -}} - {{- $objectName = printf "%s-%s" $defaultServiceAccountName $identifier -}} - {{- end -}} - - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - {{- /* Return the serviceAccount object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/serviceMonitor/_enabled_servicemonitors.tpl b/charts/library/common/templates/lib/serviceMonitor/_enabled_servicemonitors.tpl index 9617e84b..4bf7609b 100644 --- a/charts/library/common/templates/lib/serviceMonitor/_enabled_servicemonitors.tpl +++ b/charts/library/common/templates/lib/serviceMonitor/_enabled_servicemonitors.tpl @@ -1,20 +1,20 @@ {{/* -Return the enabled ServiceMonitors. +Return the enabled serviceMonitors. */}} {{- define "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" -}} {{- $rootContext := .rootContext -}} {{- $enabledServiceMonitors := dict -}} - {{- range $name, $serviceMonitor := $rootContext.Values.serviceMonitor -}} + {{- range $identifier, $serviceMonitor := $rootContext.Values.serviceMonitor -}} {{- if kindIs "map" $serviceMonitor -}} - {{- /* Enable by default, but allow override */ -}} + {{- /* Enable Service by default, but allow override */ -}} {{- $serviceMonitorEnabled := true -}} {{- if hasKey $serviceMonitor "enabled" -}} {{- $serviceMonitorEnabled = $serviceMonitor.enabled -}} {{- end -}} {{- if $serviceMonitorEnabled -}} - {{- $_ := set $enabledServiceMonitors $name . -}} + {{- $_ := set $enabledServiceMonitors $identifier . -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/serviceMonitor/_getByIdentifier.tpl b/charts/library/common/templates/lib/serviceMonitor/_getByIdentifier.tpl new file mode 100644 index 00000000..1b2b8506 --- /dev/null +++ b/charts/library/common/templates/lib/serviceMonitor/_getByIdentifier.tpl @@ -0,0 +1,13 @@ +{{/* +Return a ServiceMonitor Object by its Identifier. +*/}} +{{- define "bjw-s.common.lib.serviceMonitor.getByIdentifier" -}} + {{- $rootContext := .rootContext -}} + {{- $identifier := .id -}} + {{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) }} + + {{- if (hasKey $enabledServiceMonitors $identifier) -}} + {{- $objectValues := get $enabledServiceMonitors $identifier -}} + {{- include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServiceMonitors)) -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl b/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl deleted file mode 100644 index f1d6b364..00000000 --- a/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl +++ /dev/null @@ -1,30 +0,0 @@ -{{/* -Convert ServiceMonitor values to an object -*/}} -{{- define "bjw-s.common.lib.serviceMonitor.valuesToObject" -}} - {{- $rootContext := .rootContext -}} - {{- $identifier := .id -}} - {{- $objectValues := .values -}} - - {{- /* Determine and inject the ServiceMonitor name */ -}} - {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} - - {{- if $objectValues.nameOverride -}} - {{- $override := tpl $objectValues.nameOverride $rootContext -}} - {{- if not (eq $objectName $override) -}} - {{- $objectName = printf "%s-%s" $objectName $override -}} - {{- end -}} - {{- else -}} - {{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) }} - {{- if gt (len $enabledServiceMonitors) 1 -}} - {{- if not (eq $objectName $identifier) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{- $_ := set $objectValues "name" $objectName -}} - {{- $_ := set $objectValues "identifier" $identifier -}} - - {{- /* Return the ServiceMonitor object */ -}} - {{- $objectValues | toYaml -}} -{{- end -}} diff --git a/charts/library/common/templates/lib/statefulset/_valuesToObject.tpl b/charts/library/common/templates/lib/statefulset/_valuesToObject.tpl index 687f4ed8..5fd323d5 100644 --- a/charts/library/common/templates/lib/statefulset/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/statefulset/_valuesToObject.tpl @@ -5,10 +5,15 @@ Convert StatefulSet values to an object {{- $rootContext := .rootContext -}} {{- $identifier := .id -}} {{- $objectValues := .values -}} + {{- $itemCount := .itemCount -}} + + {{- $objectName := (include "bjw-s.common.lib.determineResourceNameFromValues" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" $itemCount)) -}} + + {{- $_ := set $objectValues "name" $objectName -}} + {{- $_ := set $objectValues "identifier" $identifier -}} {{- $strategy := default "RollingUpdate" $objectValues.strategy -}} {{- $_ := set $objectValues "strategy" $strategy -}} - {{- /* Return the StatefulSet object */ -}} {{- $objectValues | toYaml -}} {{- end -}} diff --git a/charts/library/common/templates/loader/_generate.tpl b/charts/library/common/templates/loader/_generate.tpl index 571b6c67..40656661 100644 --- a/charts/library/common/templates/loader/_generate.tpl +++ b/charts/library/common/templates/loader/_generate.tpl @@ -2,21 +2,23 @@ Secondary entrypoint and primary loader for the common chart */}} {{- define "bjw-s.common.loader.generate" -}} + {{- $rootContext := $ -}} + {{- /* Run global chart validations */ -}} - {{- include "bjw-s.common.lib.chart.validate" . -}} + {{- include "bjw-s.common.lib.chart.validate" $rootContext -}} {{- /* Build the templates */ -}} - {{- include "bjw-s.common.render.pvcs" . | nindent 0 -}} - {{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}} - {{- include "bjw-s.common.render.configMaps.fromFolder" . | nindent 0 -}} - {{- include "bjw-s.common.render.configMaps" . | nindent 0 -}} - {{- include "bjw-s.common.render.controllers" . | nindent 0 -}} - {{- include "bjw-s.common.render.services" . | nindent 0 -}} - {{- include "bjw-s.common.render.ingresses" . | nindent 0 -}} - {{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}} - {{- include "bjw-s.common.render.routes" . | nindent 0 -}} - {{- include "bjw-s.common.render.secrets" . | nindent 0 -}} - {{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}} - {{- include "bjw-s.common.render.rawResources" . | nindent 0 -}} - {{- include "bjw-s.common.render.rbac" . | nindent 0 -}} + {{- include "bjw-s.common.render.pvcs" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.serviceAccount" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.configMaps.fromFolder" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.configMaps" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.controllers" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.services" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.ingresses" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.serviceMonitors" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.routes" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.secrets" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.networkpolicies" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.rawResources" $rootContext | nindent 0 -}} + {{- include "bjw-s.common.render.rbac" $rootContext | nindent 0 -}} {{- end -}} diff --git a/charts/library/common/templates/render/_configmaps.tpl b/charts/library/common/templates/render/_configmaps.tpl index 1edd7537..050ff560 100644 --- a/charts/library/common/templates/render/_configmaps.tpl +++ b/charts/library/common/templates/render/_configmaps.tpl @@ -4,25 +4,18 @@ Renders the configMap objects required by the chart. {{- define "bjw-s.common.render.configMaps" -}} {{- $rootContext := $ -}} - {{- /* Generate named configMaps as required */ -}} - {{- range $key, $configMap := .Values.configMaps }} - {{- /* Enable configMap by default, but allow override */ -}} - {{- $configMapEnabled := true -}} - {{- if hasKey $configMap "enabled" -}} - {{- $configMapEnabled = $configMap.enabled -}} - {{- end -}} + {{- /* Generate configMaps as required */ -}} + {{- $enabledConfigMaps := (include "bjw-s.common.lib.configMap.enabledConfigmaps" (dict "rootContext" $rootContext) | fromYaml ) -}} - {{- if $configMapEnabled -}} - {{- $configMapValues := (mustDeepCopy $configMap) -}} + {{- range $identifier := keys $enabledConfigMaps -}} + {{- /* Generate object from the raw configMap values */ -}} + {{- $configMapObject := (include "bjw-s.common.lib.configMap.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- /* Create object from the raw configMap values */ -}} - {{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $configMapValues)) | fromYaml -}} - {{- /* Perform validations on the configMap before rendering */ -}} - {{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $ "object" $configMapObject "id" $key) -}} + {{- /* Perform validations on the configMap before rendering */ -}} + {{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $rootContext "object" $configMapObject "id" $identifier) -}} {{/* Include the configMap class */}} - {{- include "bjw-s.common.class.configMap" (dict "rootContext" $ "object" $configMapObject) | nindent 0 -}} - {{- end -}} + {{- include "bjw-s.common.class.configMap" (dict "rootContext" $rootContext "object" $configMapObject) | nindent 0 -}} {{- end -}} {{- end -}} @@ -30,23 +23,26 @@ Renders the configMap objects required by the chart. Renders configMap objects required by the chart from a folder in the repo's path. */}} {{- define "bjw-s.common.render.configMaps.fromFolder" -}} + {{- $rootContext := $ -}} - {{- $valuesCopy := .Values -}} - {{- $configMapsFromFolder := .Values.configMapsFromFolder | default dict -}} + {{- $valuesCopy := $rootContext.Values -}} + {{- $configMapsFromFolder := $rootContext.Values.configMapsFromFolder | default dict -}} {{- $configMapsFromFolderEnabled := dig "enabled" false $configMapsFromFolder -}} {{- if $configMapsFromFolderEnabled -}} {{- /* Perform validations before rendering */ -}} {{- include "bjw-s.common.lib.configMap.fromFolder.validate" (dict "rootContext" $ "basePath" $configMapsFromFolder.basePath) -}} - {{- $basePath := $configMapsFromFolder.basePath -}} + {{/* Generate a list of unique top level folders */}} - {{ $topLevelFolders := dict}} + {{- $basePath := $configMapsFromFolder.basePath -}} + {{- $topLevelFolders := dict -}} {{- range $path, $_ := .Files.Glob (printf "%s/*/*" $basePath) -}} {{- $_ := set $topLevelFolders (dir $path) "" -}} {{- end -}} {{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}} - {{/* Iterate over the top level folders */}} - {{ range $path := $top_level_folder_list }} + + {{- /* Iterate over the top level folders */ -}} + {{- range $path := $top_level_folder_list -}} {{- $folder := base $path -}} {{- $configMapData := dict -}} {{- $configMapBinaryData := dict -}} @@ -70,16 +66,16 @@ Renders configMap objects required by the chart from a folder in the repo's path {{- $configMapData = merge $configMapData (dict $file $fileContent) -}} {{- end -}} {{- end -}} - - {{ end }} + {{- end -}} {{- $configMapValues := dict "enabled" true "forceRename" $configMapForceRename "labels" $configMapLabels "annotations" $configMapAnnotations "data" $configMapData "binaryData" $configMapBinaryData -}} - {{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $ "id" $folder "values" $configMapValues)) | fromYaml -}} - {{/* Append it to .Values.configMaps so it can be created by "bjw-s.common.render.configMaps" and fetched by identifier */}} - {{- $existingConfigMaps := (get $valuesCopy "configMaps"| default dict) -}} - {{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}} - {{- $valuesCopy := merge $valuesCopy (dict "configMaps" $mergedConfigMaps) -}} - {{ end }} - {{ end }} + {{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $folder "values" $configMapValues) | fromYaml) -}} -{{ end }} + {{- /* Append it to .Values.configMaps so it can be created by "bjw-s.common.render.configMaps" and fetched by identifier */ -}} + {{- $existingConfigMaps := (get $valuesCopy "configMaps" | default dict) -}} + {{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict $folder $configMapObject) -}} + + {{- $valuesCopy := merge $valuesCopy (dict "configMaps" $mergedConfigMaps) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/library/common/templates/render/_controllers.tpl b/charts/library/common/templates/render/_controllers.tpl index 4a294716..25d38a12 100644 --- a/charts/library/common/templates/render/_controllers.tpl +++ b/charts/library/common/templates/render/_controllers.tpl @@ -5,43 +5,38 @@ Renders the controller objects required by the chart. {{- $rootContext := $ -}} {{- /* Generate named controller objects as required */ -}} - {{- range $key, $controller := .Values.controllers -}} - {{- /* Enable controller by default, but allow override */ -}} - {{- $controllerEnabled := true -}} - {{- if hasKey $controller "enabled" -}} - {{- $controllerEnabled = $controller.enabled -}} - {{- end -}} + {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledControllers -}} + {{- /* Create object from the raw controller values */ -}} + {{- $controllerObject := (include "bjw-s.common.lib.controller.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if $controllerEnabled -}} - {{- $controllerValues := $controller -}} + {{- /* Perform validations on the controller before rendering */ -}} + {{- include "bjw-s.common.lib.controller.validate" (dict "rootContext" $rootContext "object" $controllerObject) -}} - {{- /* Create object from the raw controller values */ -}} - {{- $controllerObject := (include "bjw-s.common.lib.controller.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerValues)) | fromYaml -}} + {{- if eq $controllerObject.type "deployment" -}} + {{- $deploymentObject := (include "bjw-s.common.lib.deployment.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}} + {{- include "bjw-s.common.lib.deployment.validate" (dict "rootContext" $rootContext "object" $deploymentObject) -}} + {{- include "bjw-s.common.class.deployment" (dict "rootContext" $rootContext "object" $deploymentObject) | nindent 0 -}} - {{- /* Perform validations on the controller before rendering */ -}} - {{- include "bjw-s.common.lib.controller.validate" (dict "rootContext" $rootContext "object" $controllerObject) -}} + {{- else if eq $controllerObject.type "cronjob" -}} + {{- $cronjobObject := (include "bjw-s.common.lib.cronjob.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}} + {{- include "bjw-s.common.lib.cronjob.validate" (dict "rootContext" $rootContext "object" $cronjobObject) -}} + {{- include "bjw-s.common.class.cronjob" (dict "rootContext" $rootContext "object" $cronjobObject) | nindent 0 -}} - {{- if eq $controllerObject.type "deployment" -}} - {{- $deploymentObject := (include "bjw-s.common.lib.deployment.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}} - {{- include "bjw-s.common.lib.deployment.validate" (dict "rootContext" $rootContext "object" $deploymentObject) -}} - {{- include "bjw-s.common.class.deployment" (dict "rootContext" $rootContext "object" $deploymentObject) | nindent 0 -}} - {{- else if eq $controllerObject.type "cronjob" -}} - {{- $cronjobObject := (include "bjw-s.common.lib.cronjob.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}} - {{- include "bjw-s.common.lib.cronjob.validate" (dict "rootContext" $rootContext "object" $cronjobObject) -}} - {{- include "bjw-s.common.class.cronjob" (dict "rootContext" $rootContext "object" $cronjobObject) | nindent 0 -}} - {{- else if eq $controllerObject.type "daemonset" -}} - {{- $daemonsetObject := (include "bjw-s.common.lib.daemonset.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}} - {{- include "bjw-s.common.lib.daemonset.validate" (dict "rootContext" $rootContext "object" $daemonsetObject) -}} - {{- include "bjw-s.common.class.daemonset" (dict "rootContext" $rootContext "object" $daemonsetObject) | nindent 0 -}} - {{- else if eq $controllerObject.type "statefulset" -}} - {{- $statefulsetObject := (include "bjw-s.common.lib.statefulset.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}} - {{- include "bjw-s.common.lib.statefulset.validate" (dict "rootContext" $rootContext "object" $statefulsetObject) -}} - {{- include "bjw-s.common.class.statefulset" (dict "rootContext" $rootContext "object" $statefulsetObject) | nindent 0 -}} - {{- else if eq $controllerObject.type "job" -}} - {{- $jobObject := (include "bjw-s.common.lib.job.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $controllerObject)) | fromYaml -}} - {{- include "bjw-s.common.lib.job.validate" (dict "rootContext" $rootContext "object" $jobObject) -}} - {{- include "bjw-s.common.class.job" (dict "rootContext" $rootContext "object" $jobObject) | nindent 0 -}} - {{- end -}} + {{- else if eq $controllerObject.type "daemonset" -}} + {{- $daemonsetObject := (include "bjw-s.common.lib.daemonset.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}} + {{- include "bjw-s.common.lib.daemonset.validate" (dict "rootContext" $rootContext "object" $daemonsetObject) -}} + {{- include "bjw-s.common.class.daemonset" (dict "rootContext" $rootContext "object" $daemonsetObject) | nindent 0 -}} + + {{- else if eq $controllerObject.type "statefulset" -}} + {{- $statefulsetObject := (include "bjw-s.common.lib.statefulset.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}} + {{- include "bjw-s.common.lib.statefulset.validate" (dict "rootContext" $rootContext "object" $statefulsetObject) -}} + {{- include "bjw-s.common.class.statefulset" (dict "rootContext" $rootContext "object" $statefulsetObject) | nindent 0 -}} + + {{- else if eq $controllerObject.type "job" -}} + {{- $jobObject := (include "bjw-s.common.lib.job.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerObject "itemCount" (len $enabledControllers))) | fromYaml -}} + {{- include "bjw-s.common.lib.job.validate" (dict "rootContext" $rootContext "object" $jobObject) -}} + {{- include "bjw-s.common.class.job" (dict "rootContext" $rootContext "object" $jobObject) | nindent 0 -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_ingresses.tpl b/charts/library/common/templates/render/_ingresses.tpl index c0cbc24a..ad4cedf4 100644 --- a/charts/library/common/templates/render/_ingresses.tpl +++ b/charts/library/common/templates/render/_ingresses.tpl @@ -2,25 +2,18 @@ Renders the Ingress objects required by the chart. */}} {{- define "bjw-s.common.render.ingresses" -}} - {{- /* Generate named Ingresses as required */ -}} - {{- range $key, $ingress := .Values.ingress }} - {{- /* Enable Ingress by default, but allow override */ -}} - {{- $ingressEnabled := true -}} - {{- if hasKey $ingress "enabled" -}} - {{- $ingressEnabled = $ingress.enabled -}} - {{- end -}} + {{- $rootContext := $ -}} - {{- if $ingressEnabled -}} - {{- $ingressValues := (mustDeepCopy $ingress) -}} + {{- /* Generate Ingresses as required */ -}} + {{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledIngresses -}} + {{- /* Generate object from the raw persistence values */ -}} + {{- $ingressObject := (include "bjw-s.common.lib.ingress.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- /* Create object from the raw ingress values */ -}} - {{- $ingressObject := (include "bjw-s.common.lib.ingress.valuesToObject" (dict "rootContext" $ "id" $key "values" $ingressValues)) | fromYaml -}} + {{- /* Perform validations on the Ingress before rendering */ -}} + {{- include "bjw-s.common.lib.ingress.validate" (dict "rootContext" $rootContext "object" $ingressObject) -}} - {{- /* Perform validations on the ingress before rendering */ -}} - {{- include "bjw-s.common.lib.ingress.validate" (dict "rootContext" $ "object" $ingressObject) -}} - - {{/* Include the ingress class */}} - {{- include "bjw-s.common.class.ingress" (dict "rootContext" $ "object" $ingressObject) | nindent 0 -}} - {{- end -}} + {{- /* Include the ingress class */ -}} + {{- include "bjw-s.common.class.ingress" (dict "rootContext" $ "object" $ingressObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_networkpolicies.tpl b/charts/library/common/templates/render/_networkpolicies.tpl index d35a591b..2082d19b 100644 --- a/charts/library/common/templates/render/_networkpolicies.tpl +++ b/charts/library/common/templates/render/_networkpolicies.tpl @@ -2,25 +2,18 @@ Renders the networkPolicy objects required by the chart. */}} {{- define "bjw-s.common.render.networkpolicies" -}} - {{- /* Generate named networkPolicy as required */ -}} - {{- range $key, $networkPolicy := .Values.networkpolicies }} - {{- /* Enable networkPolicy by default, but allow override */ -}} - {{- $networkPolicyEnabled := true -}} - {{- if hasKey $networkPolicy "enabled" -}} - {{- $networkPolicyEnabled = $networkPolicy.enabled -}} - {{- end -}} + {{- $rootContext := $ -}} - {{- if $networkPolicyEnabled -}} - {{- $networkPolicyValues := (mustDeepCopy $networkPolicy) -}} + {{- /* Generate networkPolicy as required */ -}} + {{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkpolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledNetworkPolicies -}} + {{- /* Generate object from the raw persistence values */ -}} + {{- $networkPolicyObject := (include "bjw-s.common.lib.networkpolicy.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- /* Create object from the raw networkPolicy values */ -}} - {{- $networkPolicyObject := (include "bjw-s.common.lib.networkpolicy.valuesToObject" (dict "rootContext" $ "id" $key "values" $networkPolicyValues)) | fromYaml -}} + {{- /* Perform validations on the networkPolicy before rendering */ -}} + {{- include "bjw-s.common.lib.networkpolicy.validate" (dict "rootContext" $ "object" $networkPolicyObject) -}} - {{- /* Perform validations on the networkPolicy before rendering */ -}} - {{- include "bjw-s.common.lib.networkpolicy.validate" (dict "rootContext" $ "object" $networkPolicyObject) -}} - - {{/* Include the networkPolicy class */}} - {{- include "bjw-s.common.class.networkpolicy" (dict "rootContext" $ "object" $networkPolicyObject) | nindent 0 -}} - {{- end -}} + {{- /* Include the networkPolicy class */ -}} + {{- include "bjw-s.common.class.networkpolicy" (dict "rootContext" $ "object" $networkPolicyObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_pvcs.tpl b/charts/library/common/templates/render/_pvcs.tpl index 98d7df5e..2e965dd3 100644 --- a/charts/library/common/templates/render/_pvcs.tpl +++ b/charts/library/common/templates/render/_pvcs.tpl @@ -1,26 +1,16 @@ {{/* -Renders the Persistent Volume Claim objects required by the chart. +Renders the Persistent Volume Claim objects required by the chart */}} {{- define "bjw-s.common.render.pvcs" -}} + {{- $rootContext := $ -}} + {{- /* Generate pvc as required */ -}} - {{- range $key, $pvc := .Values.persistence -}} - {{- /* Enable PVC by default, but allow override */ -}} - {{- $pvcEnabled := true -}} - {{- if hasKey $pvc "enabled" -}} - {{- $pvcEnabled = $pvc.enabled -}} - {{- end -}} + {{- $enabledPVCs := (include "bjw-s.common.lib.pvc.enabledPVCs" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledPVCs -}} + {{- /* Generate object from the raw persistence values */ -}} + {{- $pvcObject := (include "bjw-s.common.lib.pvc.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if and $pvcEnabled (eq (default "persistentVolumeClaim" $pvc.type) "persistentVolumeClaim") (not $pvc.existingClaim) -}} - {{- $pvcValues := (mustDeepCopy $pvc) -}} - - {{- /* Create object from the raw PVC values */ -}} - {{- $pvcObject := (include "bjw-s.common.lib.pvc.valuesToObject" (dict "rootContext" $ "id" $key "values" $pvcValues)) | fromYaml -}} - - {{- /* Perform validations on the PVC before rendering */ -}} - {{- include "bjw-s.common.lib.pvc.validate" (dict "rootContext" $ "object" $pvcValues) -}} - - {{- /* Include the PVC class */ -}} - {{- include "bjw-s.common.class.pvc" (dict "rootContext" $ "object" $pvcValues) | nindent 0 -}} - {{- end -}} + {{- /* Include the PVC class */ -}} + {{- include "bjw-s.common.class.pvc" (dict "rootContext" $rootContext "object" $pvcObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_rawResources.tpl b/charts/library/common/templates/render/_rawResources.tpl index 7137bc1c..920df340 100644 --- a/charts/library/common/templates/render/_rawResources.tpl +++ b/charts/library/common/templates/render/_rawResources.tpl @@ -5,24 +5,12 @@ Renders other arbirtrary objects required by the chart. {{- $rootContext := $ -}} {{- /* Generate raw resources as required */ -}} - {{- range $key, $resource := .Values.rawResources -}} - {{- /* Enable by default, but allow override */ -}} - {{- $resourceEnabled := true -}} - {{- if hasKey $resource "enabled" -}} - {{- $resourceEnabled = $resource.enabled -}} - {{- end -}} + {{- $enabledRawResources := (include "bjw-s.common.lib.rawResource.enabledRawResources" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledRawResources -}} + {{- /* Generate object from the raw resource values */ -}} + {{- $rawResourceObject := (include "bjw-s.common.lib.rawResource.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if $resourceEnabled -}} - {{- $resourceValues := (mustDeepCopy $resource) -}} - - {{- /* Create object from the raw resource values */ -}} - {{- $resourceObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $resourceValues)) | fromYaml -}} - - {{- /* Perform validations on the resource before rendering */ -}} - {{- include "bjw-s.common.lib.rawResource.validate" (dict "rootContext" $ "object" $resourceValues) -}} - - {{- /* Include the raw resource class */ -}} - {{- include "bjw-s.common.class.rawResource" (dict "rootContext" $ "object" $resourceValues) | nindent 0 -}} - {{- end -}} + {{- /* Include the raw resource class */ -}} + {{- include "bjw-s.common.class.rawResource" (dict "rootContext" $rootContext "object" $rawResourceObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_rbac.tpl b/charts/library/common/templates/render/_rbac.tpl index b4cfdb38..2d701f48 100644 --- a/charts/library/common/templates/render/_rbac.tpl +++ b/charts/library/common/templates/render/_rbac.tpl @@ -4,9 +4,7 @@ Renders RBAC objects required by the chart. {{- define "bjw-s.common.render.rbac" -}} {{- $rootContext := . -}} {{- include "bjw-s.common.render.rbac.roles" (dict "rootContext" $rootContext) -}} - {{- include "bjw-s.common.render.rbac.roleBindings" (dict "rootContext" $rootContext) -}} - {{ end }} {{/* @@ -14,27 +12,16 @@ Renders RBAC Role objects required by the chart. */}} {{- define "bjw-s.common.render.rbac.roles" -}} {{- $rootContext := .rootContext -}} - {{- /* Generate named Roles as required */ -}} - {{- range $key, $role := $rootContext.Values.rbac.roles }} - {{- /* Enable role by default, but allow override */ -}} - {{- $roleEnabled := true -}} - {{- if hasKey $role "enabled" -}} - {{- $roleEnabled = $role.enabled -}} - {{- end -}} + {{- $enabledRoles := (include "bjw-s.common.lib.rbac.role.enabledRoles" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledRoles -}} + {{- /* Generate object from the raw role values */ -}} + {{- $roleObject := (include "bjw-s.common.lib.rbac.role.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if $roleEnabled -}} - {{- $roleValues := (mustDeepCopy $role) -}} + {{- /* Perform validations on the role before rendering */ -}} + {{- include "bjw-s.common.lib.rbac.role.validate" (dict "rootContext" $rootContext "object" $roleObject) -}} - {{- /* Create object from the raw role values */ -}} - {{- $roleObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $roleValues)) | fromYaml -}} - - {{- /* Perform validations on the role before rendering */ -}} - {{- include "bjw-s.common.lib.rbac.role.validate" (dict "rootContext" $rootContext "object" $roleObject) -}} - - {{/* Include the role class */}} - {{- include "bjw-s.common.class.rbac.Role" (dict "rootContext" $rootContext "object" $roleObject) | nindent 0 -}} - - {{- end -}} + {{/* Include the role class */}} + {{- include "bjw-s.common.class.rbac.Role" (dict "rootContext" $rootContext "object" $roleObject) | nindent 0 -}} {{- end -}} {{- end -}} @@ -43,25 +30,12 @@ Renders RBAC RoleBinding objects required by the chart. */}} {{- define "bjw-s.common.render.rbac.roleBindings" -}} {{- $rootContext := .rootContext -}} - {{- range $key, $roleBinding := $rootContext.Values.rbac.bindings }} - {{- /* Enable RoleBinding by default, but allow override */ -}} - {{- $roleBindingEnabled := true -}} - {{- if hasKey $roleBinding "enabled" -}} - {{- $roleBindingEnabled = $roleBinding.enabled -}} - {{- end -}} + {{- $enabledRoleBindings := (include "bjw-s.common.lib.rbac.roleBinding.enabledRoleBindings" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledRoleBindings -}} + {{- /* Generate object from the raw role values */ -}} + {{- $roleBindingObject := (include "bjw-s.common.lib.rbac.roleBinding.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if $roleBindingEnabled -}} - {{- $roleBindingValues := (mustDeepCopy $roleBinding) -}} - - {{- /* Create object from the raw RoleBinding values */ -}} - {{- $roleBindingObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $roleBindingValues)) | fromYaml -}} - - {{- /* Perform validations on the RoleBinding before rendering */ -}} - {{- include "bjw-s.common.lib.rbac.roleBinding.validate" (dict "rootContext" $rootContext "object" $roleBindingObject) -}} - - {{/* Include the RoleBinding class */}} - {{- include "bjw-s.common.class.rbac.roleBinding" (dict "rootContext" $rootContext "object" $roleBindingObject) | nindent 0 -}} - - {{- end -}} + {{/* Include the RoleBinding class */}} + {{- include "bjw-s.common.class.rbac.roleBinding" (dict "rootContext" $rootContext "object" $roleBindingObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_routes.tpl b/charts/library/common/templates/render/_routes.tpl index ae3e709c..4336ecf4 100644 --- a/charts/library/common/templates/render/_routes.tpl +++ b/charts/library/common/templates/render/_routes.tpl @@ -2,18 +2,18 @@ Renders the Route objects required by the chart */}} {{- define "bjw-s.common.render.routes" -}} - {{- /* Generate named routes as required */ -}} - {{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $) | fromYaml ) -}} - {{- range $key, $route := $enabledRoutes -}} - {{- $routeValues := (mustDeepCopy $route) -}} + {{- $rootContext := $ -}} - {{- /* Create object from the raw Route values */ -}} - {{- $routeObject := (include "bjw-s.common.lib.route.valuesToObject" (dict "rootContext" $ "id" $key "values" $routeValues)) | fromYaml -}} + {{- /* Generate named routes as required */ -}} + {{- $enabledRoutes := (include "bjw-s.common.lib.route.enabledRoutes" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledRoutes -}} + {{- /* Generate object from the raw route values */ -}} + {{- $routeObject := (include "bjw-s.common.lib.route.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} {{- /* Perform validations on the Route before rendering */ -}} - {{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $ "object" $routeObject) -}} + {{- include "bjw-s.common.lib.route.validate" (dict "rootContext" $rootContext "object" $routeObject) -}} {{- /* Include the Route class */ -}} - {{- include "bjw-s.common.class.route" (dict "rootContext" $ "object" $routeObject) | nindent 0 -}} + {{- include "bjw-s.common.class.route" (dict "rootContext" $rootContext "object" $routeObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_secrets.tpl b/charts/library/common/templates/render/_secrets.tpl index 63e79f21..b3889ed1 100644 --- a/charts/library/common/templates/render/_secrets.tpl +++ b/charts/library/common/templates/render/_secrets.tpl @@ -5,24 +5,13 @@ Renders the Secret objects required by the chart. {{- $rootContext := $ -}} {{- /* Generate named Secrets as required */ -}} - {{- range $key, $secret := .Values.secrets }} - {{- /* Enable Secret by default, but allow override */ -}} - {{- $secretEnabled := true -}} - {{- if hasKey $secret "enabled" -}} - {{- $secretEnabled = $secret.enabled -}} - {{- end -}} + {{- $enabledSecrets := (include "bjw-s.common.lib.secret.enabledSecrets" (dict "rootContext" $rootContext) | fromYaml ) -}} - {{- if $secretEnabled -}} - {{- $secretValues := (mustDeepCopy $secret) -}} + {{- range $identifier := keys $enabledSecrets -}} + {{- /* Generate object from the raw secret values */ -}} + {{- $secretObject := (include "bjw-s.common.lib.secret.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- /* Create object from the raw Secret values */ -}} - {{- $secretObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $secretValues)) | fromYaml -}} - - {{- /* Perform validations on the Secret before rendering */ -}} - {{- include "bjw-s.common.lib.secret.validate" (dict "rootContext" $ "object" $secretObject) -}} - - {{/* Include the Secret class */}} - {{- include "bjw-s.common.class.secret" (dict "rootContext" $ "object" $secretObject) | nindent 0 -}} - {{- end -}} + {{- /* Include the Secret class */ -}} + {{- include "bjw-s.common.class.secret" (dict "rootContext" $rootContext "object" $secretObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_serviceMonitors.tpl b/charts/library/common/templates/render/_serviceMonitors.tpl index ab8c1ff2..062331ea 100644 --- a/charts/library/common/templates/render/_serviceMonitors.tpl +++ b/charts/library/common/templates/render/_serviceMonitors.tpl @@ -1,26 +1,19 @@ {{/* -Renders the serviceMonitor objects required by the chart. +Renders the serviceMonitor object required by the chart. */}} {{- define "bjw-s.common.render.serviceMonitors" -}} + {{- $rootContext := $ -}} + {{- /* Generate named serviceMonitors as required */ -}} - {{- range $key, $serviceMonitor := .Values.serviceMonitor -}} - {{- /* Enable ServiceMonitor by default, but allow override */ -}} - {{- $serviceMonitorEnabled := true -}} - {{- if hasKey $serviceMonitor "enabled" -}} - {{- $serviceMonitorEnabled = $serviceMonitor.enabled -}} - {{- end -}} + {{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledServiceMonitors -}} + {{- /* Generate object from the raw serviceMonitor values */ -}} + {{- $serviceMonitorObject := (include "bjw-s.common.lib.serviceMonitor.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} - {{- if $serviceMonitorEnabled -}} - {{- $serviceMonitorValues := (mustDeepCopy $serviceMonitor) -}} + {{- /* Perform validations on the ServiceMonitor before rendering */ -}} + {{- include "bjw-s.common.lib.serviceMonitor.validate" (dict "rootContext" $rootContext "object" $serviceMonitorObject) -}} - {{- /* Create object from the raw ServiceMonitor values */ -}} - {{- $serviceMonitorObject := (include "bjw-s.common.lib.serviceMonitor.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceMonitorValues)) | fromYaml -}} - - {{- /* Perform validations on the serviceMonitor before rendering */ -}} - {{- include "bjw-s.common.lib.serviceMonitor.validate" (dict "rootContext" $ "object" $serviceMonitorObject) -}} - - {{/* Include the serviceMonitor class */}} - {{- include "bjw-s.common.class.serviceMonitor" (dict "rootContext" $ "object" $serviceMonitorObject) | nindent 0 -}} - {{- end -}} + {{- /* Include the ServiceMonitor class */ -}} + {{- include "bjw-s.common.class.serviceMonitor" (dict "rootContext" $rootContext "object" $serviceMonitorObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_serviceaccount.tpl b/charts/library/common/templates/render/_serviceaccount.tpl index a60e85fd..f3a42953 100644 --- a/charts/library/common/templates/render/_serviceaccount.tpl +++ b/charts/library/common/templates/render/_serviceaccount.tpl @@ -2,48 +2,23 @@ Renders the serviceAccount object required by the chart. */}} {{- define "bjw-s.common.render.serviceAccount" -}} - {{- if .Values.serviceAccount.create -}} - {{- $serviceAccountValues := (mustDeepCopy .Values.serviceAccount) -}} + {{- $rootContext := $ -}} - {{- /* Create object from the raw ServiceAccount values */ -}} - {{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $ "id" "default" "values" $serviceAccountValues)) | fromYaml -}} + {{- /* Generate named serviceAccounts as required */ -}} + {{- $enabledServiceAccounts := (include "bjw-s.common.lib.serviceAccount.enabledServiceAccounts" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledServiceAccounts -}} + {{- /* Generate object from the raw serviceAccount values */ -}} + {{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} {{- /* Perform validations on the ServiceAccount before rendering */ -}} - {{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $ "object" $serviceAccountObject) -}} + {{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $rootContext "object" $serviceAccountObject) -}} {{- /* Create a service account secret */ -}} - {{- $_ := set .Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "enabled" true "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}} - - {{/* Include the serviceAccount class */}} - {{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $ "object" $serviceAccountObject) | nindent 0 -}} - - {{- end -}} - - {{- /* Generate named serviceAccount objects as required */ -}} - {{- with .Values.serviceAccount.extraServiceAccounts -}} - {{- range $key, $serviceAccount := . -}} - {{- $serviceAccountEnabled := true -}} - {{- if hasKey $serviceAccount "create" -}} - {{- $serviceAccountEnabled = $serviceAccount.create -}} - {{- end -}} - - {{- if $serviceAccountEnabled -}} - {{- $serviceAccountValues := $serviceAccount -}} - - {{- /* Create object from the raw ServiceAccount values */ -}} - {{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceAccountValues)) | fromYaml -}} - - {{- /* Perform validations on the ServiceAccount before rendering */ -}} - {{- include "bjw-s.common.lib.serviceAccount.validate" (dict "rootContext" $ "object" $serviceAccountObject) -}} - - {{- /* Create a service account secret */ -}} - {{- $_ := set $.Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "enabled" true "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}} - - {{/* Include the serviceAccount class */}} - {{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $ "object" $serviceAccountObject) | nindent 0 -}} - - {{- end -}} + {{- if $serviceAccountObject.staticToken -}} + {{- $_ := set $rootContext.Values.secrets (printf "%s-sa-token" $serviceAccountObject.identifier) (dict "suffix" (printf "%s-sa-token" $serviceAccountObject.identifier) "annotations" (dict "kubernetes.io/service-account.name" $serviceAccountObject.name) "type" "kubernetes.io/service-account-token") -}} {{- end -}} - {{- end -}} + {{- /* Include the ServiceAccount class */ -}} + {{- include "bjw-s.common.class.serviceAccount" (dict "rootContext" $rootContext "object" $serviceAccountObject) | nindent 0 -}} + {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/render/_services.tpl b/charts/library/common/templates/render/_services.tpl index cf6f6ee8..ca934e17 100644 --- a/charts/library/common/templates/render/_services.tpl +++ b/charts/library/common/templates/render/_services.tpl @@ -2,18 +2,18 @@ Renders the Service objects required by the chart. */}} {{- define "bjw-s.common.render.services" -}} - {{- /* Generate named Services as required */ -}} - {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $) | fromYaml ) -}} - {{- range $key, $svc := $enabledServices -}} - {{- $serviceValues := (mustDeepCopy $svc) -}} + {{- $rootContext := $ -}} - {{- /* Create object from the raw Service values */ -}} - {{- $serviceObject := (include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $ "id" $key "values" $serviceValues)) | fromYaml -}} + {{- /* Generate named Services as required */ -}} + {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) -}} + {{- range $identifier := keys $enabledServices -}} + {{- /* Generate object from the raw service values */ -}} + {{- $serviceObject := (include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml) -}} {{- /* Perform validations on the Service before rendering */ -}} - {{- include "bjw-s.common.lib.service.validate" (dict "rootContext" $ "object" $serviceObject) -}} + {{- include "bjw-s.common.lib.service.validate" (dict "rootContext" $rootContext "object" $serviceObject) -}} {{- /* Include the Service class */ -}} - {{- include "bjw-s.common.class.service" (dict "rootContext" $ "object" $serviceObject) | nindent 0 -}} + {{- include "bjw-s.common.class.service" (dict "rootContext" $rootContext "object" $serviceObject) | nindent 0 -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/test-chart/Chart.yaml b/charts/library/common/test-chart/Chart.yaml index 21ebdb55..8c763b55 100644 --- a/charts/library/common/test-chart/Chart.yaml +++ b/charts/library/common/test-chart/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 description: A helper chart that is used to test the common library chart name: common-test version: 1.0.0 -kubeVersion: ">=1.22.0-0" +kubeVersion: ">=1.28.0-0" maintainers: - name: bjw-s email: me@bjw-s.dev diff --git a/charts/library/common/test-chart/ci/advanced-values.yaml b/charts/library/common/test-chart/ci/advanced-values.yaml index d58ece45..dda6e69a 100644 --- a/charts/library/common/test-chart/ci/advanced-values.yaml +++ b/charts/library/common/test-chart/ci/advanced-values.yaml @@ -1,5 +1,5 @@ --- -# yaml-language-server: $schema=../../common/values.schema.json +# yaml-language-server: $schema=../../../common/values.schema.json controllers: main: containers: @@ -72,15 +72,13 @@ ingress: configMaps: config: - enabled: true data: test: value 1 persistence: data: type: configMap - name: |- - {{- (include "bjw-s.common.lib.chart.names.fullname" $) -}}-config + identifier: config advancedMounts: main: # the controller with the "main" identifier main: # the container with the "main" identifier @@ -99,7 +97,7 @@ persistence: rawResources: unsupportedPDB: enabled: true - nameOverride: pdb + forceRename: pdb apiVersion: policy/v1 kind: PodDisruptionBudget spec: diff --git a/charts/library/common/test-chart/ci/basic-values.yaml b/charts/library/common/test-chart/ci/basic-values.yaml index 078e44bc..fa840992 100644 --- a/charts/library/common/test-chart/ci/basic-values.yaml +++ b/charts/library/common/test-chart/ci/basic-values.yaml @@ -1,5 +1,5 @@ --- -# yaml-language-server: $schema=../../common/values.schema.json +# yaml-language-server: $schema=../../../common/values.schema.json controllers: main: containers: @@ -23,16 +23,12 @@ ingress: - host: "test.local" paths: - path: / - service: - identifier: main - port: http tls: - hosts: - "test.local" service: main: - controller: main ports: http: port: 8080 diff --git a/charts/library/common/test-chart/ci/cronjob-values.yaml b/charts/library/common/test-chart/ci/cronjob-values.yaml index 6a9060e2..ef51dbd0 100644 --- a/charts/library/common/test-chart/ci/cronjob-values.yaml +++ b/charts/library/common/test-chart/ci/cronjob-values.yaml @@ -1,5 +1,5 @@ --- -# yaml-language-server: $schema=../../common/values.schema.json +# yaml-language-server: $schema=../../../common/values.schema.json controllers: main: type: cronjob diff --git a/charts/library/common/test-chart/ci/no-service.yaml b/charts/library/common/test-chart/ci/no-service.yaml index ed23874f..fee33dd7 100644 --- a/charts/library/common/test-chart/ci/no-service.yaml +++ b/charts/library/common/test-chart/ci/no-service.yaml @@ -1,5 +1,5 @@ --- -# yaml-language-server: $schema=../../common/values.schema.json +# yaml-language-server: $schema=../../../common/values.schema.json controllers: main: containers: diff --git a/charts/library/common/test-chart/ci/vaultwarden-example.yaml b/charts/library/common/test-chart/ci/vaultwarden-example.yaml index 55e67058..b783a7be 100644 --- a/charts/library/common/test-chart/ci/vaultwarden-example.yaml +++ b/charts/library/common/test-chart/ci/vaultwarden-example.yaml @@ -1,5 +1,5 @@ --- -# yaml-language-server: $schema=../../common/values.schema.json +# yaml-language-server: $schema=../../values.schema.json controllers: main: strategy: Recreate diff --git a/charts/library/common/test-chart/unittests/_values/rbac_values.yaml b/charts/library/common/test-chart/unittests/_values/rbac_values.yaml index 017cc8f4..cb0707ff 100644 --- a/charts/library/common/test-chart/unittests/_values/rbac_values.yaml +++ b/charts/library/common/test-chart/unittests/_values/rbac_values.yaml @@ -1,5 +1,5 @@ serviceAccount: - create: true + default: {} rbac: roles: diff --git a/charts/library/common/test-chart/unittests/chart/validations_test.yaml b/charts/library/common/test-chart/unittests/chart/validations_test.yaml index 80c4ef8b..0dd18aa5 100644 --- a/charts/library/common/test-chart/unittests/chart/validations_test.yaml +++ b/charts/library/common/test-chart/unittests/chart/validations_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: Chart validations +suite: chart - validations templates: - common.yaml values: diff --git a/charts/library/common/test-chart/unittests/configmap/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/configmap/metadata_annotations_test.yaml new file mode 100644 index 00000000..d5176d2a --- /dev/null +++ b/charts/library/common/test-chart/unittests/configmap/metadata_annotations_test.yaml @@ -0,0 +1,117 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: configmap - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: no annotations are set by default + set: + configMaps: + config: + data: + test: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + configMaps: + config: + data: + test: test + annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + configMaps: + config: + data: + test: test + annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test + + - it: default metadata from folder should pass + set: + configMaps: + config: + data: + test: test + configMapsFromFolder: + enabled: true + basePath: ci/configMapsFolder + configMapsOverrides: + test_2: + fileAttributeOverrides: + helm.jpg: + binary: true + test_2.yaml: + escaped: true + asserts: + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-config + notExists: + path: metadata.annotations + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_1 + notExists: + path: metadata.annotations + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_2 + notExists: + path: metadata.annotations + + - it: custom metadata from folder should pass + set: + configMaps: + config: + data: + test: test + configMapsFromFolder: + enabled: true + basePath: ci/configMapsFolder + configMapsOverrides: + test_2: + annotations: + test: test_annotation + fileAttributeOverrides: + helm.jpg: + binary: true + test_2.yaml: + escaped: true + asserts: + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_2 + equal: + path: metadata.annotations + value: + test: test_annotation diff --git a/charts/library/common/test-chart/unittests/configmap/metadata_test.yaml b/charts/library/common/test-chart/unittests/configmap/metadata_labels_test.yaml similarity index 54% rename from charts/library/common/test-chart/unittests/configmap/metadata_test.yaml rename to charts/library/common/test-chart/unittests/configmap/metadata_labels_test.yaml index b28aae51..5fcb871d 100644 --- a/charts/library/common/test-chart/unittests/configmap/metadata_test.yaml +++ b/charts/library/common/test-chart/unittests/configmap/metadata_labels_test.yaml @@ -1,28 +1,22 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: configmap metadata +suite: configmap - metadata - labels templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - - it: default metadata should pass + - it: default labels set: configMaps: config: data: test: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - notExists: - path: metadata.annotations - - documentIndex: *ConfigmapDocument - equal: + - equal: path: metadata.labels value: app.kubernetes.io/instance: RELEASE-NAME @@ -30,29 +24,19 @@ tests: app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - it: custom metadata should pass + - it: custom labels set: configMaps: config: data: test: test - annotations: - test_annotation: test labels: test_label: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ConfigmapDocument - equal: + - equal: path: metadata.labels value: app.kubernetes.io/instance: RELEASE-NAME @@ -61,35 +45,21 @@ tests: helm.sh/chart: common-test-1.0.0 test_label: test - - it: custom metadata with global metadata should pass + - it: custom labels mixed with global labels set: - global: - labels: - global_label: test - annotations: - global_annotation: test + global.labels: + global_label: test configMaps: config: data: test: test - annotations: - test_annotation: test labels: test_label: test + documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ConfigmapDocument - equal: + - equal: path: metadata.labels value: app.kubernetes.io/instance: RELEASE-NAME @@ -99,19 +69,6 @@ tests: helm.sh/chart: common-test-1.0.0 test_label: test - - it: default configuration from folder with binary files should fail - set: - configMaps: - config: - data: - test: test - configMapsFromFolder: - enabled: true - basePath: ci/configMapsFolder - asserts: - - failedTemplate: - errorMessage: "There was an error loading ConfigMap: test_2. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" - - it: default metadata from folder should pass set: configMaps: @@ -129,15 +86,9 @@ tests: test_2.yaml: escaped: true asserts: - - hasDocuments: - count: 4 - - documentIndex: &FirstConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *FirstConfigmapDocument - notExists: - path: metadata.annotations - - documentIndex: *FirstConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-config equal: path: metadata.labels value: @@ -145,13 +96,9 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - documentIndex: &SecondConfigmapDocument 1 - isKind: - of: ConfigMap - - documentIndex: *SecondConfigmapDocument - notExists: - path: metadata.annotations - - documentIndex: *SecondConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_1 equal: path: metadata.labels value: @@ -159,13 +106,9 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - documentIndex: &ThirdConfigmapDocument 2 - isKind: - of: ConfigMap - - documentIndex: *ThirdConfigmapDocument - notExists: - path: metadata.annotations - - documentIndex: *ThirdConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_2 equal: path: metadata.labels value: @@ -187,20 +130,15 @@ tests: test_2: labels: test: test_label - annotations: - test: test_annotation fileAttributeOverrides: helm.jpg: binary: true test_2.yaml: escaped: true asserts: - - hasDocuments: - count: 4 - - documentIndex: &FirstConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *FirstConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-config equal: path: metadata.labels value: @@ -208,10 +146,9 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - documentIndex: &SecondConfigmapDocument 1 - isKind: - of: ConfigMap - - documentIndex: *SecondConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_1 equal: path: metadata.labels value: @@ -219,10 +156,9 @@ tests: app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - documentIndex: &ThirdConfigmapDocument 2 - isKind: - of: ConfigMap - - documentIndex: *ThirdConfigmapDocument + - documentSelector: + path: $[?(@.kind == "ConfigMap")].metadata.name + value: release-name-test_2 equal: path: metadata.labels value: @@ -231,8 +167,3 @@ tests: app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 test: test_label - - documentIndex: *ThirdConfigmapDocument - equal: - path: metadata.annotations - value: - test: test_annotation diff --git a/charts/library/common/test-chart/unittests/configmap/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/configmap/metadata_name_test.yaml new file mode 100644 index 00000000..45b15113 --- /dev/null +++ b/charts/library/common/test-chart/unittests/configmap/metadata_name_test.yaml @@ -0,0 +1,183 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: configmap - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + configMaps.main: + data: + test: test +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + configMaps.main.forceRename: forceRename + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + configMaps.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + configMaps.main.prefix: prefix + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + configMaps.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + configMaps.main.suffix: suffix + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + configMaps.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + configMaps.main.prefix: prefix + configMaps.main.suffix: suffix + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + configMaps.main.forceRename: forceRename + configMaps.main.prefix: prefix + configMaps.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + configMaps.second: + data: + test: test + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + configMaps.second: + prefix: prefix + data: + test: test + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + configMaps.second: + suffix: suffix + data: + test: test + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + configMaps.second: + prefix: prefix + suffix: suffix + data: + test: test + asserts: + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + configMaps.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + data: + test: test + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/configmap/names_test.yaml b/charts/library/common/test-chart/unittests/configmap/names_test.yaml deleted file mode 100644 index 5727cb56..00000000 --- a/charts/library/common/test-chart/unittests/configmap/names_test.yaml +++ /dev/null @@ -1,196 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: configMap names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default should pass - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: ConfigMap - - - it: with disabled configMap should pass - set: - configMaps: - config: - enabled: false - data: - test: test - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: ConfigMap - - - it: with multiple configMap should pass - set: - configMaps: - config: - data: - foo: bar - secondary: - data: - test: test - asserts: - - hasDocuments: - count: 3 - - documentIndex: &FirstConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *FirstConfigmapDocument - isNotNullOrEmpty: - path: metadata.name - - documentIndex: &SecondConfigmapDocument 1 - isKind: - of: ConfigMap - - documentIndex: *SecondConfigmapDocument - isNotNullOrEmpty: - path: metadata.name - - - it: default name should pass - set: - configMaps: - config: - data: - test: test - asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME-config - - - it: with nameOverride should pass - set: - configMaps: - config: - data: - test: test - nameOverride: http - asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME-http - - - it: with templated nameOverride should pass - set: - configMaps: - config: - data: - test: test - nameOverride: "{{ .Release.Name }}" - asserts: - - hasDocuments: - count: 2 - - documentIndex: &ConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *ConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME - - - it: with templated nameOverride and from folder should pass - set: - configMaps: - config: - data: - test: test - nameOverride: "{{ .Release.Name }}" - configMapsFromFolder: - enabled: true - basePath: ci/configMapsFolder - configMapsOverrides: - test_2: - fileAttributeOverrides: - helm.jpg: - binary: true - test_2.yaml: - escaped: true - asserts: - - hasDocuments: - count: 4 - - documentIndex: &FirstConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *FirstConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME - - documentIndex: &SecondConfigmapDocument 1 - isKind: - of: ConfigMap - - documentIndex: *SecondConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME-test_1 - - documentIndex: &ThirdConfigmapDocument 2 - isKind: - of: ConfigMap - - documentIndex: *ThirdConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME-test_2 - - - it: with templated nameOverride and from folder with forceRename should pass - set: - configMaps: - config: - data: - test: test - nameOverride: "{{ .Release.Name }}" - configMapsFromFolder: - enabled: true - basePath: ci/configMapsFolder - configMapsOverrides: - test_1: - forceRename: &newName1 newName1 - test_2: - forceRename: &newName2 newName2 - fileAttributeOverrides: - helm.jpg: - binary: true - test_2.yaml: - escaped: true - asserts: - - hasDocuments: - count: 4 - - documentIndex: &FirstConfigmapDocument 0 - isKind: - of: ConfigMap - - documentIndex: *FirstConfigmapDocument - equal: - path: metadata.name - value: RELEASE-NAME - - documentIndex: &SecondConfigmapDocument 1 - isKind: - of: ConfigMap - - documentIndex: *SecondConfigmapDocument - equal: - path: metadata.name - value: *newName1 - - documentIndex: &ThirdConfigmapDocument 2 - isKind: - of: ConfigMap - - documentIndex: *ThirdConfigmapDocument - equal: - path: metadata.name - value: *newName2 diff --git a/charts/library/common/test-chart/unittests/configmap/pod_metadata_test.yaml b/charts/library/common/test-chart/unittests/configmap/pod_metadata_test.yaml deleted file mode 100644 index 6fea2acc..00000000 --- a/charts/library/common/test-chart/unittests/configmap/pod_metadata_test.yaml +++ /dev/null @@ -1,73 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: configmap Pod metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - configMaps: - config: - enabled: true - data: - test: value 1 - test_default_enabled: - data: - test: value 1 - test_not_in_checksum: - includeInChecksum: false - data: - test: value 1 - test_disabled: - enabled: false - data: - test: value 1 - asserts: - - documentIndex: &ControllerDoc 3 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: spec.template.metadata.annotations - value: - checksum/configMaps: 66d23d7a53c4e2a523ba85a969696b4ebb78ec5d79ab9c12c210c1569f48511b - - - it: default metadata from folder should pass - set: - configMaps: - config: - enabled: true - data: - test: value 1 - test_default_enabled: - data: - test: value 1 - test_not_in_checksum: - includeInChecksum: false - data: - test: value 1 - test_disabled: - enabled: false - data: - test: value 1 - configMapsFromFolder: - enabled: true - basePath: ci/configMapsFolder - configMapsOverrides: - test_2: - fileAttributeOverrides: - helm.jpg: - binary: true - test_2.yaml: - escaped: true - asserts: - - documentIndex: &ControllerDoc 5 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: spec.template.metadata.annotations - value: - checksum/configMaps: e83a24569d0b4f2ccc44aec36d4e9a1c44a29bcc92eefdffe14fb1ce81dff054 diff --git a/charts/library/common/test-chart/unittests/configmap/presence_test.yaml b/charts/library/common/test-chart/unittests/configmap/presence_test.yaml new file mode 100644 index 00000000..818fd410 --- /dev/null +++ b/charts/library/common/test-chart/unittests/configmap/presence_test.yaml @@ -0,0 +1,85 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: configmap - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: configMap should not be rendered by default + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name + any: true + + - it: with disabled configMap + set: + configMaps: + config: + enabled: false + data: + test: test + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name + any: true + + - it: with multiple configMaps + set: + configMaps: + config: + data: + foo: bar + secondary: + data: + test: test + asserts: + - containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name-config + any: true + - containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name-secondary + any: true + + - it: combined with configMapsFromFolder + set: + configMaps: + config: + data: + test: test + configMapsFromFolder: + enabled: true + basePath: ci/configMapsFolder + configMapsOverrides: + test_2: + fileAttributeOverrides: + helm.jpg: + binary: true + test_2.yaml: + escaped: true + asserts: + - containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name-config + any: true + - containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name-test_1 + any: true + - containsDocument: + apiVersion: v1 + kind: ConfigMap + name: release-name-test_2 + any: true diff --git a/charts/library/common/test-chart/unittests/configmap/validation_test.yaml b/charts/library/common/test-chart/unittests/configmap/validation_test.yaml new file mode 100644 index 00000000..d19061fa --- /dev/null +++ b/charts/library/common/test-chart/unittests/configmap/validation_test.yaml @@ -0,0 +1,20 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: configmap - validations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: default configuration from folder with binary files should fail + set: + configMaps: + config: + data: + test: test + configMapsFromFolder: + enabled: true + basePath: ci/configMapsFolder + asserts: + - failedTemplate: + errorMessage: "There was an error loading ConfigMap: test_2. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" diff --git a/charts/library/common/test-chart/unittests/container/field_args_test.yaml b/charts/library/common/test-chart/unittests/container/field_args_test.yaml index 76aa324a..e94285a5 100644 --- a/charts/library/common/test-chart/unittests/container/field_args_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_args_test.yaml @@ -1,29 +1,27 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container args override +suite: container - fields - args templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].args - it: single string should pass set: controllers.main.containers.main.args: sleep infinity + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].args value: - sleep infinity @@ -33,12 +31,11 @@ tests: controllers.main.containers.main.args: | echo hello echo world + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].args value: - |- @@ -48,12 +45,11 @@ tests: - it: single quoted string should pass set: controllers.main.containers.main.args: "sleep infinity" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].args value: - sleep infinity @@ -64,12 +60,11 @@ tests: - sleep - infinity - "test" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].args value: - sleep @@ -80,12 +75,11 @@ tests: set: controllers.main.defaultContainerOptions: args: value_of_args + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].args value: - value_of_args @@ -97,12 +91,11 @@ tests: controllers.main.containers.main.args: - value 1 - value 2 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].args value: - value 1 diff --git a/charts/library/common/test-chart/unittests/container/field_command_test.yaml b/charts/library/common/test-chart/unittests/container/field_command_test.yaml index d41871bc..30816400 100644 --- a/charts/library/common/test-chart/unittests/container/field_command_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_command_test.yaml @@ -1,29 +1,27 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container command override +suite: container - fields - command templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].command - it: single string should pass set: controllers.main.containers.main.command: /bin/sh + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].command value: - /bin/sh @@ -33,12 +31,11 @@ tests: controllers.main.containers.main.command: | /bin/sh -c + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].command value: - |- @@ -48,12 +45,11 @@ tests: - it: single quoted string should pass set: controllers.main.containers.main.command: "/bin/sh" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].command value: - /bin/sh @@ -63,12 +59,11 @@ tests: controllers.main.containers.main.command: - /bin/sh - "-c" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].command value: - /bin/sh @@ -78,12 +73,11 @@ tests: set: controllers.main.defaultContainerOptions: command: value_of_command + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].command value: - value_of_command @@ -95,12 +89,11 @@ tests: controllers.main.containers.main.command: - value 1 - value 2 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].command value: - value 1 diff --git a/charts/library/common/test-chart/unittests/container/field_env_test.yaml b/charts/library/common/test-chart/unittests/container/field_env_test.yaml index e2813943..71a731bc 100644 --- a/charts/library/common/test-chart/unittests/container/field_env_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_env_test.yaml @@ -1,30 +1,28 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container env values +suite: container - fields - env templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - notExists: + - notExists: path: spec.template.spec.containers[0].env - it: KeyValue string should pass set: controllers.main.containers.main.env: string: value_of_env + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: string @@ -34,12 +32,11 @@ tests: set: controllers.main.containers.main.env: string: 4.2 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: string @@ -49,12 +46,11 @@ tests: set: controllers.main.containers.main.env: string: 1 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: string @@ -65,12 +61,11 @@ tests: controllers.main.containers.main.env: - name: STATIC_ENV_FROM_LIST value: STATIC_ENV_VALUE_FROM_LIST + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: STATIC_ENV_FROM_LIST @@ -83,12 +78,11 @@ tests: valueFrom: fieldRef: fieldPath: spec.nodeName + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: DYNAMIC_ENV_FROM_LIST @@ -102,12 +96,11 @@ tests: - name: DYNAMIC_ENV_FROM_LIST fieldRef: fieldPath: spec.nodeName + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: DYNAMIC_ENV_FROM_LIST @@ -121,12 +114,11 @@ tests: DYNAMIC_ENV: fieldRef: fieldPath: spec.nodeName + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: DYNAMIC_ENV @@ -143,18 +135,16 @@ tests: secretKeyRef: name: "{{ .Release.Name }}-secret" key: "{{ .Release.Name }}-key" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: DYNAMIC_ENV value: RELEASE-NAME-admin - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[1] value: name: TEMPLATE_ENV @@ -171,20 +161,18 @@ tests: valueFrom: fieldRef: fieldPath: spec.nodeName + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: DYNAMIC_ENV valueFrom: fieldRef: fieldPath: spec.nodeName - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[1] value: name: STATIC_ENV @@ -207,32 +195,28 @@ tests: dependsOn: - DYNAMIC_ENV - ORDERED_ENV + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: STATIC_ENV value: "1" - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[1] value: name: DYNAMIC_ENV valueFrom: fieldRef: fieldPath: spec.nodeName - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[2] value: name: ORDERED_ENV value: "true" - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[3] value: name: DEPENDENT_ENV @@ -243,12 +227,11 @@ tests: controllers.main.defaultContainerOptions: env: string: value_of_env + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: string @@ -261,12 +244,11 @@ tests: string: value_of_env controllers.main.containers.main.env: someThingElse: value_of_env + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: someThingElse diff --git a/charts/library/common/test-chart/unittests/container/field_envfrom_test.yaml b/charts/library/common/test-chart/unittests/container/field_envfrom_test.yaml index 1715fbdb..fa365b25 100644 --- a/charts/library/common/test-chart/unittests/container/field_envfrom_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_envfrom_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container envFrom values +suite: container - fields - envFrom templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - notExists: + - notExists: path: spec.template.spec.containers[0].envFrom - it: explicit envFrom should pass @@ -23,19 +22,17 @@ tests: prefix: test - configMapRef: name: myCustomConfig + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: secretRef: name: myCustomSecret prefix: test - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[1] value: configMapRef: @@ -50,19 +47,17 @@ tests: prefix: test - configMapRef: name: myCustomConfig + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: secretRef: name: myCustomSecret prefix: test - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[1] value: configMapRef: @@ -81,19 +76,17 @@ tests: - secretRef: name: myCustomSecretOverride prefix: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: secretRef: name: myCustomSecretOverride prefix: test - - documentIndex: *DeploymentDoc - notExists: + - notExists: path: spec.template.spec.containers[0].envFrom[1] - it: envFrom configmap identifier reference should pass @@ -107,23 +100,21 @@ tests: config: data: test: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: configMapRef: - name: RELEASE-NAME-config + name: release-name prefix: test - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[1] value: configMapRef: - name: RELEASE-NAME-config + name: release-name - it: envFrom Secret identifier reference should pass set: @@ -137,23 +128,21 @@ tests: secret: stringData: test: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: secretRef: - name: RELEASE-NAME-secret + name: release-name prefix: test - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[1] value: secretRef: - name: RELEASE-NAME-secret + name: release-name prefix: test - it: envFrom with templated name reference should pass @@ -165,30 +154,26 @@ tests: - secret: "{{ .Release.Name }}-secret" - secretRef: name: "{{ .Release.Name }}-secret2" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[0] value: configMapRef: name: RELEASE-NAME-config - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[1] value: configMapRef: name: RELEASE-NAME-config2 - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[2] value: secretRef: name: RELEASE-NAME-secret - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].envFrom[3] value: secretRef: diff --git a/charts/library/common/test-chart/unittests/container/field_image_test.yaml b/charts/library/common/test-chart/unittests/container/field_image_test.yaml index bb64d835..2bfb1080 100644 --- a/charts/library/common/test-chart/unittests/container/field_image_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_image_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container image tag +suite: container - fields - image templates: - common.yaml tests: @@ -11,12 +11,11 @@ tests: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo tag: latest + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo:latest @@ -27,12 +26,11 @@ tests: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo tag: 1.23 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo:1.23 @@ -43,12 +41,11 @@ tests: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo tag: "{{.Chart.Version}}" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo:1.0.0 @@ -61,12 +58,11 @@ tests: tag: 32 containers: main: {} # needed to have at least a container enabled + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo:32 @@ -78,11 +74,10 @@ tests: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo-override tag: 33 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo-override:33 diff --git a/charts/library/common/test-chart/unittests/container/name_test.yaml b/charts/library/common/test-chart/unittests/container/field_nameOverride_test.yaml similarity index 74% rename from charts/library/common/test-chart/unittests/container/name_test.yaml rename to charts/library/common/test-chart/unittests/container/field_nameOverride_test.yaml index 8b00872c..52a5b3f6 100644 --- a/charts/library/common/test-chart/unittests/container/name_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_nameOverride_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container name +suite: container - fields - nameOverride templates: - common.yaml values: @@ -13,12 +13,11 @@ tests: nameOverride: template-test image: repository: ghcr.io/mendhak/http-https-echo + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].name value: template-test @@ -28,12 +27,11 @@ tests: main: image: repository: ghcr.io/mendhak/http-https-echo + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].name value: main @@ -44,11 +42,10 @@ tests: nameOverride: "{{ .Release.Name }}-container" image: repository: ghcr.io/mendhak/http-https-echo + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].name value: RELEASE-NAME-container diff --git a/charts/library/common/test-chart/unittests/container/ports_test.yaml b/charts/library/common/test-chart/unittests/container/field_ports_test.yaml similarity index 72% rename from charts/library/common/test-chart/unittests/container/ports_test.yaml rename to charts/library/common/test-chart/unittests/container/field_ports_test.yaml index 3e470f62..a9ed977d 100644 --- a/charts/library/common/test-chart/unittests/container/ports_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_ports_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container ports +suite: container - fields - ports templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].ports - it: custom port should pass @@ -25,13 +24,11 @@ tests: - containerPort: 8080 name: http protocol: TCP - + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].ports[0] value: containerPort: 8080 diff --git a/charts/library/common/test-chart/unittests/container/probes_test.yaml b/charts/library/common/test-chart/unittests/container/field_probes_test.yaml similarity index 87% rename from charts/library/common/test-chart/unittests/container/probes_test.yaml rename to charts/library/common/test-chart/unittests/container/field_probes_test.yaml index 9457834c..a79cd2d5 100644 --- a/charts/library/common/test-chart/unittests/container/probes_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_probes_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container probes +suite: container - fields - probes templates: - common.yaml values: @@ -13,9 +13,9 @@ set: tests: - it: default probes - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -51,7 +51,9 @@ tests: enabled: true primary: true port: 8080 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - documentIndex: 0 isKind: @@ -87,7 +89,9 @@ tests: - it: probes with string Service port set: service.main.ports.http.port: "80" - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -144,37 +148,37 @@ tests: asserts: - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-main + value: release-name-main equal: path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port value: 8081 - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-main + value: release-name-main equal: path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port value: 8081 - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-main + value: release-name-main equal: path: spec.template.spec.containers[0].startupProbe.tcpSocket.port value: 8081 - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-other + value: release-name-other equal: path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port value: 8080 - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-other + value: release-name-other equal: path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port value: 8080 - documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME-other + value: release-name-other equal: path: spec.template.spec.containers[0].startupProbe.tcpSocket.port value: 8080 @@ -185,7 +189,9 @@ tests: main: enabled: false controller: main - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - notExists: path: spec.template.spec.containers[0].livenessProbe @@ -202,7 +208,9 @@ tests: enabled: true type: AUTO path: /api/version - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - documentIndex: 0 isKind: @@ -227,7 +235,9 @@ tests: enabled: true type: HTTP path: /api/version - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -248,7 +258,9 @@ tests: enabled: true type: HTTPS path: /api/version - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -268,7 +280,9 @@ tests: liveness: enabled: true type: GRPC - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -287,7 +301,9 @@ tests: enabled: true type: GRPC service: test - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -314,7 +330,9 @@ tests: periodSeconds: 10 timeoutSeconds: 1 failureThreshold: 3 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].livenessProbe @@ -341,7 +359,9 @@ tests: periodSeconds: 10 timeoutSeconds: 1 failureThreshold: 3 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].readinessProbe @@ -368,7 +388,9 @@ tests: periodSeconds: 10 timeoutSeconds: 1 failureThreshold: 3 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].startupProbe @@ -387,7 +409,9 @@ tests: liveness: enabled: true port: http - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - documentIndex: 0 equal: @@ -406,7 +430,9 @@ tests: readiness: enabled: true port: http - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].readinessProbe @@ -424,7 +450,9 @@ tests: startup: enabled: true port: http - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.containers[0].startupProbe diff --git a/charts/library/common/test-chart/unittests/container/field_resources_test.yaml b/charts/library/common/test-chart/unittests/container/field_resources_test.yaml index 16d1a196..263b6990 100644 --- a/charts/library/common/test-chart/unittests/container/field_resources_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_resources_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container resources +suite: container - fields - resources templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].resources - it: defaultContainerOption should pass @@ -28,18 +27,16 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 1Gi - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.initContainers[0].resources value: requests: @@ -63,18 +60,16 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 2Gi - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.initContainers[0].resources value: requests: @@ -96,18 +91,16 @@ tests: resources: requests: memory: 2Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 1Gi - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.initContainers[0].resources value: requests: @@ -127,16 +120,14 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 1Gi - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.initContainers[0].resources diff --git a/charts/library/common/test-chart/unittests/container/field_restartpolicy_test.yaml b/charts/library/common/test-chart/unittests/container/field_restartpolicy_test.yaml index 5d088742..87ac7b77 100644 --- a/charts/library/common/test-chart/unittests/container/field_restartpolicy_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_restartpolicy_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container restartPolicy +suite: container - fields - restartPolicy templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].restartPolicy - it: custom restartPolicy should pass @@ -20,12 +19,10 @@ tests: controllers.main.containers: main: restartPolicy: Always - + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].restartPolicy value: Always diff --git a/charts/library/common/test-chart/unittests/container/field_securityContext_test.yaml b/charts/library/common/test-chart/unittests/container/field_securityContext_test.yaml index 2f8afce4..5a0d97b0 100644 --- a/charts/library/common/test-chart/unittests/container/field_securityContext_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_securityContext_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container securityContext +suite: container - fields - securityContext templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].securityContext - it: defaultContainerOption should pass @@ -23,12 +22,11 @@ tests: securityContext: runAsUser: 1000 runAsGroup: 1000 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].securityContext value: runAsUser: 1000 @@ -47,12 +45,11 @@ tests: securityContext: runAsUser: 568 runAsGroup: 568 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].securityContext value: runAsUser: 568 diff --git a/charts/library/common/test-chart/unittests/container/field_stdin_test.yaml b/charts/library/common/test-chart/unittests/container/field_stdin_test.yaml index 83034533..6e565368 100644 --- a/charts/library/common/test-chart/unittests/container/field_stdin_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_stdin_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container stdin +suite: container - fields - stdin templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].stdin - it: custom stdin should pass @@ -20,11 +19,10 @@ tests: controllers.main.containers: main: stdin: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].stdin value: true diff --git a/charts/library/common/test-chart/unittests/container/field_tty_test.yaml b/charts/library/common/test-chart/unittests/container/field_tty_test.yaml index a3b86bcb..3027686b 100644 --- a/charts/library/common/test-chart/unittests/container/field_tty_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_tty_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container tty +suite: container - fields - tty templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].tty - it: custom tty should pass @@ -20,11 +19,10 @@ tests: controllers.main.containers: main: tty: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].tty value: true diff --git a/charts/library/common/test-chart/unittests/container/volumemounts_test.yaml b/charts/library/common/test-chart/unittests/container/field_volumemounts_test.yaml similarity index 74% rename from charts/library/common/test-chart/unittests/container/volumemounts_test.yaml rename to charts/library/common/test-chart/unittests/container/field_volumemounts_test.yaml index 370a6006..22a2e3d9 100644 --- a/charts/library/common/test-chart/unittests/container/volumemounts_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_volumemounts_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container volumeMounts +suite: container - fields - volumeMounts templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: no persistence should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - notExists: + - notExists: path: spec.template.spec.containers[0].volumeMounts - it: default should pass @@ -21,12 +20,11 @@ tests: config: accessMode: ReadWriteOnce size: 1Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: config @@ -47,7 +45,6 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 - persistence: data: type: configMap @@ -69,12 +66,10 @@ tests: - path: /second-pod/config.yaml readOnly: false subPath: config.yaml - asserts: - - documentIndex: &FirstDeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *FirstDeploymentDoc + - documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name-main equal: path: spec.template.spec.containers[0].volumeMounts value: @@ -84,7 +79,9 @@ tests: name: data subPath: config.yaml mountPropagation: HostToContainer - - documentIndex: *FirstDeploymentDoc + - documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name-main equal: path: spec.template.spec.containers[1].volumeMounts value: @@ -93,10 +90,9 @@ tests: - mountPath: /appdata/config name: data readOnly: true - - documentIndex: &SecondDeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *SecondDeploymentDoc + - documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name-second equal: path: spec.template.spec.containers[0].volumeMounts value: @@ -111,12 +107,11 @@ tests: persistence: cache: type: emptyDir + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: cache @@ -130,12 +125,11 @@ tests: size: 1G globalMounts: - path: /custom + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: config @@ -149,18 +143,36 @@ tests: globalMounts: - path: /config subPath: "mySubPath" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: config mountPath: /config subPath: mySubPath + - it: mount with subPathExpr should pass + set: + persistence: + config: + existingClaim: myClaim + globalMounts: + - path: /config + subPathExpr: $(POD_NAME) + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.containers[0].volumeMounts[0] + value: + name: config + mountPath: /config + subPathExpr: $(POD_NAME) + - it: hostPath with custom mountPath should pass set: persistence: @@ -169,12 +181,11 @@ tests: hostPath: /tmp globalMounts: - path: /data + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: config @@ -188,12 +199,11 @@ tests: hostPath: /dev globalMounts: - subPath: mySubPath + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: config @@ -210,12 +220,11 @@ tests: accessMode: "ReadWriteOnce" size: "10Gi" storageClass: "storage" + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: storage @@ -234,18 +243,16 @@ tests: globalMounts: - path: /tmp/storage - path: /tmp/secondMountPoint + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[0] value: name: storage mountPath: /tmp/storage - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.template.spec.containers[0].volumeMounts[1] value: name: storage @@ -270,21 +277,18 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - notExists: + - notExists: path: spec.template.spec.containers[0].volumeMounts - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.template.spec.containers[1].volumeMounts[0] value: name: storage mountPath: /tmp/storage - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.template.spec.containers[1].volumeMounts[1] value: name: storage diff --git a/charts/library/common/test-chart/unittests/container/workingdir_test.yaml b/charts/library/common/test-chart/unittests/container/field_workingdir_test.yaml similarity index 64% rename from charts/library/common/test-chart/unittests/container/workingdir_test.yaml rename to charts/library/common/test-chart/unittests/container/field_workingdir_test.yaml index b35bf00a..e6881b50 100644 --- a/charts/library/common/test-chart/unittests/container/workingdir_test.yaml +++ b/charts/library/common/test-chart/unittests/container/field_workingdir_test.yaml @@ -1,40 +1,37 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: container workingDir override +suite: container - fields - workingDir templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.containers[0].workingDir - it: string should pass set: controllers.main.containers.main.workingDir: /work + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].workingDir value: /work - it: quoted string should pass set: controllers.main.containers.main.workingDir: "/work" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].workingDir value: /work diff --git a/charts/library/common/test-chart/unittests/container/validations_test.yaml b/charts/library/common/test-chart/unittests/container/validations_test.yaml index 7608bb2d..4d270603 100644 --- a/charts/library/common/test-chart/unittests/container/validations_test.yaml +++ b/charts/library/common/test-chart/unittests/container/validations_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: Container validations +suite: container - validations templates: - common.yaml values: diff --git a/charts/library/common/test-chart/unittests/controller/cronjob_test.yaml b/charts/library/common/test-chart/unittests/controller/cronjob_test.yaml deleted file mode 100644 index 83469fa4..00000000 --- a/charts/library/common/test-chart/unittests/controller/cronjob_test.yaml +++ /dev/null @@ -1,95 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: cronjob configuration -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default cronjob configuration should pass - set: - controllers.main.type: cronjob - controllers.main.cronjob.schedule: "*/20 * * * *" - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: spec.suspend - value: false - - documentIndex: *ControllerDoc - equal: - path: spec.schedule - value: "*/20 * * * *" - - documentIndex: *ControllerDoc - equal: - path: spec.concurrencyPolicy - value: Forbid - - documentIndex: *ControllerDoc - equal: - path: spec.successfulJobsHistoryLimit - value: 1 - - documentIndex: *ControllerDoc - equal: - path: spec.failedJobsHistoryLimit - value: 1 - - documentIndex: *ControllerDoc - notExists: - path: spec.jobTemplate.spec.ttlSecondsAfterFinished - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.template.spec.restartPolicy - value: Never - - - it: custom cronjob configuration should pass - set: - controllers: - main: - type: cronjob - pod: - restartPolicy: OnFailure - cronjob: - suspend: &CronJobSuspended true - schedule: &CronJobSchedule "0 3 * * *" - concurrencyPolicy: &CronJobConcurrencyPolicy "Test" - failedJobsHistory: &CronJobFailedJobsHistory 2 - successfulJobsHistory: &CronJobSuccessfulJobsHistory 3 - ttlSecondsAfterFinished: &ttlSecondsAfterFinished 3600 - parallelism: &CronJobParallelism 3 - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: spec.suspend - value: *CronJobSuspended - - documentIndex: *ControllerDoc - equal: - path: spec.schedule - value: *CronJobSchedule - - documentIndex: *ControllerDoc - equal: - path: spec.concurrencyPolicy - value: *CronJobConcurrencyPolicy - - documentIndex: *ControllerDoc - equal: - path: spec.successfulJobsHistoryLimit - value: *CronJobSuccessfulJobsHistory - - documentIndex: *ControllerDoc - equal: - path: spec.failedJobsHistoryLimit - value: *CronJobFailedJobsHistory - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.ttlSecondsAfterFinished - value: *ttlSecondsAfterFinished - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.template.spec.restartPolicy - value: OnFailure - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.parallelism - value: *CronJobParallelism diff --git a/charts/library/common/test-chart/unittests/controller/default_container_options_test.yaml b/charts/library/common/test-chart/unittests/controller/field_defaultContainerOptions_test.yaml similarity index 79% rename from charts/library/common/test-chart/unittests/controller/default_container_options_test.yaml rename to charts/library/common/test-chart/unittests/controller/field_defaultContainerOptions_test.yaml index e9e91b3b..5d25e209 100644 --- a/charts/library/common/test-chart/unittests/controller/default_container_options_test.yaml +++ b/charts/library/common/test-chart/unittests/controller/field_defaultContainerOptions_test.yaml @@ -1,16 +1,16 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller defaultContainerOptions +suite: controller - fields - defaultContainerOptions templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 notExists: path: spec.template.spec.containers[0].resources @@ -25,12 +25,11 @@ tests: controllers.main.containers.main.resources: requests: memory: 2Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: @@ -47,12 +46,11 @@ tests: controllers.main.containers.main.resources: requests: memory: 2Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: @@ -69,12 +67,11 @@ tests: controllers.main.containers.main.resources: requests: memory: 2Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: @@ -92,18 +89,16 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 1Gi - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.initContainers[0].resources value: requests: @@ -121,16 +116,14 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[0].resources value: requests: memory: 1Gi - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.initContainers[0].resources diff --git a/charts/library/common/test-chart/unittests/controller/field_revisionhistorylimit_test.yaml b/charts/library/common/test-chart/unittests/controller/field_revisionhistorylimit_test.yaml deleted file mode 100644 index f1031f00..00000000 --- a/charts/library/common/test-chart/unittests/controller/field_revisionhistorylimit_test.yaml +++ /dev/null @@ -1,130 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller revisionHistoryLimit -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - # Deployment - - it: default should pass for Deployment - set: - controllers.main.type: deployment - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 3 - - - it: custom revisionHistoryLimit should pass for Deployment - set: - controllers.main: - type: deployment - revisionHistoryLimit: 8 - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 8 - - - it: explicit revisionHistoryLimit 0 should pass for Deployment - set: - controllers.main: - type: deployment - revisionHistoryLimit: 0 - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 0 - - # StatefulSet - - it: default should pass for StatefulSet - set: - controllers.main.type: statefulset - asserts: - - documentIndex: 0 - isKind: - of: StatefulSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 3 - - - it: custom revisionHistoryLimit should pass for StatefulSet - set: - controllers.main: - type: statefulset - revisionHistoryLimit: 8 - asserts: - - documentIndex: 0 - isKind: - of: StatefulSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 8 - - - it: explicit revisionHistoryLimit 0 should pass for StatefulSet - set: - controllers.main: - type: statefulset - revisionHistoryLimit: 0 - asserts: - - documentIndex: 0 - isKind: - of: StatefulSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 0 - - # DaemonSet - - it: default should pass for DaemonSet - set: - controllers.main.type: daemonset - asserts: - - documentIndex: 0 - isKind: - of: DaemonSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 3 - - - it: custom revisionHistoryLimit should pass for DaemonSet - set: - controllers.main: - type: daemonset - revisionHistoryLimit: 8 - asserts: - - documentIndex: 0 - isKind: - of: DaemonSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 8 - - - it: explicit revisionHistoryLimit 0 should pass for DaemonSet - set: - controllers.main: - type: daemonset - revisionHistoryLimit: 0 - asserts: - - documentIndex: 0 - isKind: - of: DaemonSet - - documentIndex: 0 - equal: - path: spec.revisionHistoryLimit - value: 0 diff --git a/charts/library/common/test-chart/unittests/controller/job_test.yaml b/charts/library/common/test-chart/unittests/controller/job_test.yaml deleted file mode 100644 index 5271b323..00000000 --- a/charts/library/common/test-chart/unittests/controller/job_test.yaml +++ /dev/null @@ -1,65 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: job configuration -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default job configuration should pass - set: - controllers: - main: - type: job - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - equal: - path: spec.suspend - value: false - - documentIndex: *ControllerDoc - notExists: - path: spec.ttlSecondsAfterFinished - - documentIndex: *ControllerDoc - equal: - path: spec.template.spec.restartPolicy - value: Never - - - it: custom job configuration should pass - set: - controllers: - main: - type: job - pod: - restartPolicy: OnFailure - job: - suspend: &JobSuspended true - ttlSecondsAfterFinished: &ttlSecondsAfterFinished 3600 - backoffLimit: 3 - parallelism: &JobParallelism 3 - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - equal: - path: spec.suspend - value: *JobSuspended - - documentIndex: *ControllerDoc - equal: - path: spec.ttlSecondsAfterFinished - value: *ttlSecondsAfterFinished - - documentIndex: *ControllerDoc - equal: - path: spec.template.spec.restartPolicy - value: OnFailure - - documentIndex: *ControllerDoc - equal: - path: spec.backoffLimit - value: 3 - - documentIndex: *ControllerDoc - equal: - path: spec.parallelism - value: *JobParallelism diff --git a/charts/library/common/test-chart/unittests/controller/metadata_cronjob_test.yaml b/charts/library/common/test-chart/unittests/controller/metadata_cronjob_test.yaml deleted file mode 100644 index bf5ba4a2..00000000 --- a/charts/library/common/test-chart/unittests/controller/metadata_cronjob_test.yaml +++ /dev/null @@ -1,123 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller metadata cronjob -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -set: - controllers.main.cronjob.schedule: "*/20 * * * *" - -tests: - - it: default metadata should pass - set: - controllers.main.type: cronjob - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - notExists: - path: metadata.annotations - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - controllers: - main: - type: cronjob - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - controllers: - main: - type: cronjob - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: jobTemplate metadata should pass - set: - controllers: - main: - type: cronjob - pod: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.template.metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: spec.jobTemplate.spec.template.metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - test_label: test diff --git a/charts/library/common/test-chart/unittests/controller/metadata_daemonset_test.yaml b/charts/library/common/test-chart/unittests/controller/metadata_daemonset_test.yaml deleted file mode 100644 index 5fdc39d7..00000000 --- a/charts/library/common/test-chart/unittests/controller/metadata_daemonset_test.yaml +++ /dev/null @@ -1,92 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller metadata daemonset -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - controllers.main.type: daemonset - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: DaemonSet - - documentIndex: *ControllerDoc - notExists: - path: metadata.annotations - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - controllers: - main: - type: daemonset - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: DaemonSet - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - controllers: - main: - type: daemonset - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: DaemonSet - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/controller/metadata_deployment_test.yaml b/charts/library/common/test-chart/unittests/controller/metadata_deployment_test.yaml deleted file mode 100644 index 1dee4300..00000000 --- a/charts/library/common/test-chart/unittests/controller/metadata_deployment_test.yaml +++ /dev/null @@ -1,92 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller metadata deployment -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - controllers.main.type: deployment - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - notExists: - path: metadata.annotations - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - controllers: - main: - type: deployment - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - controllers: - main: - type: deployment - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/controller/metadata_job_test.yaml b/charts/library/common/test-chart/unittests/controller/metadata_job_test.yaml deleted file mode 100644 index 21f25bf9..00000000 --- a/charts/library/common/test-chart/unittests/controller/metadata_job_test.yaml +++ /dev/null @@ -1,120 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller metadata job -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - controllers.main.type: job - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - notExists: - path: metadata.annotations - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - controllers: - main: - type: job - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - controllers: - main: - type: job - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: jobTemplate metadata should pass - set: - controllers: - main: - type: job - pod: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Job - - documentIndex: *ControllerDoc - equal: - path: spec.template.metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: spec.template.metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - test_label: test diff --git a/charts/library/common/test-chart/unittests/controller/metadata_statefulset_test.yaml b/charts/library/common/test-chart/unittests/controller/metadata_statefulset_test.yaml deleted file mode 100644 index 6c98b0f4..00000000 --- a/charts/library/common/test-chart/unittests/controller/metadata_statefulset_test.yaml +++ /dev/null @@ -1,92 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller metadata statefulset -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - controllers.main.type: statefulset - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: StatefulSet - - documentIndex: *ControllerDoc - notExists: - path: metadata.annotations - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - controllers: - main: - type: statefulset - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: StatefulSet - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - controllers: - main: - type: statefulset - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: StatefulSet - - documentIndex: *ControllerDoc - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *ControllerDoc - equal: - path: metadata.labels - value: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/controller/presence_test.yaml b/charts/library/common/test-chart/unittests/controller/presence_test.yaml new file mode 100644 index 00000000..7d0311fe --- /dev/null +++ b/charts/library/common/test-chart/unittests/controller/presence_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: controller - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + asserts: + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name + any: true + + - it: multiple controllers should pass + set: + controllers: + second: + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name-main + any: true + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name-second + any: true + + - it: disabled should pass + set: + controllers.main.enabled: false + asserts: + - not: true + containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name + any: true diff --git a/charts/library/common/test-chart/unittests/controller/type_test.yaml b/charts/library/common/test-chart/unittests/controller/type_test.yaml index 159bc3cd..debfd7a8 100644 --- a/charts/library/common/test-chart/unittests/controller/type_test.yaml +++ b/charts/library/common/test-chart/unittests/controller/type_test.yaml @@ -1,138 +1,56 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: controller types +suite: controller - types templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - - it: default should pass + - it: should default to Deployment asserts: - - documentIndex: &deploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *deploymentDoc - equal: - path: metadata.name - value: RELEASE-NAME - - documentIndex: *deploymentDoc - equal: - path: metadata.labels['app.kubernetes.io/component'] - value: main - - - it: additional controllers should pass - set: - controllers: - second: - containers: - main: - image: - repository: ghcr.io/mendhak/http-https-echo - tag: 31 - asserts: - - hasDocuments: - count: 2 - - documentIndex: &firstDeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *firstDeploymentDoc - equal: - path: metadata.name - value: RELEASE-NAME-main - - documentIndex: *firstDeploymentDoc - equal: - path: metadata.labels['app.kubernetes.io/component'] - value: main - - documentIndex: &secondDeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *secondDeploymentDoc - equal: - path: metadata.name - value: RELEASE-NAME-second - - documentIndex: *secondDeploymentDoc - equal: - path: metadata.labels['app.kubernetes.io/component'] - value: second - - - it: additional controllers with nameOverride should pass - set: - controllers: - main: - nameOverride: "{{ .Release.Name }}" - second: - nameOverride: testOverride - containers: - main: - image: - repository: ghcr.io/mendhak/http-https-echo - tag: 31 - asserts: - - hasDocuments: - count: 2 - - documentIndex: &firstDeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *firstDeploymentDoc - equal: - path: metadata.name - value: RELEASE-NAME - - documentIndex: *firstDeploymentDoc - equal: - path: metadata.labels['app.kubernetes.io/component'] - value: main - - documentIndex: &secondDeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *secondDeploymentDoc - equal: - path: metadata.name - value: RELEASE-NAME-testOverride - - documentIndex: *secondDeploymentDoc - equal: - path: metadata.labels['app.kubernetes.io/component'] - value: second + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name + any: true - it: daemonset should pass set: controllers.main.type: daemonset asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: DaemonSet - - documentIndex: *ControllerDoc - equal: - path: metadata.name - value: RELEASE-NAME + - containsDocument: + apiVersion: apps/v1 + kind: DaemonSet + name: release-name + any: true - it: statefulset should pass set: controllers.main.type: statefulset asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: StatefulSet - - documentIndex: *ControllerDoc - equal: - path: metadata.name - value: RELEASE-NAME + - containsDocument: + apiVersion: apps/v1 + kind: StatefulSet + name: release-name + any: true - it: cronjob should pass set: controllers.main.type: cronjob controllers.main.cronjob.schedule: "*/20 * * * *" asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: CronJob - - documentIndex: *ControllerDoc - equal: - path: metadata.name - value: RELEASE-NAME + - containsDocument: + apiVersion: batch/v1 + kind: CronJob + name: release-name + any: true - - it: disabled should pass + - it: job should pass set: - controllers.main.enabled: false + controllers.main.type: job asserts: - - hasDocuments: - count: 0 + - containsDocument: + apiVersion: batch/v1 + kind: Job + name: release-name + any: true diff --git a/charts/library/common/test-chart/unittests/cronjob/field_concurrencyPolicy_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_concurrencyPolicy_test.yaml new file mode 100644 index 00000000..8a9bd30a --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_concurrencyPolicy_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - concurrencyPolicy +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.concurrencyPolicy + value: Forbid + + - it: custom configuration should pass + set: + controllers.main.cronjob.concurrencyPolicy: Test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.concurrencyPolicy + value: Test diff --git a/charts/library/common/test-chart/unittests/cronjob/field_failedJobsHistory_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_failedJobsHistory_test.yaml new file mode 100644 index 00000000..cfa13df8 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_failedJobsHistory_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - failedJobsHistory +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.failedJobsHistoryLimit + value: 1 + + - it: custom configuration should pass + set: + controllers.main.cronjob.failedJobsHistory: 2 + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.failedJobsHistoryLimit + value: 2 diff --git a/charts/library/common/test-chart/unittests/cronjob/field_parallelism_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_parallelism_test.yaml new file mode 100644 index 00000000..ab6a37a2 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_parallelism_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - parallelism +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.parallelism + + - it: custom configuration should pass + set: + controllers.main.cronjob.parallelism: 3 + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.parallelism + value: 3 diff --git a/charts/library/common/test-chart/unittests/cronjob/field_restartPolicy_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_restartPolicy_test.yaml new file mode 100644 index 00000000..88582f81 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_restartPolicy_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - restartPolicy +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.restartPolicy + value: Never + + - it: custom configuration should pass + set: + controllers.main.pod.restartPolicy: OnFailure + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.template.spec.restartPolicy + value: OnFailure diff --git a/charts/library/common/test-chart/unittests/cronjob/field_successfulJobsHistory_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_successfulJobsHistory_test.yaml new file mode 100644 index 00000000..22e4653f --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_successfulJobsHistory_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - successfulJobsHistory +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.successfulJobsHistoryLimit + value: 1 + + - it: custom configuration should pass + set: + controllers.main.cronjob.successfulJobsHistory: 3 + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.successfulJobsHistoryLimit + value: 3 diff --git a/charts/library/common/test-chart/unittests/cronjob/field_suspend_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_suspend_test.yaml new file mode 100644 index 00000000..f9c3c4fe --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_suspend_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - suspend +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.suspend + value: false + + - it: custom configuration should pass + set: + controllers.main.cronjob.suspend: true + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.suspend + value: true diff --git a/charts/library/common/test-chart/unittests/cronjob/field_ttlSecondsAfterFinished_test.yaml b/charts/library/common/test-chart/unittests/cronjob/field_ttlSecondsAfterFinished_test.yaml new file mode 100644 index 00000000..fc87294d --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/field_ttlSecondsAfterFinished_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - fields - ttlSecondsAfterFinished +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: cronjob + controllers.main.cronjob.schedule: "*/20 * * * *" +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.jobTemplate.spec.ttlSecondsAfterFinished + + - it: custom configuration should pass + set: + controllers.main.cronjob.ttlSecondsAfterFinished: 3600 + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.ttlSecondsAfterFinished + value: 3600 diff --git a/charts/library/common/test-chart/unittests/cronjob/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/cronjob/metadata_annotations_test.yaml new file mode 100644 index 00000000..2e1d6dc7 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/metadata_annotations_test.yaml @@ -0,0 +1,49 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: cronjob + cronjob: + schedule: "*/20 * * * *" +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_annotations_test.yaml b/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_annotations_test.yaml new file mode 100644 index 00000000..09debac5 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_annotations_test.yaml @@ -0,0 +1,25 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - jobTemplate - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: cronjob + cronjob: + schedule: "*/20 * * * *" +tests: + - it: jobTemplate metadata should pass + set: + controllers.main.pod.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.template.metadata.annotations + value: + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_labels_test.yaml b/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_labels_test.yaml new file mode 100644 index 00000000..9bb1333c --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/metadata_jobTemplate_labels_test.yaml @@ -0,0 +1,28 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - jobTemplate - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: cronjob + cronjob: + schedule: "*/20 * * * *" +tests: + - it: jobTemplate metadata should pass + set: + controllers.main.pod.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: spec.jobTemplate.spec.template.metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + test_label: test diff --git a/charts/library/common/test-chart/unittests/cronjob/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/cronjob/metadata_labels_test.yaml new file mode 100644 index 00000000..c0956623 --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/metadata_labels_test.yaml @@ -0,0 +1,65 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: cronjob + cronjob: + schedule: "*/20 * * * *" +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "CronJob")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/cronjob/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/cronjob/metadata_name_test.yaml new file mode 100644 index 00000000..d9e188ab --- /dev/null +++ b/charts/library/common/test-chart/unittests/cronjob/metadata_name_test.yaml @@ -0,0 +1,219 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: cronjob - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: cronjob + cronjob: + schedule: "*/20 * * * *" +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name + any: true + + - it: forceRename + set: + controllers.main.forceRename: forceRename + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + controllers.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: common-test + any: true + + - it: prefix + set: + controllers.main.prefix: prefix + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + controllers.main.prefix: "{{ .Chart.Name }}-prefix" + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: common-test-prefix-release-name + any: true + + - it: suffix + set: + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + controllers.main.suffix: "{{ .Chart.Name }}-suffix" + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-common-test-suffix + any: true + + - it: both prefix and suffix + set: + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + controllers.main.forceRename: forceRename + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + controllers: + second: + type: cronjob + cronjob: + schedule: "*/20 * * * *" + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + controllers: + second: + type: cronjob + cronjob: + schedule: "*/20 * * * *" + prefix: prefix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + controllers: + second: + type: cronjob + cronjob: + schedule: "*/20 * * * *" + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + controllers: + second: + type: cronjob + cronjob: + schedule: "*/20 * * * *" + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: CronJob + apiVersion: batch/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + controllers: + second: + type: cronjob + cronjob: + schedule: "*/20 * * * *" + forceRename: forceRename + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/daemonset/field_revisionhistorylimit_test.yaml b/charts/library/common/test-chart/unittests/daemonset/field_revisionhistorylimit_test.yaml new file mode 100644 index 00000000..4e699eff --- /dev/null +++ b/charts/library/common/test-chart/unittests/daemonset/field_revisionhistorylimit_test.yaml @@ -0,0 +1,42 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: daemonset - fields - revisionHistoryLimit +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: daemonset +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 3 + + - it: custom revisionHistoryLimit + set: + controllers.main: + revisionHistoryLimit: 8 + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 8 + + - it: explicit revisionHistoryLimit 0 should pass + set: + controllers.main: + revisionHistoryLimit: 0 + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 0 diff --git a/charts/library/common/test-chart/unittests/daemonset/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/daemonset/metadata_annotations_test.yaml new file mode 100644 index 00000000..d6bdedb9 --- /dev/null +++ b/charts/library/common/test-chart/unittests/daemonset/metadata_annotations_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: daemonset - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: daemonset +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/daemonset/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/daemonset/metadata_labels_test.yaml new file mode 100644 index 00000000..6b47127a --- /dev/null +++ b/charts/library/common/test-chart/unittests/daemonset/metadata_labels_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: daemonset - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: daemonset +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "DaemonSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/daemonset/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/daemonset/metadata_name_test.yaml new file mode 100644 index 00000000..a103396d --- /dev/null +++ b/charts/library/common/test-chart/unittests/daemonset/metadata_name_test.yaml @@ -0,0 +1,206 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: daemonset - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: daemonset +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name + any: true + + - it: forceRename + set: + controllers.main.forceRename: forceRename + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + controllers.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: common-test + any: true + + - it: prefix + set: + controllers.main.prefix: prefix + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + controllers.main.prefix: "{{ .Chart.Name }}-prefix" + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: common-test-prefix-release-name + any: true + + - it: suffix + set: + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + controllers.main.suffix: "{{ .Chart.Name }}-suffix" + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-common-test-suffix + any: true + + - it: both prefix and suffix + set: + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + controllers.main.forceRename: forceRename + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + controllers: + second: + type: daemonset + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + controllers: + second: + type: daemonset + prefix: prefix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + controllers: + second: + type: daemonset + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + controllers: + second: + type: daemonset + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: DaemonSet + apiVersion: apps/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + controllers: + second: + type: daemonset + forceRename: forceRename + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/deployment/field_revisionhistorylimit_test.yaml b/charts/library/common/test-chart/unittests/deployment/field_revisionhistorylimit_test.yaml new file mode 100644 index 00000000..65b6b860 --- /dev/null +++ b/charts/library/common/test-chart/unittests/deployment/field_revisionhistorylimit_test.yaml @@ -0,0 +1,42 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: deployment - fields - revisionHistoryLimit +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: deployment +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 3 + + - it: custom revisionHistoryLimit should pass + set: + controllers.main: + revisionHistoryLimit: 8 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 8 + + - it: explicit revisionHistoryLimit 0 should pass + set: + controllers.main: + revisionHistoryLimit: 0 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 0 diff --git a/charts/library/common/test-chart/unittests/deployment/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/deployment/metadata_annotations_test.yaml new file mode 100644 index 00000000..5d1e6cbc --- /dev/null +++ b/charts/library/common/test-chart/unittests/deployment/metadata_annotations_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: deployment - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: deployment +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/deployment/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/deployment/metadata_labels_test.yaml new file mode 100644 index 00000000..8b2d3420 --- /dev/null +++ b/charts/library/common/test-chart/unittests/deployment/metadata_labels_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: deployment - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: deployment +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/deployment/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/deployment/metadata_name_test.yaml new file mode 100644 index 00000000..e6463956 --- /dev/null +++ b/charts/library/common/test-chart/unittests/deployment/metadata_name_test.yaml @@ -0,0 +1,199 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: deployment - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name + any: true + + - it: forceRename + set: + controllers.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + controllers.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: common-test + any: true + + - it: prefix + set: + controllers.main.prefix: prefix + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + controllers.main.prefix: "{{ .Chart.Name }}-prefix" + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: common-test-prefix-release-name + any: true + + - it: suffix + set: + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + controllers.main.suffix: "{{ .Chart.Name }}-suffix" + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-common-test-suffix + any: true + + - it: both prefix and suffix + set: + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + controllers.main.forceRename: forceRename + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + controllers: + second: + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + controllers: + second: + prefix: prefix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + controllers: + second: + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + controllers: + second: + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + controllers: + second: + forceRename: forceRename + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/ingress/field_hosts_host_test.yaml b/charts/library/common/test-chart/unittests/ingress/field_hosts_host_test.yaml new file mode 100644 index 00000000..e66942a9 --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/field_hosts_host_test.yaml @@ -0,0 +1,53 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: ingress - fields - hosts - host +templates: + - common.yaml +values: + - ../_values/ingress_main_default_hosts.yaml + - ../_values/service_main_default.yaml + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].host + value: chart-example.local + + - it: custom host should pass + set: + ingress.main: + hosts: + - host: chart-test.local + paths: + - path: /test + service: + identifier: main + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].host + value: chart-test.local + + - it: host with template should pass + set: + ingress.main: + hosts: + - host: "{{ .Release.Name }}.hostname" + paths: + - path: / + service: + identifier: main + port: http + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].host + value: RELEASE-NAME.hostname diff --git a/charts/library/common/test-chart/unittests/ingress/field_hosts_paths_path_test.yaml b/charts/library/common/test-chart/unittests/ingress/field_hosts_paths_path_test.yaml new file mode 100644 index 00000000..71814787 --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/field_hosts_paths_path_test.yaml @@ -0,0 +1,52 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: ingress - fields - hosts - paths - path +templates: + - common.yaml +values: + - ../_values/ingress_main_default_hosts.yaml + - ../_values/service_main_default.yaml + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].http.paths[0].path + value: "/" + + - it: custom path should pass + set: + ingress.main: + hosts: + - host: chart-test.local + paths: + - path: /test + service: + identifier: main + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].http.paths[0].path + value: "/test" + + - it: path with template should pass + set: + ingress.main: + hosts: + - host: chart-test.local + paths: + - path: "/{{ .Release.Name }}.path" + service: + identifier: main + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].http.paths[0].path + value: "/RELEASE-NAME.path" diff --git a/charts/library/common/test-chart/unittests/ingress/service_reference_test.yaml b/charts/library/common/test-chart/unittests/ingress/field_hosts_paths_service_test.yaml similarity index 55% rename from charts/library/common/test-chart/unittests/ingress/service_reference_test.yaml rename to charts/library/common/test-chart/unittests/ingress/field_hosts_paths_service_test.yaml index 0892582f..1815eb8b 100644 --- a/charts/library/common/test-chart/unittests/ingress/service_reference_test.yaml +++ b/charts/library/common/test-chart/unittests/ingress/field_hosts_paths_service_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: ingress service reference +suite: ingress - fields - hosts - paths - service templates: - common.yaml values: @@ -15,12 +15,11 @@ tests: ports: http: port: &httpPort 8081 + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].http.paths[0].backend value: service: @@ -38,12 +37,11 @@ tests: service: name: pathService port: 1234 + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].http.paths[0].backend value: service: @@ -59,21 +57,75 @@ tests: paths: - path: / service: - name: "{{ .Release.Name }}" + name: "{{ .Release.Name | lower }}" port: 1234 + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].http.paths[0].backend value: service: - name: RELEASE-NAME + name: release-name port: number: 1234 + - it: automatic service and port reference should pass + set: + service: + main: + controller: main + ports: + http: + port: 8081 + http2: + port: 1880 + ingress: + main: + className: "nginx" + hosts: + - host: http.chart-test.local + paths: + - path: / + pathType: Prefix + - host: http2.chart-test.local + paths: + - path: / + pathType: Prefix + service: + port: http2 + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + # First Ingress host + - equal: + path: spec.rules[0].host + value: http.chart-test.local + - equal: + path: spec.rules[0].http.paths[0].path + value: "/" + - equal: + path: spec.rules[0].http.paths[0].backend.service.name + value: release-name + - equal: + path: spec.rules[0].http.paths[0].backend.service.port.number + value: 8081 + # Second Ingress host + - equal: + path: spec.rules[1].host + value: http2.chart-test.local + - equal: + path: spec.rules[1].http.paths[0].path + value: "/" + - equal: + path: spec.rules[1].http.paths[0].backend.service.name + value: release-name + - equal: + path: spec.rules[1].http.paths[0].backend.service.port.number + value: 1880 + - it: multiple hosts with port name references should pass set: service: @@ -103,41 +155,33 @@ tests: service: identifier: main port: http2 + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress # First Ingress host - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].host value: http.chart-test.local - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].http.paths[0].path value: "/" - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[0].http.paths[0].backend.service.name - value: "RELEASE-NAME" - - documentIndex: *IngressDocument - equal: + value: release-name + - equal: path: spec.rules[0].http.paths[0].backend.service.port.number value: *httpPort # Second Ingress host - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[1].host value: http2.chart-test.local - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[1].http.paths[0].path value: "/" - - documentIndex: *IngressDocument - equal: + - equal: path: spec.rules[1].http.paths[0].backend.service.name - value: "RELEASE-NAME" - - documentIndex: *IngressDocument - equal: + value: release-name + - equal: path: spec.rules[1].http.paths[0].backend.service.port.number value: *http2Port diff --git a/charts/library/common/test-chart/unittests/ingress/tls_test.yaml b/charts/library/common/test-chart/unittests/ingress/field_tls_test.yaml similarity index 63% rename from charts/library/common/test-chart/unittests/ingress/tls_test.yaml rename to charts/library/common/test-chart/unittests/ingress/field_tls_test.yaml index 64a2207f..bf2364f2 100644 --- a/charts/library/common/test-chart/unittests/ingress/tls_test.yaml +++ b/charts/library/common/test-chart/unittests/ingress/field_tls_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: ingress tls +suite: ingress - fields - tls templates: - common.yaml values: @@ -8,12 +8,11 @@ values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - notExists: + - notExists: path: spec.tls - it: tls enabled should pass @@ -23,12 +22,11 @@ tests: - secretName: test hosts: - hostname + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.tls[0] value: secretName: test @@ -41,12 +39,11 @@ tests: tls: - hosts: - hostname + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.tls[0] value: hosts: @@ -56,18 +53,17 @@ tests: set: ingress.main: tls: - - secretName: "{{ .Release.Name }}-secret" + - secretName: "{{ .Release.Name | lower }}-secret" hosts: - hostname + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.tls[0] value: - secretName: RELEASE-NAME-secret + secretName: release-name-secret hosts: - hostname @@ -78,12 +74,11 @@ tests: - secretName: '{{ "" }}' hosts: - hostname + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: + - equal: path: spec.tls[0] value: hosts: diff --git a/charts/library/common/test-chart/unittests/ingress/fiield_defaultBackend_test.yaml b/charts/library/common/test-chart/unittests/ingress/fiield_defaultBackend_test.yaml new file mode 100644 index 00000000..2da2a128 --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/fiield_defaultBackend_test.yaml @@ -0,0 +1,31 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: ingress - fields - defaultBackend +templates: + - common.yaml +values: + - ../_values/ingress_main_default_hosts.yaml + - ../_values/service_main_default.yaml + - ../_values/controllers_main_default_container.yaml +tests: + - it: with defaultBackend should pass + set: + ingress.main: + defaultBackend: + resource: + apiGroup: k8s.example.com + kind: StorageBucket + name: static-assets + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: spec.defaultBackend + value: + resource: + apiGroup: k8s.example.com + kind: StorageBucket + name: static-assets + - notExists: + path: spec.rules diff --git a/charts/library/common/test-chart/unittests/ingress/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/ingress/metadata_annotations_test.yaml new file mode 100644 index 00000000..e0477a9e --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/metadata_annotations_test.yaml @@ -0,0 +1,61 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: "ingress - metadata - annotations" +templates: + - common.yaml +values: + - ../_values/ingress_main_default_hosts.yaml + - ../_values/controllers_main_default_container.yaml +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + ingress.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + ingress.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test + + - it: custom annotations with templates + set: + ingress.main.annotations: + template_annotation1: "{{ .Release.Name | lower }}" + template_annotation2: "{{ .Chart.Name | lower }}" + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations["template_annotation1"] + value: release-name + - equal: + path: metadata.annotations["template_annotation2"] + value: common-test diff --git a/charts/library/common/test-chart/unittests/ingress/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/ingress/metadata_labels_test.yaml new file mode 100644 index 00000000..52883942 --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/metadata_labels_test.yaml @@ -0,0 +1,74 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: "ingress - metadata - labels" +templates: + - common.yaml +values: + - ../_values/ingress_main_default_hosts.yaml + - ../_values/controllers_main_default_container.yaml +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + ingress.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + ingress.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels with templates + set: + ingress.main.labels: + template_label1: "{{ .Release.Name | lower }}" + template_label2: "{{ .Chart.Name | lower }}" + documentSelector: + path: $[?(@.kind == "Ingress")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels["template_label1"] + value: release-name + - equal: + path: metadata.labels["template_label2"] + value: common-test diff --git a/charts/library/common/test-chart/unittests/ingress/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/ingress/metadata_name_test.yaml new file mode 100644 index 00000000..34d68cec --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/metadata_name_test.yaml @@ -0,0 +1,211 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: ingress - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/ingress_main_default_hosts.yaml + - ../_values/service_main_default.yaml +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name + any: true + + - it: forceRename + set: + ingress.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + ingress.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: common-test + any: true + + - it: prefix + set: + ingress.main.prefix: prefix + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + ingress.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: common-test-release-name + any: true + + - it: suffix + set: + ingress.main.suffix: suffix + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + ingress.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + ingress.main.prefix: prefix + ingress.main.suffix: suffix + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + ingress.main.forceRename: forceRename + ingress.main.prefix: prefix + ingress.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + ingress: + second: + hosts: + - host: "chart-example.local" + paths: + - path: / + service: + name: RELEASE-NAME + port: 8081 + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + ingress: + second: + prefix: prefix + hosts: + - host: "chart-example.local" + paths: + - path: / + service: + name: RELEASE-NAME + port: 8081 + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + ingress: + second: + suffix: suffix + hosts: + - host: "chart-example.local" + paths: + - path: / + service: + name: RELEASE-NAME + port: 8081 + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + ingress: + second: + prefix: prefix + suffix: suffix + hosts: + - host: "chart-example.local" + paths: + - path: / + service: + name: RELEASE-NAME + port: 8081 + asserts: + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + ingress: + second: + forceRename: forceRename + prefix: prefix + suffix: suffix + hosts: + - host: "chart-example.local" + paths: + - path: / + service: + name: RELEASE-NAME + port: 8081 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/ingress/metadata_test.yaml b/charts/library/common/test-chart/unittests/ingress/metadata_test.yaml deleted file mode 100644 index 0db936d6..00000000 --- a/charts/library/common/test-chart/unittests/ingress/metadata_test.yaml +++ /dev/null @@ -1,115 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: ingress metadata -templates: - - common.yaml -values: - - ../_values/ingress_main_default_hosts.yaml - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - notExists: - path: metadata.annotations - - documentIndex: *IngressDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - ingress.main: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *IngressDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - ingress.main: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *IngressDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test - - - - it: custom metadata with templates should pass - set: - ingress.main: - annotations: - template_annotation1: "{{ .Release.Name | lower }}" - template_annotation2: "{{ .Chart.Name | lower }}" - labels: - template_label1: "{{ .Release.Name | lower }}" - template_label2: "{{ .Chart.Name | lower }}" - asserts: - - documentIndex: &IngressDocument 1 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: metadata.annotations["template_annotation1"] - value: release-name - - documentIndex: *IngressDocument - equal: - path: metadata.annotations["template_annotation2"] - value: common-test - - documentIndex: *IngressDocument - equal: - path: metadata.labels["template_label1"] - value: release-name - - documentIndex: *IngressDocument - equal: - path: metadata.labels["template_label2"] - value: common-test diff --git a/charts/library/common/test-chart/unittests/ingress/presence_test.yaml b/charts/library/common/test-chart/unittests/ingress/presence_test.yaml index 6201f767..bcefc734 100644 --- a/charts/library/common/test-chart/unittests/ingress/presence_test.yaml +++ b/charts/library/common/test-chart/unittests/ingress/presence_test.yaml @@ -1,20 +1,18 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: ingress presence +suite: ingress - presence templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml - - ../_values/controllers_main_default_container.yaml tests: - it: default should pass asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: Ingress + - not: true + containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + any: true - it: explicitly disabled should pass values: @@ -22,12 +20,11 @@ tests: set: ingress.main.enabled: false asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: Ingress + - not: true + containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + any: true - it: explicitly enabled should pass values: @@ -35,15 +32,11 @@ tests: set: ingress.main.enabled: true asserts: - - hasDocuments: - count: 2 - - documentIndex: 0 - not: true - isKind: - of: Ingress - - documentIndex: 1 - isKind: - of: Ingress + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: release-name + any: true - it: multiple ingress should pass values: @@ -59,30 +52,16 @@ tests: identifier: main port: http asserts: - - hasDocuments: - count: 4 - - documentIndex: 0 - not: true - isKind: - of: Ingress - - documentIndex: 1 - not: true - isKind: - of: Ingress - - documentIndex: &FirstIngressDocument 2 - isKind: - of: Ingress - - documentIndex: *FirstIngressDocument - equal: - path: metadata.name - value: RELEASE-NAME-main - - documentIndex: &SecondIngressDocument 3 - isKind: - of: Ingress - - documentIndex: *SecondIngressDocument - equal: - path: metadata.name - value: RELEASE-NAME-test + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: release-name-main + any: true + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: release-name-test + any: true - it: multiple ingress with explicit disabled should pass values: @@ -98,16 +77,14 @@ tests: identifier: main port: http asserts: - - hasDocuments: - count: 2 - - documentIndex: 0 - not: true - isKind: - of: Ingress - - documentIndex: &FirstIngressDocument 1 - isKind: - of: Ingress - - documentIndex: *FirstIngressDocument - equal: - path: metadata.name - value: RELEASE-NAME + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: release-name + any: true + - not: true + containsDocument: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: release-name-test + any: true diff --git a/charts/library/common/test-chart/unittests/ingress/validations_test.yaml b/charts/library/common/test-chart/unittests/ingress/validations_test.yaml new file mode 100644 index 00000000..19955024 --- /dev/null +++ b/charts/library/common/test-chart/unittests/ingress/validations_test.yaml @@ -0,0 +1,55 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: ingress - validations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: service reference to non-existing service should fail + set: + ingress.main.hosts: + - host: "chart-example.local" + paths: + - path: / + service: + identifier: main + port: 8081 + asserts: + - failedTemplate: + errorMessage: "No enabled Service found with this identifier. (ingress: 'main', path: '/', identifier: 'main')" + + - it: automatic service determination should fail when no service is enabled + set: + ingress.main.hosts: + - host: "chart-example.local" + paths: + - path: / + service: + port: 8081 + asserts: + - failedTemplate: + errorMessage: "Either service.name or service.identifier is required because automatic Service detection is not possible. (ingress: main, host: chart-example.local, path: /)" + + - it: automatic service determination should fail when >1 service is enabled + set: + service: + main: + controller: main + ports: + ui: + port: 8082 + second: + controller: main + ports: + ui: + port: 8082 + ingress.main.hosts: + - host: "chart-example.local" + paths: + - path: / + service: + port: 8081 + asserts: + - failedTemplate: + errorMessage: "Either service.name or service.identifier is required because automatic Service detection is not possible. (ingress: main, host: chart-example.local, path: /)" diff --git a/charts/library/common/test-chart/unittests/ingress/values_test.yaml b/charts/library/common/test-chart/unittests/ingress/values_test.yaml deleted file mode 100644 index 4e3f778b..00000000 --- a/charts/library/common/test-chart/unittests/ingress/values_test.yaml +++ /dev/null @@ -1,132 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: ingress values -templates: - - common.yaml -values: - - ../_values/ingress_main_default_hosts.yaml - - ../_values/service_main_default.yaml - - ../_values/controllers_main_default_container.yaml -tests: - - it: default should pass - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].host - value: chart-example.local - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].http.paths[0].path - value: "/" - - - it: nameOverride should pass - set: - ingress.main: - nameOverride: test - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: metadata.name - value: RELEASE-NAME-test - - - it: nameOverride with template should pass - set: - ingress.main: - nameOverride: "{{ .Release.Name }}" - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: metadata.name - value: RELEASE-NAME - - - it: custom host and path should pass - set: - ingress.main: - hosts: - - host: chart-test.local - paths: - - path: /test - service: - identifier: main - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].host - value: chart-test.local - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].http.paths[0].path - value: "/test" - - - it: host with template should pass - set: - ingress.main: - hosts: - - host: "{{ .Release.Name }}.hostname" - paths: - - path: / - service: - identifier: main - port: http - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].host - value: RELEASE-NAME.hostname - - - it: path with template should pass - set: - ingress.main: - hosts: - - host: chart-test.local - paths: - - path: "/{{ .Release.Name }}.path" - service: - identifier: main - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: spec.rules[0].http.paths[0].path - value: "/RELEASE-NAME.path" - - - it: with defaultBackend should pass - set: - ingress.main: - defaultBackend: - resource: - apiGroup: k8s.example.com - kind: StorageBucket - name: static-assets - asserts: - - documentIndex: &IngressDocument 2 - isKind: - of: Ingress - - documentIndex: *IngressDocument - equal: - path: spec.defaultBackend - value: - resource: - apiGroup: k8s.example.com - kind: StorageBucket - name: static-assets - - documentIndex: *IngressDocument - notExists: - path: spec.rules diff --git a/charts/library/common/test-chart/unittests/job/field_backoffLimit_test.yaml b/charts/library/common/test-chart/unittests/job/field_backoffLimit_test.yaml new file mode 100644 index 00000000..ff378276 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/field_backoffLimit_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - fields - backoffLimit +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.backoffLimit + value: 6 + + - it: custom configuration should pass + set: + controllers.main.job.backoffLimit: 3 + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.backoffLimit + value: 3 diff --git a/charts/library/common/test-chart/unittests/job/field_parallelism_test.yaml b/charts/library/common/test-chart/unittests/job/field_parallelism_test.yaml new file mode 100644 index 00000000..cb56b51f --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/field_parallelism_test.yaml @@ -0,0 +1,28 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - fields - parallelism +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.parallelism + + - it: custom configuration should pass + set: + controllers.main.job.parallelism: 3 + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.parallelism + value: 3 diff --git a/charts/library/common/test-chart/unittests/job/field_restartPolicy_test.yaml b/charts/library/common/test-chart/unittests/job/field_restartPolicy_test.yaml new file mode 100644 index 00000000..da3df171 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/field_restartPolicy_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - fields - restartPolicy +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.restartPolicy + value: Never + + - it: custom configuration should pass + set: + controllers.main.pod.restartPolicy: OnFailure + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.restartPolicy + value: OnFailure diff --git a/charts/library/common/test-chart/unittests/job/field_suspend_test.yaml b/charts/library/common/test-chart/unittests/job/field_suspend_test.yaml new file mode 100644 index 00000000..16c307ca --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/field_suspend_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - fields - suspend +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.suspend + value: false + + - it: custom configuration should pass + set: + controllers.main.job.suspend: true + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.suspend + value: true diff --git a/charts/library/common/test-chart/unittests/job/field_ttlSecondsAfterFinished_test.yaml b/charts/library/common/test-chart/unittests/job/field_ttlSecondsAfterFinished_test.yaml new file mode 100644 index 00000000..969c4371 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/field_ttlSecondsAfterFinished_test.yaml @@ -0,0 +1,28 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - fields - ttlSecondsAfterFinished +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: default configuration should pass + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.ttlSecondsAfterFinished + + - it: custom configuration should pass + set: + controllers.main.job.ttlSecondsAfterFinished: 3600 + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.ttlSecondsAfterFinished + value: 3600 diff --git a/charts/library/common/test-chart/unittests/job/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/job/metadata_annotations_test.yaml new file mode 100644 index 00000000..0cb4d859 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/metadata_annotations_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: job +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_annotations_test.yaml b/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_annotations_test.yaml new file mode 100644 index 00000000..63332859 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_annotations_test.yaml @@ -0,0 +1,23 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - jobTemplate - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: job +tests: + - it: jobTemplate metadata should pass + set: + controllers.main.pod.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.metadata.annotations + value: + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_labels_test.yaml b/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_labels_test.yaml new file mode 100644 index 00000000..8baa3496 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/metadata_jobTemplate_labels_test.yaml @@ -0,0 +1,26 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - jobTemplate - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: job +tests: + - it: jobTemplate metadata should pass + set: + controllers.main.pod.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + test_label: test diff --git a/charts/library/common/test-chart/unittests/job/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/job/metadata_labels_test.yaml new file mode 100644 index 00000000..8b81a7b6 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/metadata_labels_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: job +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Job")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/job/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/job/metadata_name_test.yaml new file mode 100644 index 00000000..a7d2f8f2 --- /dev/null +++ b/charts/library/common/test-chart/unittests/job/metadata_name_test.yaml @@ -0,0 +1,206 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: job - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: job +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name + any: true + + - it: forceRename + set: + controllers.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + controllers.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: common-test + any: true + + - it: prefix + set: + controllers.main.prefix: prefix + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + controllers.main.prefix: "{{ .Chart.Name }}-prefix" + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: common-test-prefix-release-name + any: true + + - it: suffix + set: + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + controllers.main.suffix: "{{ .Chart.Name }}-suffix" + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-common-test-suffix + any: true + + - it: both prefix and suffix + set: + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + controllers.main.forceRename: forceRename + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + controllers: + second: + type: job + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + controllers: + second: + type: job + prefix: prefix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + controllers: + second: + type: job + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + controllers: + second: + type: job + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: release-name-main + any: true + - containsDocument: + kind: Job + apiVersion: batch/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + controllers: + second: + type: job + forceRename: forceRename + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/misc/nameoverride_test.yaml b/charts/library/common/test-chart/unittests/misc/nameoverride_test.yaml index 61ede15a..84c35690 100644 --- a/charts/library/common/test-chart/unittests/misc/nameoverride_test.yaml +++ b/charts/library/common/test-chart/unittests/misc/nameoverride_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: nameOverride tests +suite: misc - global nameOverride test templates: - common.yaml values: @@ -8,22 +8,18 @@ values: tests: - it: default name is set to release name asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: metadata.name - value: RELEASE-NAME + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name + any: true - it: global.nameOverride can be set set: global.nameOverride: custom-name asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: metadata.name - value: RELEASE-NAME-custom-name + - containsDocument: + apiVersion: apps/v1 + kind: Deployment + name: release-name-custom-name + any: true diff --git a/charts/library/common/test-chart/unittests/networkpolicy/field_podselector_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/field_podselector_test.yaml new file mode 100644 index 00000000..6a53f376 --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/field_podselector_test.yaml @@ -0,0 +1,46 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: networkPolicy - fields - podSelector +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: networkpolicy targets the correct controller by default + set: + networkpolicies: + main: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: spec.podSelector + value: + matchLabels: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + + - it: networkpolicy targets supports custom podSelector + set: + networkpolicies: + main: + controller: main + policyTypes: + - Ingress + - Egress + podSelector: {} + rules: {} + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: spec.podSelector + value: {} diff --git a/charts/library/common/test-chart/unittests/networkpolicy/field_rules_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/field_rules_test.yaml new file mode 100644 index 00000000..73cc0c71 --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/field_rules_test.yaml @@ -0,0 +1,33 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: networkPolicy - fields - rules +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: networkpolicy rules are passed through + set: + networkpolicies: + main: + controller: main + policyTypes: + - Ingress + - Egress + rules: + ingress: + - {} + egress: + - {} + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: spec.ingress + value: + - {} + - equal: + path: spec.egress + value: + - {} diff --git a/charts/library/common/test-chart/unittests/networkpolicy/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/metadata_annotations_test.yaml new file mode 100644 index 00000000..0ca09103 --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/metadata_annotations_test.yaml @@ -0,0 +1,51 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: "networkPolicy - metadata - annotations" +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + networkpolicies.main: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + networkpolicies.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + networkpolicies.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/networkpolicy/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/metadata_labels_test.yaml new file mode 100644 index 00000000..663bf30f --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/metadata_labels_test.yaml @@ -0,0 +1,64 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: "networkPolicy - metadata - labels" +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + networkpolicies.main: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + networkpolicies.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + networkpolicies.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "NetworkPolicy")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/networkpolicy/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/metadata_name_test.yaml new file mode 100644 index 00000000..287e9bbc --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/metadata_name_test.yaml @@ -0,0 +1,201 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: networkPolicy - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + networkpolicies.main: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name + any: true + + - it: forceRename + set: + networkpolicies.main.forceRename: forceRename + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + networkpolicies.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: common-test + any: true + + - it: prefix + set: + networkpolicies.main.prefix: prefix + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + networkpolicies.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: common-test-release-name + any: true + + - it: suffix + set: + networkpolicies.main.suffix: suffix + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + networkpolicies.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + networkpolicies.main.prefix: prefix + networkpolicies.main.suffix: suffix + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + networkpolicies.main.forceRename: forceRename + networkpolicies.main.prefix: prefix + networkpolicies.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + networkpolicies.second: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + networkpolicies.second: + prefix: prefix + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + networkpolicies.second: + suffix: suffix + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + networkpolicies.second: + prefix: prefix + suffix: suffix + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: release-name-main + any: true + - containsDocument: + kind: NetworkPolicy + apiVersion: networking.k8s.io/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + networkpolicies.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/networkpolicy/metadata_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/metadata_test.yaml deleted file mode 100644 index c543d078..00000000 --- a/charts/library/common/test-chart/unittests/networkpolicy/metadata_test.yaml +++ /dev/null @@ -1,94 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: networkPolicy metadata - -set: - networkpolicies.main: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - notExists: - path: metadata.annotations - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - networkpolicies: - main: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - networkpolicies: - main: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/networkpolicy/names_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/names_test.yaml deleted file mode 100644 index 8bea3596..00000000 --- a/charts/library/common/test-chart/unittests/networkpolicy/names_test.yaml +++ /dev/null @@ -1,85 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: networkPolicy names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default should pass - set: - networkpolicies: - main: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - asserts: - - hasDocuments: - count: 2 - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.name - value: RELEASE-NAME - - - it: custom name suffix should pass - set: - networkpolicies: - main: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - nameOverride: block-ingress - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: metadata.name - value: RELEASE-NAME-block-ingress - - - it: multiple networkpolicies can be enabled - set: - networkpolicies: - primary: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - secondary: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - asserts: - - hasDocuments: - count: 3 - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: &firstNetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *firstNetworkPolicyDocument - equal: - path: metadata.name - value: RELEASE-NAME-primary - - documentIndex: 2 - isKind: - of: NetworkPolicy - - documentIndex: &secondNetworkPolicyDocument 2 - isKind: - of: NetworkPolicy - - documentIndex: *secondNetworkPolicyDocument - equal: - path: metadata.name - value: RELEASE-NAME-secondary diff --git a/charts/library/common/test-chart/unittests/networkpolicy/presence_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/presence_test.yaml new file mode 100644 index 00000000..78f9cedf --- /dev/null +++ b/charts/library/common/test-chart/unittests/networkpolicy/presence_test.yaml @@ -0,0 +1,57 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: networkPolicy - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: main networkpolicy is disabled by default + asserts: + - not: true + containsDocument: + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + any: true + + - it: main networkpolicy can be enabled + set: + networkpolicies.main: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + name: release-name + any: true + + - it: multiple networkpolicies can be enabled + set: + networkpolicies: + primary: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + secondary: + controller: main + policyTypes: + - Ingress + - Egress + rules: {} + asserts: + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + name: release-name-primary + any: true + - containsDocument: + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + name: release-name-secondary + any: true diff --git a/charts/library/common/test-chart/unittests/networkpolicy/validations_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/validations_test.yaml index 034d391f..23576871 100644 --- a/charts/library/common/test-chart/unittests/networkpolicy/validations_test.yaml +++ b/charts/library/common/test-chart/unittests/networkpolicy/validations_test.yaml @@ -1,17 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: NetworkPolicy validations +suite: networkPolicy - validations templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml +set: + networkpolicies: + main: + controller: "" + rules: {} tests: - it: networkpolicy requires either controller reference or podSelector - set: - networkpolicies: - main: - controller: "" - rules: {} asserts: - failedTemplate: errorMessage: "controller reference or podSelector is required for NetworkPolicy. (NetworkPolicy main)" @@ -22,7 +22,6 @@ tests: main: controller: main policyTypes: [] - rules: {} asserts: - failedTemplate: errorMessage: "policyTypes is required for NetworkPolicy. (NetworkPolicy main)" @@ -34,7 +33,6 @@ tests: controller: main policyTypes: - test - rules: {} asserts: - failedTemplate: errorMessage: "Not a valid policyType for NetworkPolicy. (NetworkPolicy main, value test)" diff --git a/charts/library/common/test-chart/unittests/networkpolicy/values_test.yaml b/charts/library/common/test-chart/unittests/networkpolicy/values_test.yaml deleted file mode 100644 index 8c499562..00000000 --- a/charts/library/common/test-chart/unittests/networkpolicy/values_test.yaml +++ /dev/null @@ -1,103 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: NetworkPolicy values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: main networkpolicy is disabled by default - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: NetworkPolicy - - - it: main networkpolicy can be enabled - set: - networkpolicies.main: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - asserts: - - hasDocuments: - count: 2 - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 1 - isKind: - of: NetworkPolicy - - - it: networkpolicy targets the correct controller - set: - networkpolicies: - main: - controller: main - policyTypes: - - Ingress - - Egress - rules: {} - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: spec.podSelector - value: - matchLabels: - app.kubernetes.io/component: main - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - - - it: networkpolicy targets supports custom podSelector - set: - networkpolicies: - main: - controller: main - policyTypes: - - Ingress - - Egress - podSelector: {} - rules: {} - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: spec.podSelector - value: {} - - - it: networkpolicy rules are passed through - set: - networkpolicies: - main: - controller: main - policyTypes: - - Ingress - - Egress - rules: - ingress: - - {} - egress: - - {} - asserts: - - documentIndex: &NetworkPolicyDocument 1 - isKind: - of: NetworkPolicy - - documentIndex: *NetworkPolicyDocument - equal: - path: spec.ingress - value: - - {} - - documentIndex: *NetworkPolicyDocument - equal: - path: spec.egress - value: - - {} diff --git a/charts/library/common/test-chart/unittests/persistence/secret_test.yaml b/charts/library/common/test-chart/unittests/persistence/secret_test.yaml deleted file mode 100644 index 92fd4075..00000000 --- a/charts/library/common/test-chart/unittests/persistence/secret_test.yaml +++ /dev/null @@ -1,77 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence secret -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: secret persistence type should pass - set: - persistence: - secret: - enabled: true - type: secret - name: mySettings - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.template.spec.volumes[0] - value: - name: secret - secret: - secretName: mySettings - - - it: secret persistence type with name template should pass - set: - persistence: - secret: - enabled: true - type: secret - name: "{{ .Release.Name }}-config" - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.template.spec.volumes[0] - value: - name: secret - secret: - secretName: RELEASE-NAME-config - - - it: secret persistence type with identifier reference should pass - set: - secrets: - mySettings: - stringData: - test: testvalue - persistence: - secret: - type: secret - identifier: mySettings - asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: - path: spec.template.spec.volumes[0] - value: - name: secret - secret: - secretName: RELEASE-NAME-mySettings - - - it: secret persistence type with invalid identifier reference should fail - set: - persistence: - secret: - type: secret - identifier: doesNotExist - asserts: - - failedTemplate: - errorMessage: "No secret found with this identifier. (persistence item 'secret', identifier 'doesNotExist')" diff --git a/charts/library/common/test-chart/unittests/persistence/validations_test.yaml b/charts/library/common/test-chart/unittests/persistence/validations_test.yaml new file mode 100644 index 00000000..0ea9f4a8 --- /dev/null +++ b/charts/library/common/test-chart/unittests/persistence/validations_test.yaml @@ -0,0 +1,27 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: persistence - validations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: configmap persistence type with invalid identifier reference should fail + set: + persistence: + configmap: + type: configMap + identifier: doesNotExist + asserts: + - failedTemplate: + errorMessage: "No configmap found with this identifier. (persistence item 'configmap', identifier 'doesNotExist')" + + - it: secret persistence type with invalid identifier reference should fail + set: + persistence: + secret: + type: secret + identifier: doesNotExist + asserts: + - failedTemplate: + errorMessage: "No secret found with this identifier. (persistence item 'secret', identifier 'doesNotExist')" diff --git a/charts/library/common/test-chart/unittests/pod/field_affinity_test.yaml b/charts/library/common/test-chart/unittests/pod/field_affinity_test.yaml index b54b73aa..b4436be9 100644 --- a/charts/library/common/test-chart/unittests/pod/field_affinity_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_affinity_test.yaml @@ -1,15 +1,15 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod affinity +suite: pod - fields - affinity templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: affinity is not present by default - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - notExists: path: spec.template.spec.affinity @@ -27,7 +27,9 @@ tests: values: - antarctica-east1 - antarctica-west1 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.affinity @@ -68,7 +70,9 @@ tests: values: - asia-east1 - asia-west1 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.affinity @@ -96,9 +100,11 @@ tests: - key: app operator: In values: - - "{{ .Release.Name }}" + - "{{ .Release.Name | lower }}" topologyKey: kubernetes.io/hostname - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.affinity @@ -110,5 +116,5 @@ tests: - key: app operator: In values: - - RELEASE-NAME + - release-name topologyKey: kubernetes.io/hostname diff --git a/charts/library/common/test-chart/unittests/pod/additional_containers_test.yaml b/charts/library/common/test-chart/unittests/pod/field_containers_multiple_test.yaml similarity index 69% rename from charts/library/common/test-chart/unittests/pod/additional_containers_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_containers_multiple_test.yaml index 0cf5149e..6dcce860 100644 --- a/charts/library/common/test-chart/unittests/pod/additional_containers_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_containers_multiple_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod with multiple containers +suite: pod - fields - containers - multiple templates: - common.yaml values: @@ -15,12 +15,11 @@ tests: image: repository: test tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[1].name value: template-test @@ -32,12 +31,11 @@ tests: image: repository: test tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[1].name value: additional1 @@ -45,19 +43,18 @@ tests: set: controllers.main.containers: additional1: - nameOverride: "{{ .Release.Name }}-container" + nameOverride: "{{ .Release.Name | lower }}-container" dependsOn: main image: repository: test tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.containers[1].name - value: RELEASE-NAME-container + value: release-name-container - it: with custom env vars dict should pass set: @@ -74,38 +71,33 @@ tests: int: 1 float: 1.5 string: value_of_env - template: "{{ .Release.Name }}-admin" + template: "{{ .Release.Name | lower }}-admin" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[0].env[0] value: name: main_env value: "value" - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].env[0] value: name: float value: "1.5" - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].env[1] value: name: int value: "1" - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].env[2] value: name: string value: value_of_env - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].env[3] value: name: template - value: RELEASE-NAME-admin + value: release-name-admin diff --git a/charts/library/common/test-chart/unittests/pod/container_order_test.yaml b/charts/library/common/test-chart/unittests/pod/field_containers_order_test.yaml similarity index 69% rename from charts/library/common/test-chart/unittests/pod/container_order_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_containers_order_test.yaml index f8aff3f1..e8e74099 100644 --- a/charts/library/common/test-chart/unittests/pod/container_order_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_containers_order_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod sidecar containers +suite: pod - fields - containers - order templates: - common.yaml values: @@ -21,24 +21,20 @@ tests: image: repository: test tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - lengthEqual: + - lengthEqual: path: spec.template.spec.containers count: 3 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[0].name value: additional1 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].name value: additional2 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[2].name value: main @@ -60,27 +56,22 @@ tests: image: repository: test tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - lengthEqual: + - lengthEqual: path: spec.template.spec.containers count: 4 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[0].name value: main - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[1].name value: additional3 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[2].name value: additional1 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.containers[3].name value: additional2 diff --git a/charts/library/common/test-chart/unittests/pod/field_dnsConfig_test.yaml b/charts/library/common/test-chart/unittests/pod/field_dnsConfig_test.yaml index 4a83032f..546c46ff 100644 --- a/charts/library/common/test-chart/unittests/pod/field_dnsConfig_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_dnsConfig_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod dnsConfig +suite: pod - fields - dnsConfig templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.dnsConfig - it: defaultPodOption should pass @@ -22,12 +21,11 @@ tests: options: - name: ndots value: "1" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.dnsConfig value: options: @@ -48,12 +46,11 @@ tests: options: - name: ndots value: "5" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.dnsConfig value: options: diff --git a/charts/library/common/test-chart/unittests/pod/field_dnsPolicy_test.yaml b/charts/library/common/test-chart/unittests/pod/field_dnsPolicy_test.yaml index 25d64e86..d6418ccf 100644 --- a/charts/library/common/test-chart/unittests/pod/field_dnsPolicy_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_dnsPolicy_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod dnsPolicy +suite: pod - fields - dnsPolicy templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.dnsPolicy value: ClusterFirst @@ -20,12 +19,11 @@ tests: set: defaultPodOptions: hostNetwork: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.dnsPolicy value: ClusterFirstWithHostNet @@ -33,11 +31,10 @@ tests: set: defaultPodOptions: dnsPolicy: None + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.dnsPolicy value: None diff --git a/charts/library/common/test-chart/unittests/pod/field_enableServiceLinks_test.yaml b/charts/library/common/test-chart/unittests/pod/field_enableServiceLinks_test.yaml index 43490b2e..2846b8dd 100644 --- a/charts/library/common/test-chart/unittests/pod/field_enableServiceLinks_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_enableServiceLinks_test.yaml @@ -1,41 +1,38 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod enableServiceLinks +suite: pod - fields - enableServiceLinks templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.enableServiceLinks value: false - it: enabled in defaultPodOptions should pass set: defaultPodOptions.enableServiceLinks: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.enableServiceLinks value: true - it: enabled in pod options should pass set: controllers.main.pod.enableServiceLinks: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.enableServiceLinks value: true diff --git a/charts/library/common/test-chart/unittests/pod/field_hostAliases_test.yaml b/charts/library/common/test-chart/unittests/pod/field_hostAliases_test.yaml index 66348bc9..6de0522e 100644 --- a/charts/library/common/test-chart/unittests/pod/field_hostAliases_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_hostAliases_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod hostAliases +suite: pod - fields - hostAliases templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.hostAliases - it: defaultPodOption should pass @@ -23,12 +22,11 @@ tests: hostnames: - "example.com" - "www.example.com" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostAliases value: - ip: "192.168.1.100" @@ -51,12 +49,11 @@ tests: - ip: "127.0.0.1" hostnames: - "localhost" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostAliases value: - ip: "127.0.0.1" diff --git a/charts/library/common/test-chart/unittests/pod/field_hostIPC_test.yaml b/charts/library/common/test-chart/unittests/pod/field_hostIPC_test.yaml index 6f04e97d..a7220098 100644 --- a/charts/library/common/test-chart/unittests/pod/field_hostIPC_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_hostIPC_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod security +suite: pod - fields - hostIPC templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostIPC value: false @@ -20,12 +19,11 @@ tests: set: defaultPodOptions: hostIPC: false + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostIPC value: false @@ -33,10 +31,10 @@ tests: set: defaultPodOptions: hostIPC: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 equal: path: spec.template.spec.hostIPC diff --git a/charts/library/common/test-chart/unittests/pod/field_hostNetwork_test.yaml b/charts/library/common/test-chart/unittests/pod/field_hostNetwork_test.yaml index 6077e351..9d5bde36 100644 --- a/charts/library/common/test-chart/unittests/pod/field_hostNetwork_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_hostNetwork_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod hostNetwork +suite: pod - fields - hostNetwork templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostNetwork value: false @@ -20,12 +19,11 @@ tests: set: defaultPodOptions: hostNetwork: false + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostNetwork value: false @@ -33,10 +31,10 @@ tests: set: defaultPodOptions: hostNetwork: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 equal: path: spec.template.spec.hostNetwork diff --git a/charts/library/common/test-chart/unittests/pod/field_hostPID_test.yaml b/charts/library/common/test-chart/unittests/pod/field_hostPID_test.yaml index 00c379d0..acbc9897 100644 --- a/charts/library/common/test-chart/unittests/pod/field_hostPID_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_hostPID_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod security +suite: pod - fields - hostPID templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostPID value: false @@ -20,12 +19,11 @@ tests: set: defaultPodOptions: hostPID: false + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostPID value: false @@ -33,11 +31,10 @@ tests: set: defaultPodOptions: hostPID: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.hostPID value: true diff --git a/charts/library/common/test-chart/unittests/pod/field_hostUsers_test.yaml b/charts/library/common/test-chart/unittests/pod/field_hostUsers_test.yaml index 8595d2c8..26e09a1a 100644 --- a/charts/library/common/test-chart/unittests/pod/field_hostUsers_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_hostUsers_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod security +suite: pod - fields - hostUsers templates: - common.yaml values: @@ -13,9 +13,9 @@ tests: capabilities: majorVersion: 1 minorVersion: 28 - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - notExists: path: spec.template.spec.hostUsers @@ -27,13 +27,17 @@ tests: set: defaultPodOptions: hostUsers: false - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - notExists: path: spec.template.spec.hostUsers - it: should not be present by default for kubernetes >= 1.29 - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - notExists: path: spec.template.spec.hostUsers @@ -42,7 +46,9 @@ tests: set: defaultPodOptions: hostUsers: false - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.hostUsers @@ -52,7 +58,9 @@ tests: set: defaultPodOptions: hostUsers: true - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.hostUsers diff --git a/charts/library/common/test-chart/unittests/pod/field_imagePullSecrets_test.yaml b/charts/library/common/test-chart/unittests/pod/field_imagePullSecrets_test.yaml index d12bf6e2..77d18bd4 100644 --- a/charts/library/common/test-chart/unittests/pod/field_imagePullSecrets_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_imagePullSecrets_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod imagePullSecrets +suite: pod - fields - imagePullSecrets templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.imagePullSecrets - it: defaultPodOption should pass @@ -20,12 +19,11 @@ tests: defaultPodOptions: imagePullSecrets: - name: my-pull-secret + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.imagePullSecrets value: - name: my-pull-secret @@ -40,12 +38,11 @@ tests: pod: imagePullSecrets: - name: my-other-secret + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.imagePullSecrets value: - name: my-other-secret diff --git a/charts/library/common/test-chart/unittests/pod/initcontainers_test.yaml b/charts/library/common/test-chart/unittests/pod/field_initcontainers_test.yaml similarity index 67% rename from charts/library/common/test-chart/unittests/pod/initcontainers_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_initcontainers_test.yaml index 441c5879..858bde9e 100644 --- a/charts/library/common/test-chart/unittests/pod/initcontainers_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_initcontainers_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod initContainers +suite: pod - fields - initContainers templates: - common.yaml values: @@ -17,35 +17,31 @@ tests: int: 1 float: 1.5 string: value_of_env - template: "{{ .Release.Name }}-admin" + template: "{{ .Release.Name | lower }}-admin" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].env[0] value: name: float value: "1.5" - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].env[1] value: name: int value: "1" - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].env[2] value: name: string value: value_of_env - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].env[3] value: name: template - value: RELEASE-NAME-admin + value: release-name-admin - it: disabled should pass set: @@ -55,12 +51,11 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - notExists: + - notExists: path: spec.template.spec.initContainers - it: with dependsOn @@ -75,20 +70,17 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: latest + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - lengthEqual: + - lengthEqual: path: spec.template.spec.initContainers count: 2 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].name value: init2 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[1].name value: init1 @@ -100,19 +92,16 @@ tests: repository: ghcr.io/mendhak/http-https-echo tag: latest restartPolicy: Always + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - lengthEqual: + - lengthEqual: path: spec.template.spec.initContainers count: 1 - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].name value: test - - documentIndex: *DeploymentDocument - equal: + - equal: path: spec.template.spec.initContainers[0].restartPolicy value: Always diff --git a/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml b/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml index 1776d541..6a897995 100644 --- a/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_nodeSelector_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod nodeSelector +suite: pod - fields - nodeSelector templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.nodeSelector - it: defaultPodOption should pass @@ -20,12 +19,11 @@ tests: defaultPodOptions: nodeSelector: disktype: ssd + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.nodeSelector value: disktype: ssd @@ -40,10 +38,10 @@ tests: pod: nodeSelector: disktype: hdd + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 equal: path: spec.template.spec.nodeSelector diff --git a/charts/library/common/test-chart/unittests/pod/field_replicas_test.yaml b/charts/library/common/test-chart/unittests/pod/field_replicas_test.yaml index 652b4eb6..a7b97546 100644 --- a/charts/library/common/test-chart/unittests/pod/field_replicas_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_replicas_test.yaml @@ -1,28 +1,27 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod replicas +suite: pod - fields - replicas templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.replicas value: 1 - it: nil should pass set: controllers.main.replicas: null + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 notExists: path: spec.replicas @@ -30,10 +29,10 @@ tests: - it: custom replicas should pass set: controllers.main.replicas: 3 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 equal: path: spec.replicas diff --git a/charts/library/common/test-chart/unittests/pod/field_resources_test.yaml b/charts/library/common/test-chart/unittests/pod/field_resources_test.yaml new file mode 100644 index 00000000..035b0815 --- /dev/null +++ b/charts/library/common/test-chart/unittests/pod/field_resources_test.yaml @@ -0,0 +1,110 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pod - fields - resources +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +capabilities: + majorVersion: 1 + minorVersion: 32 +tests: + - it: should not be present by default for kubernetes < 1.32 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + capabilities: + majorVersion: 1 + minorVersion: 31 + asserts: + - notExists: + path: spec.resources + + - it: should not be present even if specified for kubernetes < 1.32 + capabilities: + majorVersion: 1 + minorVersion: 31 + set: + controllers: + main: + pod: + resources: + limits: + memory: 128Mi + asserts: + - notExists: + path: spec.resources + + - it: should not be present by default for kubernetes >= 1.32 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.resources + + - it: defaultPodOption should pass + set: + defaultPodOptions: + resources: + limits: + cpu: 100m + memory: 128Mi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.resources + value: + limits: + cpu: 100m + memory: 128Mi + + - it: defaultPodOption with pod override should overwrite by default + set: + defaultPodOptions: + resources: + limits: + cpu: 100m + memory: 128Mi + controllers: + main: + pod: + resources: + limits: + memory: 256Mi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.resources + value: + limits: + memory: 256Mi + + - it: defaultPodOption with pod override can be merged + set: + defaultPodOptionsStrategy: merge + defaultPodOptions: + resources: + limits: + cpu: 100m + memory: 128Mi + controllers: + main: + pod: + resources: + limits: + memory: 256Mi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.resources + value: + limits: + cpu: 100m + memory: 256Mi diff --git a/charts/library/common/test-chart/unittests/pod/field_securityContext_test.yaml b/charts/library/common/test-chart/unittests/pod/field_securityContext_test.yaml index 85d9b716..be06ff31 100644 --- a/charts/library/common/test-chart/unittests/pod/field_securityContext_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_securityContext_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod securityContext +suite: pod - fields - securityContext templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.securityContext - it: defaultPodOption should pass @@ -23,12 +22,11 @@ tests: runAsGroup: 1000 fsGroup: 1000 fsGroupChangePolicy: OnRootMismatch + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.securityContext value: runAsUser: 1000 @@ -52,12 +50,11 @@ tests: runAsGroup: 568 fsGroup: 568 fsGroupChangePolicy: OnRootMismatch + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.securityContext value: runAsUser: 568 diff --git a/charts/library/common/test-chart/unittests/pod/field_serviceAccount_test.yaml b/charts/library/common/test-chart/unittests/pod/field_serviceAccount_test.yaml index 2ecb1820..fcc5054b 100644 --- a/charts/library/common/test-chart/unittests/pod/field_serviceAccount_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_serviceAccount_test.yaml @@ -1,174 +1,56 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod serviceAccount +suite: pod - fields - serviceAccount templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - hasDocuments: - count: 1 - - documentIndex: &deploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: + - equal: path: spec.template.spec.serviceAccountName value: default - - it: default with flag should pass - set: - enforceServiceAccountCreation: true - asserts: - - hasDocuments: - count: 1 - - documentIndex: &deploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: default - - - it: with create, without name should pass - set: - serviceAccount: - create: true - asserts: - - hasDocuments: - count: 3 - - documentIndex: &serviceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &deploymentDocument 1 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: RELEASE-NAME - - - it: with create, with name should pass - set: - serviceAccount: - create: true - name: mySA - asserts: - - hasDocuments: - count: 3 - - documentIndex: &serviceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &deploymentDocument 1 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: mySA - - - it: without create, with name should pass - set: - serviceAccount: - create: false - name: &serviceAccountName mySA - asserts: - - hasDocuments: - count: 1 - - documentIndex: &deploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *serviceAccountName - - - it: without create, with name, with flag should pass - set: - enforceServiceAccountCreation: true - serviceAccount: - create: false - name: &serviceAccountName mySA - asserts: - - hasDocuments: - count: 1 - - documentIndex: &deploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: default - - - it: with extraServiceAccounts default should pass - set: - serviceAccount: - create: false - name: &serviceAccountName mySA - extraServiceAccounts: - mySA2: - create: false - mySA3: - create: true - asserts: - - hasDocuments: - count: 3 - - documentIndex: &deploymentDocument 1 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *serviceAccountName - - - it: with extraServiceAccounts identifier should pass + - it: with serviceAccount identifier should pass set: controllers: main: serviceAccount: identifier: mySA3 serviceAccount: - create: false - name: mySA - extraServiceAccounts: - mySA2: - create: false - mySA3: - create: true + mySA3: {} + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - hasDocuments: - count: 3 - - documentIndex: &deploymentDocument 1 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: + - equal: path: spec.template.spec.serviceAccountName - value: RELEASE-NAME-mySA3 + value: release-name - - it: with extraServiceAccounts name should pass + - it: with non-existing serviceAccount identifier fail set: controllers: main: serviceAccount: - name: arbitrary-SA - serviceAccount: - create: false - name: mySA - extraServiceAccounts: - mySA2: - create: false - mySA3: - create: true + identifier: mySA3 asserts: - - hasDocuments: - count: 3 - - documentIndex: &deploymentDocument 1 - isKind: - of: Deployment - - documentIndex: *deploymentDocument - equal: + - failedTemplate: + errorMessage: "No enabled ServiceAccount found with this identifier. (controller: 'main', identifier: 'mySA3')" + + - it: with serviceAccount name should pass + set: + controllers: + main: + serviceAccount: + name: mySA3 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: path: spec.template.spec.serviceAccountName - value: arbitrary-SA + value: mySA3 diff --git a/charts/library/common/test-chart/unittests/pod/field_shareProcessNamespace_test.yaml b/charts/library/common/test-chart/unittests/pod/field_shareProcessNamespace_test.yaml index f44603ee..998c1e68 100644 --- a/charts/library/common/test-chart/unittests/pod/field_shareProcessNamespace_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_shareProcessNamespace_test.yaml @@ -1,15 +1,15 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod security +suite: pod - fields - shareProcessNamespace templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: shareProcessNamespace should not be present by default - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - notExists: path: spec.template.spec.shareProcessNamespace @@ -18,7 +18,9 @@ tests: set: defaultPodOptions: shareProcessNamespace: false - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.shareProcessNamespace @@ -28,7 +30,9 @@ tests: set: defaultPodOptions: shareProcessNamespace: true - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - equal: path: spec.template.spec.shareProcessNamespace diff --git a/charts/library/common/test-chart/unittests/pod/field_tolerations_test.yaml b/charts/library/common/test-chart/unittests/pod/field_tolerations_test.yaml index 4f24da28..804f5f02 100644 --- a/charts/library/common/test-chart/unittests/pod/field_tolerations_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_tolerations_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod tolerations +suite: pod - fields - tolerations templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - notExists: + - notExists: path: spec.template.spec.tolerations - it: defaultPodOption should pass @@ -23,12 +22,11 @@ tests: operator: "Equal" value: "value1" effect: "NoSchedule" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.tolerations value: - key: "key1" @@ -52,12 +50,11 @@ tests: operator: "Equal" value: "value1" effect: "NoSchedule" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.tolerations value: - key: "master" diff --git a/charts/library/common/test-chart/unittests/pod/field_topologySpreadConstraints_test.yaml b/charts/library/common/test-chart/unittests/pod/field_topologySpreadConstraints_test.yaml index 457c4d1d..eb84246f 100644 --- a/charts/library/common/test-chart/unittests/pod/field_topologySpreadConstraints_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_topologySpreadConstraints_test.yaml @@ -1,16 +1,16 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pod topologySpreadConstraints +suite: pod - fields - topologySpreadConstraints templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 notExists: path: spec.template.spec.topologySpreadConstraints @@ -25,12 +25,11 @@ tests: labelSelector: matchLabels: app: foo + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.topologySpreadConstraints value: - maxSkew: 1 @@ -60,12 +59,11 @@ tests: labelSelector: matchLabels: app: foo + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.topologySpreadConstraints value: - maxSkew: 2 diff --git a/charts/library/common/test-chart/unittests/persistence/configmap_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_configmap_test.yaml similarity index 53% rename from charts/library/common/test-chart/unittests/persistence/configmap_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_configmap_test.yaml index 174e7b54..6a2107b4 100644 --- a/charts/library/common/test-chart/unittests/persistence/configmap_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_configmap_test.yaml @@ -1,21 +1,29 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence configmap +suite: pod - fields - volumes (configMap) templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml +set: + configMaps: + mySettings: + suffix: mySettings + data: + test: testvalue + persistence: + configmap: + type: configMap tests: - it: configmap persistence type should pass set: persistence: configmap: - type: configMap name: mySettings + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - documentIndex: 0 equal: path: spec.template.spec.volumes[0] @@ -28,51 +36,30 @@ tests: set: persistence: configmap: - type: configMap - name: '{{ include "bjw-s.common.lib.chart.names.fullname" $ }}-config' + name: '{{ include "bjw-s.common.lib.chart.names.fullname" $ | lower }}-config' + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: configmap configMap: - name: RELEASE-NAME-config + name: release-name-config - it: configmap persistence type with identifier reference should pass set: - configMaps: - mySettings: - data: - test: testvalue persistence: configmap: - type: configMap identifier: mySettings + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: ConfigMap - - documentIndex: 1 - isKind: - of: Deployment - - documentIndex: 1 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: configmap configMap: - name: RELEASE-NAME-mySettings - - - it: configmap persistence type with invalid identifier reference should fail - set: - persistence: - configmap: - type: configMap - identifier: doesNotExist - asserts: - - failedTemplate: - errorMessage: "No configmap found with this identifier. (persistence item 'configmap', identifier 'doesNotExist')" + name: release-name-mysettings diff --git a/charts/library/common/test-chart/unittests/persistence/custom.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_custom_test.yaml similarity index 83% rename from charts/library/common/test-chart/unittests/persistence/custom.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_custom_test.yaml index 0a2d868c..2073c1e4 100644 --- a/charts/library/common/test-chart/unittests/persistence/custom.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_custom_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence custom +suite: pod - fields - volumes (custom) templates: - common.yaml values: @@ -18,12 +18,11 @@ tests: - path: "labels" fieldRef: fieldPath: metadata.labels + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: custom-mount diff --git a/charts/library/common/test-chart/unittests/persistence/emptydir_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_emptydir_test.yaml similarity index 64% rename from charts/library/common/test-chart/unittests/persistence/emptydir_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_emptydir_test.yaml index a1ecf303..72f2a6be 100644 --- a/charts/library/common/test-chart/unittests/persistence/emptydir_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_emptydir_test.yaml @@ -1,23 +1,21 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence emptydir +suite: pod - fields - volumes (emptyDir) templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml +set: + persistence: + config: + type: emptyDir tests: - it: default emptyDir should pass - set: - persistence: - config: - enabled: true - type: emptyDir + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: config @@ -27,15 +25,12 @@ tests: set: persistence: config: - enabled: true - type: emptyDir medium: memory + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: config @@ -46,16 +41,13 @@ tests: set: persistence: config: - enabled: true - type: emptyDir medium: memory sizeLimit: 1Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: config diff --git a/charts/library/common/test-chart/unittests/persistence/hostpath_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_hostpath_test.yaml similarity index 50% rename from charts/library/common/test-chart/unittests/persistence/hostpath_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_hostpath_test.yaml index 651cb57c..9fbb4f54 100644 --- a/charts/library/common/test-chart/unittests/persistence/hostpath_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_hostpath_test.yaml @@ -1,47 +1,41 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence hostpath +suite: pod - fields - volumes (hostPath) templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml +set: + persistence: + hostpathmounts: + type: hostPath + hostPath: "/tmp1" tests: - it: hostPath should pass - set: - persistence: - hostpathmounts-data: - enabled: true - type: hostPath - hostPath: "/tmp1" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: - name: hostpathmounts-data + name: hostpathmounts hostPath: path: /tmp1 - it: hostPath with type should pass set: persistence: - hostpathmounts-with-type: - enabled: true - type: hostPath - hostPath: "/tmp2" + hostpathmounts: hostPathType: "Directory" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: - name: hostpathmounts-with-type + name: hostpathmounts hostPath: - path: /tmp2 + path: /tmp1 type: Directory diff --git a/charts/library/common/test-chart/unittests/persistence/nfs_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_nfs_test.yaml similarity index 78% rename from charts/library/common/test-chart/unittests/persistence/nfs_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_nfs_test.yaml index c4e7fccd..5934fe3f 100644 --- a/charts/library/common/test-chart/unittests/persistence/nfs_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_nfs_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence nfs +suite: pod - fields - volumes (nfs) templates: - common.yaml values: @@ -10,16 +10,14 @@ tests: set: persistence: nfs: - enabled: true type: nfs server: 10.10.0.8 path: /tank/nas/library + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: nfs diff --git a/charts/library/common/test-chart/unittests/persistence/claimnames_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_pvc_test.yaml similarity index 67% rename from charts/library/common/test-chart/unittests/persistence/claimnames_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_pvc_test.yaml index 3c36b650..c01d25cf 100644 --- a/charts/library/common/test-chart/unittests/persistence/claimnames_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_pvc_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence claimnames +suite: pod - fields - volumes (pvc) templates: - common.yaml values: @@ -12,29 +12,27 @@ tests: config: accessMode: ReadWriteOnce size: 1Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 1 - isKind: - of: Deployment - - documentIndex: 1 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: config persistentVolumeClaim: - claimName: RELEASE-NAME-config + claimName: release-name - it: with existingClaim should pass set: persistence: existingClaim: existingClaim: myClaim + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 0 - isKind: - of: Deployment - - documentIndex: 0 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: existingClaim @@ -45,36 +43,33 @@ tests: set: persistence: claimWithoutSuffix: - nameOverride: "-" accessMode: ReadWriteMany size: 1G + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 1 - isKind: - of: Deployment - - documentIndex: 1 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: claimWithoutSuffix persistentVolumeClaim: - claimName: RELEASE-NAME + claimName: release-name - it: custom suffix should pass set: persistence: claimWithNameOverride: - nameOverride: suffix + suffix: suffix accessMode: ReadWriteMany size: 1G + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: 1 - isKind: - of: Deployment - - documentIndex: 1 - equal: + - equal: path: spec.template.spec.volumes[0] value: name: claimWithNameOverride persistentVolumeClaim: - claimName: RELEASE-NAME-suffix + claimName: release-name-suffix diff --git a/charts/library/common/test-chart/unittests/pod/field_volumes_secret_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_secret_test.yaml new file mode 100644 index 00000000..eddf6adf --- /dev/null +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_secret_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pod - fields - volumes (secret) +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + secrets: + mySettings: + stringData: + test: testvalue + persistence: + secret: + type: secret +tests: + - it: secret persistence type should pass + set: + persistence: + secret: + name: mySettings + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: secret + secret: + secretName: mySettings + + - it: secret persistence type with name template should pass + set: + persistence: + secret: + name: "{{ .Release.Name | lower }}-config" + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: secret + secret: + secretName: release-name-config + + - it: secret persistence type with identifier reference should pass + set: + persistence: + secret: + identifier: mySettings + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.spec.volumes[0] + value: + name: secret + secret: + secretName: release-name diff --git a/charts/library/common/test-chart/unittests/persistence/volumes_test.yaml b/charts/library/common/test-chart/unittests/pod/field_volumes_test.yaml similarity index 80% rename from charts/library/common/test-chart/unittests/persistence/volumes_test.yaml rename to charts/library/common/test-chart/unittests/pod/field_volumes_test.yaml index 0501a418..5567c3bf 100644 --- a/charts/library/common/test-chart/unittests/persistence/volumes_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/field_volumes_test.yaml @@ -1,18 +1,17 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence volumes +suite: pod - fields - volumes templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: no persistence should pass + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - notExists: + - notExists: path: spec.template.spec.volumes - it: default should pass @@ -21,17 +20,16 @@ tests: config: accessMode: ReadWriteOnce size: 1Gi + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - - documentIndex: &DeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *DeploymentDoc - equal: + - equal: path: spec.template.spec.volumes value: - name: config persistentVolumeClaim: - claimName: RELEASE-NAME-config + claimName: release-name - it: advanced mount config should pass set: @@ -48,7 +46,6 @@ tests: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 - persistence: config: existingClaim: test @@ -80,10 +77,9 @@ tests: existingClaim: test asserts: - - documentIndex: &FirstDeploymentDoc 0 - isKind: - of: Deployment - - documentIndex: *FirstDeploymentDoc + - documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name-main equal: path: spec.template.spec.volumes value: @@ -96,10 +92,9 @@ tests: - name: no-mounts persistentVolumeClaim: claimName: test - - documentIndex: &SecondDeploymentDoc 1 - isKind: - of: Deployment - - documentIndex: *SecondDeploymentDoc + - documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name-second equal: path: spec.template.spec.volumes value: diff --git a/charts/library/common/test-chart/unittests/pod/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/pod/metadata_annotations_test.yaml index 92eb2ad6..740790d9 100644 --- a/charts/library/common/test-chart/unittests/pod/metadata_annotations_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/metadata_annotations_test.yaml @@ -1,25 +1,26 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: "pod metadata: annotations" +suite: "pod - metadata - annotations" templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default pod annotations - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - notExists: path: spec.template.metadata.annotations - it: pod annotations from defaultPodOptions should be included set: - defaultPodOptions: - annotations: - defaultPodOptionsAnnotation: test - documentSelector: *DeploymentSelector + defaultPodOptions.annotations: + defaultPodOptionsAnnotation: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.annotations @@ -28,12 +29,11 @@ tests: - it: pod annotations from pod options should be included set: - controllers: - main: - pod: - annotations: - podOptionsAnnotation: test - documentSelector: *DeploymentSelector + controllers.main.pod.annotations: + podOptionsAnnotation: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.annotations @@ -42,10 +42,11 @@ tests: - it: pod annotations from global annotations should not be included by default set: - global: - annotations: - globalAnnotation: test - documentSelector: *DeploymentSelector + global.annotations: + globalAnnotation: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isNotSubset: path: spec.template.metadata.annotations @@ -58,9 +59,102 @@ tests: propagateGlobalMetadataToPods: true annotations: globalAnnotation: test - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.annotations content: globalAnnotation: test + + - it: configMap checksum should be included in pod annotations + set: + configMaps: + config: + enabled: true + data: + test: value 1 + test_default_enabled: + data: + test: value 1 + test_not_in_checksum: + includeInChecksum: false + data: + test: value 1 + test_disabled: + enabled: false + data: + test: value 1 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.metadata.annotations + value: + checksum/configMaps: 66d23d7a53c4e2a523ba85a969696b4ebb78ec5d79ab9c12c210c1569f48511b + + - it: configMap checksum from folder should be included in pod annotations + set: + configMaps: + config: + enabled: true + data: + test: value 1 + test_default_enabled: + data: + test: value 1 + test_not_in_checksum: + includeInChecksum: false + data: + test: value 1 + test_disabled: + enabled: false + data: + test: value 1 + configMapsFromFolder: + enabled: true + basePath: ci/configMapsFolder + configMapsOverrides: + test_2: + fileAttributeOverrides: + helm.jpg: + binary: true + test_2.yaml: + escaped: true + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.metadata.annotations + value: + checksum/configMaps: e83a24569d0b4f2ccc44aec36d4e9a1c44a29bcc92eefdffe14fb1ce81dff054 + + - it: secret checksum should be included in pod annotations + set: + secrets: + secret_1: + stringData: + test: value 1 + secret_2: # default enabled + stringData: + test_1: value 1 + test_2: value 2 + test_not_in_checksum: + includeInChecksum: false + stringData: + test: value 1 + test_disabled: + enabled: false + stringData: + test: value 1 + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name + asserts: + - equal: + path: spec.template.metadata.annotations + value: + checksum/secrets: cd4e5076088172611ca1c43c659a275232d9eeb887acc20575ac141038b9aacb diff --git a/charts/library/common/test-chart/unittests/pod/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/pod/metadata_labels_test.yaml index 4dd47aa5..1986d8d9 100644 --- a/charts/library/common/test-chart/unittests/pod/metadata_labels_test.yaml +++ b/charts/library/common/test-chart/unittests/pod/metadata_labels_test.yaml @@ -1,29 +1,30 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: "pod metadata: labels" +suite: "pod - metadata - labels" templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - it: default pod labels - documentSelector: &DeploymentSelector + documentSelector: path: $[?(@.kind == "Deployment")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - equal: path: spec.template.metadata.labels value: - app.kubernetes.io/component: main + app.kubernetes.io/controller: main app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME - it: pod labels from defaultPodOptions should be included set: - defaultPodOptions: - labels: - defaultPodOptionsLabel: test - documentSelector: *DeploymentSelector + defaultPodOptions.labels: + defaultPodOptionsLabel: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.labels @@ -32,12 +33,12 @@ tests: - it: pod labels from pod options should be included set: - controllers: - main: - pod: - labels: - podOptionsLabel: test - documentSelector: *DeploymentSelector + controllers.main.pod: + labels: + podOptionsLabel: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.labels @@ -46,10 +47,11 @@ tests: - it: pod labels from global labels should not be included by default set: - global: - labels: - globalLabel: test - documentSelector: *DeploymentSelector + global.labels: + globalLabel: test + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isNotSubset: path: spec.template.metadata.labels @@ -62,7 +64,9 @@ tests: propagateGlobalMetadataToPods: true labels: globalLabel: test - documentSelector: *DeploymentSelector + documentSelector: + path: $[?(@.kind == "Deployment")].metadata.name + value: release-name asserts: - isSubset: path: spec.template.metadata.labels diff --git a/charts/library/common/test-chart/unittests/pvc/datasource_test.yaml b/charts/library/common/test-chart/unittests/pvc/datasource_test.yaml deleted file mode 100644 index 096cc8c7..00000000 --- a/charts/library/common/test-chart/unittests/pvc/datasource_test.yaml +++ /dev/null @@ -1,112 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pvc datasource -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -set: - persistence.config: - accessMode: ReadWriteOnce - size: 1Gi - -tests: - - it: default should pass - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSource - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSourceRef - - - it: with dataSource should pass - set: - persistence.config: - dataSource: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: MySnapshot - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: spec.dataSource - value: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: MySnapshot - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSourceRef - - - it: templated dataSource name should pass - set: - persistence.config: - dataSource: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: "{{ .Release.Name }}-config" - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: spec.dataSource - value: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: RELEASE-NAME-config - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSourceRef - - - it: with dataSourceRef should pass - set: - persistence.config: - dataSourceRef: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: MySnapshot - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: spec.dataSourceRef - value: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: MySnapshot - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSource - - - it: templated dataSourceRef name should pass - set: - persistence.config: - dataSourceRef: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: "{{ .Release.Name }}-config" - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: spec.dataSourceRef - value: - apiGroup: snapshot.storage.k8s.io - kind: VolumeSnapshot - name: RELEASE-NAME-config - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: spec.dataSource diff --git a/charts/library/common/test-chart/unittests/pvc/field_datasourceRef_test.yaml b/charts/library/common/test-chart/unittests/pvc/field_datasourceRef_test.yaml new file mode 100644 index 00000000..5dc65550 --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/field_datasourceRef_test.yaml @@ -0,0 +1,60 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - fields - datasourceRef +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + persistence.config: + accessMode: ReadWriteOnce + size: 1Gi + +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.dataSourceRef + + - it: with dataSourceRef should pass + set: + persistence.config: + dataSourceRef: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: MySnapshot + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - equal: + path: spec.dataSourceRef + value: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: MySnapshot + - notExists: + path: spec.dataSource + + - it: templated dataSourceRef name should pass + set: + persistence.config: + dataSourceRef: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: "{{ .Release.Name }}-config" + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - equal: + path: spec.dataSourceRef + value: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: RELEASE-NAME-config + - notExists: + path: spec.dataSource diff --git a/charts/library/common/test-chart/unittests/pvc/field_datasource_test.yaml b/charts/library/common/test-chart/unittests/pvc/field_datasource_test.yaml new file mode 100644 index 00000000..11b6eb0a --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/field_datasource_test.yaml @@ -0,0 +1,60 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - fields - datasource +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + persistence.config: + accessMode: ReadWriteOnce + size: 1Gi + +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - notExists: + path: spec.dataSource + + - it: with dataSource should pass + set: + persistence.config: + dataSource: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: MySnapshot + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - equal: + path: spec.dataSource + value: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: MySnapshot + - notExists: + path: spec.dataSourceRef + + - it: templated dataSource name should pass + set: + persistence.config: + dataSource: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: "{{ .Release.Name }}-config" + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name + asserts: + - equal: + path: spec.dataSource + value: + apiGroup: snapshot.storage.k8s.io + kind: VolumeSnapshot + name: RELEASE-NAME-config + - notExists: + path: spec.dataSourceRef diff --git a/charts/library/common/test-chart/unittests/pvc/storageclass_test.yaml b/charts/library/common/test-chart/unittests/pvc/field_storageclass.yaml similarity index 55% rename from charts/library/common/test-chart/unittests/pvc/storageclass_test.yaml rename to charts/library/common/test-chart/unittests/pvc/field_storageclass.yaml index d1f98dc3..e7311ec9 100644 --- a/charts/library/common/test-chart/unittests/pvc/storageclass_test.yaml +++ b/charts/library/common/test-chart/unittests/pvc/field_storageclass.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pvc storageclass +suite: pvc - fields - storageclass templates: - common.yaml values: @@ -12,24 +12,22 @@ set: tests: - it: default should pass + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - notExists: + - notExists: path: spec.storageClassName - it: custom should pass set: persistence.config: storageClass: custom + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: + - equal: path: spec.storageClassName value: custom @@ -37,11 +35,10 @@ tests: set: persistence.config: storageClass: "-" + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: + - equal: path: spec.storageClassName value: "" diff --git a/charts/library/common/test-chart/unittests/pvc/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/pvc/metadata_annotations_test.yaml new file mode 100644 index 00000000..a0453e03 --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/metadata_annotations_test.yaml @@ -0,0 +1,50 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + persistence.test: + type: persistentVolumeClaim + suffix: test + accessMode: ReadWriteOnce + size: 1Gi +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + persistence.test.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + persistence.test.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/pvc/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/pvc/metadata_labels_test.yaml new file mode 100644 index 00000000..34dc3a8c --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/metadata_labels_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + persistence.test: + type: persistentVolumeClaim + suffix: test + accessMode: ReadWriteOnce + size: 1Gi +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + persistence.test.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + persistence.test.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "PersistentVolumeClaim")].metadata.name + value: release-name-test + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/pvc/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/pvc/metadata_name_test.yaml new file mode 100644 index 00000000..147386ff --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/metadata_name_test.yaml @@ -0,0 +1,189 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + persistence.main: + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + persistence.main.forceRename: forceRename + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + persistence.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + persistence.main.prefix: prefix + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + persistence.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + persistence.main.suffix: suffix + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + persistence.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + persistence.main.prefix: prefix + persistence.main.suffix: suffix + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + persistence.main.forceRename: forceRename + persistence.main.prefix: prefix + persistence.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + persistence.second: + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + persistence.second: + prefix: prefix + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + persistence.second: + suffix: suffix + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + persistence.second: + prefix: prefix + suffix: suffix + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + persistence.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + type: persistentVolumeClaim + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/pvc/metadata_test.yaml b/charts/library/common/test-chart/unittests/pvc/metadata_test.yaml deleted file mode 100644 index 9be3d9de..00000000 --- a/charts/library/common/test-chart/unittests/pvc/metadata_test.yaml +++ /dev/null @@ -1,110 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pvc metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -set: - persistence.config: - accessMode: ReadWriteOnce - size: 1Gi - -tests: - - it: default should pass - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - notExists: - path: metadata.annotations - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: retain enabled should pass - set: - persistence.config: - retain: true - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.annotations - value: - helm.sh/resource-policy: keep - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - persistence.config: - labels: - test_label: test - annotations: - test_annotation: test - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - persistence.config: - labels: - test_label: test - annotations: - test_annotation: test - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.annotations - value: - test_annotation: test - global_annotation: test - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/pvc/names_test.yaml b/charts/library/common/test-chart/unittests/pvc/names_test.yaml deleted file mode 100644 index 536eac09..00000000 --- a/charts/library/common/test-chart/unittests/pvc/names_test.yaml +++ /dev/null @@ -1,67 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pvc names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -set: - persistence.config: - accessMode: ReadWriteOnce - size: 1Gi - -tests: - - it: disabled should pass - set: - persistence.config.enabled: false - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: PersistentVolumeClaim - - - it: enabled should pass - set: - persistence.config.enabled: true - asserts: - - hasDocuments: - count: 2 - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: 1 - not: true - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.name - value: RELEASE-NAME-config - - - it: without suffix should pass - set: - persistence.config: - nameOverride: "-" - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.name - value: RELEASE-NAME - - - it: with custom suffix should pass - set: - persistence.config: - nameOverride: "custom" - asserts: - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.name - value: RELEASE-NAME-custom diff --git a/charts/library/common/test-chart/unittests/pvc/presence_test.yaml b/charts/library/common/test-chart/unittests/pvc/presence_test.yaml new file mode 100644 index 00000000..69db5fd1 --- /dev/null +++ b/charts/library/common/test-chart/unittests/pvc/presence_test.yaml @@ -0,0 +1,52 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: pvc - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: pvc is enabled by default + set: + persistence.test: + type: persistentVolumeClaim + suffix: test + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-test + any: true + + - it: pvc can be explicitly enabled + set: + persistence.test: + type: persistentVolumeClaim + enabled: true + suffix: test + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-test + any: true + + - it: pvc can be disabled + set: + persistence.test: + type: persistentVolumeClaim + enabled: false + suffix: test + accessMode: ReadWriteOnce + size: 1Gi + asserts: + - not: true + containsDocument: + kind: PersistentVolumeClaim + apiVersion: v1 + name: release-name-test + any: true diff --git a/charts/library/common/test-chart/unittests/pvc/values_test.yaml b/charts/library/common/test-chart/unittests/pvc/values_test.yaml deleted file mode 100644 index acf4f20e..00000000 --- a/charts/library/common/test-chart/unittests/pvc/values_test.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: pvc values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default enabled should pass - set: - persistence.test: - type: persistentVolumeClaim - accessMode: ReadWriteOnce - size: 1Gi - asserts: - - hasDocuments: - count: 2 - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.name - value: RELEASE-NAME-test - - - it: explicit enabled should pass - set: - persistence.test: - enabled: true - type: persistentVolumeClaim - accessMode: ReadWriteOnce - size: 1Gi - asserts: - - hasDocuments: - count: 2 - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: PersistentVolumeClaim - - documentIndex: *PersistentVolumeClaimDocument - equal: - path: metadata.name - value: RELEASE-NAME-test - - - it: explicit disabled - set: - persistence.test: - enabled: false - type: persistentVolumeClaim - accessMode: ReadWriteOnce - size: 1Gi - asserts: - - hasDocuments: - count: 1 - - documentIndex: &PersistentVolumeClaimDocument 0 - isKind: - of: Deployment diff --git a/charts/library/common/test-chart/unittests/rawResource/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/rawResource/metadata_annotations_test.yaml new file mode 100644 index 00000000..d0d2d199 --- /dev/null +++ b/charts/library/common/test-chart/unittests/rawResource/metadata_annotations_test.yaml @@ -0,0 +1,51 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: rawResource - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + rawResources: + config: + apiVersion: v1 + kind: Endpoint + spec: + test: test +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + rawResources.config.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + rawResources.config.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/rawResource/metadata_test.yaml b/charts/library/common/test-chart/unittests/rawResource/metadata_labels_test.yaml similarity index 56% rename from charts/library/common/test-chart/unittests/rawResource/metadata_test.yaml rename to charts/library/common/test-chart/unittests/rawResource/metadata_labels_test.yaml index 5eee6f83..446458d4 100644 --- a/charts/library/common/test-chart/unittests/rawResource/metadata_test.yaml +++ b/charts/library/common/test-chart/unittests/rawResource/metadata_labels_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: rawResource metadata +suite: rawResource - metadata - labels templates: - common.yaml values: @@ -13,13 +13,11 @@ set: spec: test: test tests: - - it: default metadata should be present - documentSelector: &EndpointSelector + - it: default labels + documentSelector: path: $[?(@.kind == "Endpoint")].metadata.name - value: RELEASE-NAME-config + value: release-name asserts: - - notExists: - path: metadata.annotations - equal: path: metadata.labels value: @@ -28,20 +26,14 @@ tests: app.kubernetes.io/name: RELEASE-NAME helm.sh/chart: common-test-1.0.0 - - it: custom metadata can be configured + - it: custom labels set: - rawResources: - config: - annotations: - test_annotation: test - labels: - test_label: test - documentSelector: *EndpointSelector + rawResources.config.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name asserts: - - equal: - path: metadata.annotations - value: - test_annotation: test - equal: path: metadata.labels value: @@ -51,26 +43,16 @@ tests: helm.sh/chart: common-test-1.0.0 test_label: test - - it: global metadata can be configured with local overrides + - it: custom labels mixed with global labels set: - global: - labels: - global_label: test - annotations: - global_annotation: test - rawResources: - config: - annotations: - test_annotation: test - labels: - test_label: test - documentSelector: *EndpointSelector + global.labels: + global_label: test + rawResources.config.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name asserts: - - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - equal: path: metadata.labels value: diff --git a/charts/library/common/test-chart/unittests/rawResource/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/rawResource/metadata_name_test.yaml new file mode 100644 index 00000000..883fbe94 --- /dev/null +++ b/charts/library/common/test-chart/unittests/rawResource/metadata_name_test.yaml @@ -0,0 +1,195 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: rawResource - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + rawResources.main: + apiVersion: v1 + kind: Endpoint + spec: + test: test +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + rawResources.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + rawResources.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + rawResources.main.prefix: prefix + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + rawResources.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + rawResources.main.suffix: suffix + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + rawResources.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + rawResources.main.prefix: prefix + rawResources.main.suffix: suffix + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + rawResources.main.forceRename: forceRename + rawResources.main.prefix: prefix + rawResources.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + rawResources.second: + apiVersion: v1 + kind: Endpoint + spec: + test: test + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + rawResources.second: + prefix: prefix + apiVersion: v1 + kind: Endpoint + spec: + test: test + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + rawResources.second: + suffix: suffix + apiVersion: v1 + kind: Endpoint + spec: + test: test + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + rawResources.second: + prefix: prefix + suffix: suffix + apiVersion: v1 + kind: Endpoint + spec: + test: test + asserts: + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Endpoint + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + rawResources.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + apiVersion: v1 + kind: Endpoint + spec: + test: test + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/rawResource/values_test.yaml b/charts/library/common/test-chart/unittests/rawResource/presence_test.yaml similarity index 62% rename from charts/library/common/test-chart/unittests/rawResource/values_test.yaml rename to charts/library/common/test-chart/unittests/rawResource/presence_test.yaml index d0d77eca..e1b7f4ae 100644 --- a/charts/library/common/test-chart/unittests/rawResource/values_test.yaml +++ b/charts/library/common/test-chart/unittests/rawResource/presence_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: rawResource values +suite: rawResource - presence templates: - common.yaml values: @@ -19,38 +19,24 @@ set: port: 443 protocol: TCP tests: - - it: raw resources can be configured - documentSelector: &EndpointSelector + - it: raw resources are enabled by default + documentSelector: path: $[?(@.kind == "Endpoint")].metadata.name - value: RELEASE-NAME-endpoint + value: release-name asserts: - equal: path: subsets[0].addresses[0].ip value: 127.0.0.1 - - it: nameOverride can be configured + - it: raw resources can be disabled set: - rawResources.endpoint: - nameOverride: test - documentSelector: - path: $[?(@.kind == "Endpoint")].metadata.name - value: RELEASE-NAME-test + rawResources.endpoint.enabled: false asserts: - - equal: - path: metadata.name - value: RELEASE-NAME-test - - - it: nameOverride with template should pass - set: - rawResources.endpoint: - nameOverride: "{{ .Release.Name }}" - documentSelector: - path: $[?(@.kind == "Endpoint")].metadata.name - value: RELEASE-NAME - asserts: - - equal: - path: metadata.name - value: RELEASE-NAME + - not: true + containsDocument: + kind: Endpoint + apiVersion: v1 + any: true - it: spec can render Helm template set: @@ -63,7 +49,9 @@ tests: - name: "{{ .Release.Name }}" port: 443 protocol: TCP - documentSelector: *EndpointSelector + documentSelector: + path: $[?(@.kind == "Endpoint")].metadata.name + value: release-name asserts: - equal: path: subsets[0].ports[0].name diff --git a/charts/library/common/test-chart/unittests/rbac/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/rbac/metadata_annotations_test.yaml new file mode 100644 index 00000000..467b08ea --- /dev/null +++ b/charts/library/common/test-chart/unittests/rbac/metadata_annotations_test.yaml @@ -0,0 +1,44 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: rbac - metadata - annotations +templates: + - common.yaml +values: + - ../_values/rbac_values.yaml +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + rbac.roles.defaultRole.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + rbac.roles.defaultRole.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/rbac/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/rbac/metadata_labels_test.yaml new file mode 100644 index 00000000..f748678c --- /dev/null +++ b/charts/library/common/test-chart/unittests/rbac/metadata_labels_test.yaml @@ -0,0 +1,57 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: rbac - metadata - labels +templates: + - common.yaml +values: + - ../_values/rbac_values.yaml +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + rbac.roles.defaultRole.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + rbac.roles.defaultRole.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/rbac/metadata_test.yaml b/charts/library/common/test-chart/unittests/rbac/metadata_test.yaml deleted file mode 100644 index 28e1f12f..00000000 --- a/charts/library/common/test-chart/unittests/rbac/metadata_test.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -suite: rbac metadata - -set: - serviceAccount: - name: test-sa - -templates: - - common.yaml -values: - - ../_values/rbac_values.yaml -tests: - - it: default metadata should pass - asserts: - - hasDocuments: - count: 4 - - documentIndex: &RoleDocument 2 - isKind: - of: Role - - documentIndex: *RoleDocument - notExists: - path: metadata.annotations - - documentIndex: *RoleDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - rbac: - roles: - defaultRole: - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - hasDocuments: - count: 4 - - documentIndex: &RoleDocument 2 - isKind: - of: Role - - documentIndex: *RoleDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *RoleDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/rbac/names_test.yaml b/charts/library/common/test-chart/unittests/rbac/names_test.yaml deleted file mode 100644 index 31a5c672..00000000 --- a/charts/library/common/test-chart/unittests/rbac/names_test.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -suite: rbac names - -set: - serviceAccount: - name: test-sa - -templates: - - common.yaml -values: - - ../_values/rbac_values.yaml -tests: - - it: default role and rolebinding names should pass - asserts: - - hasDocuments: - count: 4 - - documentIndex: &RoleDocument 2 - isKind: - of: Role - - documentIndex: *RoleDocument - equal: - path: metadata.name - value: RELEASE-NAME-defaultRole - - - documentIndex: &BindingDocument 3 - isKind: - of: RoleBinding - - documentIndex: *BindingDocument - equal: - path: metadata.name - value: RELEASE-NAME-defaultBinding - - - it: custom role name should pass - set: - rbac: - roles: - defaultRole: - forceRename: customRole - bindings: - defaultBinding: - forceRename: customBinding - asserts: - - hasDocuments: - count: 4 - - documentIndex: &RoleDocument 2 - isKind: - of: Role - - documentIndex: &BindingDocument 3 - isKind: - of: RoleBinding - - documentIndex: *RoleDocument - equal: - path: metadata.name - value: customRole - - documentIndex: *BindingDocument - equal: - path: metadata.name - value: customBinding diff --git a/charts/library/common/test-chart/unittests/rbac/presence_test.yaml b/charts/library/common/test-chart/unittests/rbac/presence_test.yaml new file mode 100644 index 00000000..a9957261 --- /dev/null +++ b/charts/library/common/test-chart/unittests/rbac/presence_test.yaml @@ -0,0 +1,72 @@ +--- +suite: rbac - presence +templates: + - common.yaml +tests: + - it: role and rolebinding can be configured are not created by default + asserts: + - not: true + containsDocument: + kind: Role + apiVersion: rbac.authorization.k8s.io/v1 + any: true + - not: true + containsDocument: + kind: RoleBinding + apiVersion: rbac.authorization.k8s.io/v1 + any: true + + - it: role and rolebinding can be configured + values: + - ../_values/rbac_values.yaml + asserts: + - documentSelector: + path: $[?(@.kind == "Role")].metadata.name + value: release-name + equal: + path: rules[0].verbs + value: ["get", "list"] + - documentSelector: + path: $[?(@.kind == "RoleBinding")].metadata.name + value: release-name + equal: + path: subjects[0].name + value: "release-name" + + - it: role and rolebinding can be disabled + values: + - ../_values/rbac_values.yaml + set: + rbac.roles.defaultRole: + enabled: false + rbac.bindings.defaultBinding: + enabled: false + asserts: + - not: true + containsDocument: + kind: Role + apiVersion: rbac.authorization.k8s.io/v1 + any: true + - not: true + containsDocument: + kind: RoleBinding + apiVersion: rbac.authorization.k8s.io/v1 + any: true + + - it: multiple role and rolebinding can be configured + values: + - ../_values/rbac_values.yaml + set: + rbac.roles.customRole: + type: ClusterRole + rules: + - apiGroups: ["*"] + resources: ["*"] + verbs: ["get", "list", "watch"] + asserts: + - documentSelector: + path: $[?(@.kind == "ClusterRole")].metadata.name + value: release-name-customrole + equal: + path: rules[0].verbs + value: ["get", "list", "watch"] diff --git a/charts/library/common/test-chart/unittests/rbac/validations_test.yaml b/charts/library/common/test-chart/unittests/rbac/validations_test.yaml index 3a3091fe..d993040a 100644 --- a/charts/library/common/test-chart/unittests/rbac/validations_test.yaml +++ b/charts/library/common/test-chart/unittests/rbac/validations_test.yaml @@ -1,10 +1,5 @@ --- -suite: rbac validations - -set: - serviceAccount: - name: test-sa - +suite: rbac - validations templates: - common.yaml values: @@ -19,10 +14,17 @@ tests: rules: {} asserts: - failedTemplate: - errorMessage: | - You selected: `InvalidRole`. Type must be one of: - - Role - - ClusterRole + errorPattern: "values don't meet the specifications of the schema" + + - it: rolebinding type must be valid + set: + rbac: + bindings: + invalidRole: + type: InvalidRole + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" - it: role rules can't be empty set: @@ -44,4 +46,12 @@ tests: roleRef: {} asserts: - failedTemplate: - errorMessage: "If not using identifier roleRef must have a `name` key" + errorPattern: "values don't meet the specifications of the schema" + + - it: serviceAccount reference to non-existing serviceAccount should fail + set: + rbac.bindings.defaultBinding.subjects: + - identifier: main + asserts: + - failedTemplate: + errorMessage: "No enabled ServiceAccount found with this identifier. (rolebinding: 'defaultBinding', identifier: 'main')" diff --git a/charts/library/common/test-chart/unittests/rbac/values_test.yaml b/charts/library/common/test-chart/unittests/rbac/values_test.yaml deleted file mode 100644 index e6574dd3..00000000 --- a/charts/library/common/test-chart/unittests/rbac/values_test.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -suite: rbac values - -set: - serviceAccount: - name: test-sa - -templates: - - common.yaml -values: - - ../_values/rbac_values.yaml -tests: - - it: default role and rolebinding should pass - asserts: - - hasDocuments: - count: 4 - - documentIndex: &RoleDocument 2 - isKind: - of: Role - - documentIndex: *RoleDocument - equal: - path: rules[0].verbs - value: ["get", "list"] - - - documentIndex: &BindingDocument 3 - isKind: - of: RoleBinding - - documentIndex: *BindingDocument - equal: - path: subjects[0].name - value: "test-sa" - - - it: custom role values should pass - set: - rbac: - roles: - customRole: - type: ClusterRole - rules: - - apiGroups: ["*"] - resources: ["*"] - verbs: ["get", "list", "watch"] - asserts: - - hasDocuments: - count: 5 - - documentIndex: &RoleDocument 2 - isKind: - of: ClusterRole - - documentIndex: *RoleDocument - equal: - path: rules[0].verbs - value: ["get", "list", "watch"] diff --git a/charts/library/common/test-chart/unittests/route/service_reference_test.yaml b/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml similarity index 67% rename from charts/library/common/test-chart/unittests/route/service_reference_test.yaml rename to charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml index 7b722aa5..bdc0916e 100644 --- a/charts/library/common/test-chart/unittests/route/service_reference_test.yaml +++ b/charts/library/common/test-chart/unittests/route/field_backendRefs_test.yaml @@ -1,12 +1,12 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: route service reference +suite: route - fields - backendRefs templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml tests: - - it: default should pass + - it: backendRefs can be configured by passing in a service name set: route.main: parentRefs: @@ -20,12 +20,11 @@ tests: namespace: NAMESPACE port: 8080 weight: 1 + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: + - equal: path: spec.rules[0].backendRefs[0] value: group: "" @@ -35,6 +34,32 @@ tests: port: 8080 weight: 1 + - it: backendRefs can be configured by passing in a service identifier + values: + - ../_values/service_main_default.yaml + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - identifier: main + port: 8080 + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: spec.rules[0].backendRefs[0] + value: + group: "" + kind: Service + name: release-name + namespace: NAMESPACE + port: 8080 + weight: 1 + - it: custom service reference should pass set: route.main: @@ -48,12 +73,11 @@ tests: port: 1234 namespace: serviceNamespace weight: 123 + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: + - equal: path: spec.rules[0].backendRefs[0] value: group: test @@ -63,28 +87,6 @@ tests: port: 1234 weight: 123 - - it: custom service reference with filter should fail - set: - route.main: - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - group: test - name: pathService - port: 1234 - namespace: serviceNamespace - weight: 123 - filters: - - type: RequestRedirect - requestRedirect: - scheme: https - statusCode: 301 - asserts: - - failedTemplate: - errorMessage: "backend refs and request redirect filters cannot co-exist." - - it: custom service with filter should pass set: route.main: @@ -97,18 +99,16 @@ tests: requestRedirect: scheme: https statusCode: 301 + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: + - equal: path: spec.rules[0].filters[0] value: type: RequestRedirect requestRedirect: scheme: https statusCode: 301 - - documentIndex: *HTTPRouteDocument - notExists: + - notExists: path: spec.rules[0].backendRefs[0] diff --git a/charts/library/common/test-chart/unittests/route/field_hostnames_test.yaml b/charts/library/common/test-chart/unittests/route/field_hostnames_test.yaml new file mode 100644 index 00000000..121abef7 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_hostnames_test.yaml @@ -0,0 +1,68 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - hostnames +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: hostnames shouldn't be used for TCPRoutes and UDPRoutes + set: + route: + main: + kind: TCPRoute + hostnames: + - chart-test.local + parentRefs: + - name: parentName + namespace: parentNamespace + udp: + kind: UDPRoute + hostnames: + - chart-test.local + parentRefs: + - name: parentName + namespace: parentNamespace + asserts: + - documentSelector: + path: $[?(@.kind == "TCPRoute")].metadata.name + value: release-name-main + notExists: + path: spec.hostnames + - documentSelector: + path: $[?(@.kind == "UDPRoute")].metadata.name + value: release-name-udp + notExists: + path: spec.hostnames + + - it: hostname can be configured + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + hostnames: + - chart-test.local + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: spec.hostnames[0] + value: chart-test.local + + - it: hostnames support Helm templates + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + hostnames: + - "{{ .Release.Name }}.local" + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: spec.hostnames[0] + value: RELEASE-NAME.local diff --git a/charts/library/common/test-chart/unittests/route/field_parentRefs_test.yaml b/charts/library/common/test-chart/unittests/route/field_parentRefs_test.yaml new file mode 100644 index 00000000..c0bc3691 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_parentRefs_test.yaml @@ -0,0 +1,67 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - parentRefs +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: setting gateway should pass + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: spec.parentRefs[0].name + value: parentName + - equal: + path: spec.parentRefs[0].namespace + value: parentNamespace + + - it: sectionName should be optional + set: + route: + main: + parentRefs: + - name: parentName + namespace: parentNamespace + second: + parentRefs: + - name: parentName + namespace: parentNamespace + sectionName: parentSection + asserts: + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-main + notExists: + path: spec.parentRefs[0].sectionName + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-second + equal: + path: spec.parentRefs[0].sectionName + value: parentSection + + - it: should be possible to configure port on the parentRefs + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + port: 443 + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: spec.parentRefs[0].name + value: parentName + - equal: + path: spec.parentRefs[0].port + value: 443 diff --git a/charts/library/common/test-chart/unittests/route/field_rules_filters_test.yaml b/charts/library/common/test-chart/unittests/route/field_rules_filters_test.yaml new file mode 100644 index 00000000..c930df10 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_rules_filters_test.yaml @@ -0,0 +1,134 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - rules - filters +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: path matches should only be used for HTTPRoutes and GRPCRoutes + set: + route: + main: + kind: HTTPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + grpc: + kind: GRPCRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + tcp: + kind: TCPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + tls: + kind: TLSRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + udp: + kind: UDPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + asserts: + - documentSelector: + path: $[?(@.kind == "GRPCRoute")].metadata.name + value: release-name-grpc + equal: + path: spec.rules[0].filters + value: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-main + equal: + path: spec.rules[0].filters + value: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + - documentSelector: + path: $[?(@.kind == "TCPRoute")].metadata.name + value: release-name-tcp + notExists: + path: spec.rules[0].filters + - documentSelector: + path: $[?(@.kind == "TLSRoute")].metadata.name + value: release-name-tls + notExists: + path: spec.rules[0].filters + - documentSelector: + path: $[?(@.kind == "UDPRoute")].metadata.name + value: release-name-udp + notExists: + path: spec.rules[0].filters diff --git a/charts/library/common/test-chart/unittests/route/field_rules_matches_test.yaml b/charts/library/common/test-chart/unittests/route/field_rules_matches_test.yaml new file mode 100644 index 00000000..bd47a302 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_rules_matches_test.yaml @@ -0,0 +1,120 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - rules - matches +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: path matches should only be used for HTTPRoutes and GRPCRoutes + set: + route: + main: + kind: HTTPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + matches: + - path: + type: PathPrefix + value: /test + grpc: + kind: GRPCRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + matches: + - path: + type: PathPrefix + value: /test + tcp: + kind: TCPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + matches: + - path: + type: PathPrefix + value: /test + tls: + kind: TLSRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + matches: + - path: + type: PathPrefix + value: /test + udp: + kind: UDPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + matches: + - path: + type: PathPrefix + value: /test + asserts: + - documentSelector: + path: $[?(@.kind == "GRPCRoute")].metadata.name + value: release-name-grpc + equal: + path: spec.rules[0].matches + value: + - path: + type: PathPrefix + value: /test + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-main + equal: + path: spec.rules[0].matches + value: + - path: + type: PathPrefix + value: /test + - documentSelector: + path: $[?(@.kind == "TCPRoute")].metadata.name + value: release-name-tcp + notExists: + path: spec.rules[0].matches + - documentSelector: + path: $[?(@.kind == "TLSRoute")].metadata.name + value: release-name-tls + notExists: + path: spec.rules[0].matches + - documentSelector: + path: $[?(@.kind == "UDPRoute")].metadata.name + value: release-name-udp + notExists: + path: spec.rules[0].matches diff --git a/charts/library/common/test-chart/unittests/route/field_rules_sessionpersistence_test.yaml b/charts/library/common/test-chart/unittests/route/field_rules_sessionpersistence_test.yaml new file mode 100644 index 00000000..3be1a02f --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_rules_sessionpersistence_test.yaml @@ -0,0 +1,118 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - rules - sessionPersistence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: sessionpersistence should only be used for HTTPRoutes and GRPCRoutes + set: + route: + main: + kind: HTTPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + sessionPersistence: + sessionName: test + grpc: + kind: GRPCRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + sessionPersistence: + sessionName: test + tcp: + kind: TCPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + sessionPersistence: + sessionName: test + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + tls: + kind: TLSRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + sessionPersistence: + sessionName: test + udp: + kind: UDPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + kind: Service + weight: 1 + sessionPersistence: + sessionName: test + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplacePrefixMatch + replacePrefixMatch: "" + asserts: + - documentSelector: + path: $[?(@.kind == "GRPCRoute")].metadata.name + value: release-name-grpc + equal: + path: spec.rules[0].sessionPersistence + value: + sessionName: test + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-main + equal: + path: spec.rules[0].sessionPersistence + value: + sessionName: test + - documentSelector: + path: $[?(@.kind == "TCPRoute")].metadata.name + value: release-name-tcp + notExists: + path: spec.rules[0].sessionPersistence + - documentSelector: + path: $[?(@.kind == "TLSRoute")].metadata.name + value: release-name-tls + notExists: + path: spec.rules[0].sessionPersistence + - documentSelector: + path: $[?(@.kind == "UDPRoute")].metadata.name + value: release-name-udp + notExists: + path: spec.rules[0].sessionPersistence diff --git a/charts/library/common/test-chart/unittests/route/field_rules_timeouts_test.yaml b/charts/library/common/test-chart/unittests/route/field_rules_timeouts_test.yaml new file mode 100644 index 00000000..71789db7 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/field_rules_timeouts_test.yaml @@ -0,0 +1,49 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - fields - rules - timeouts +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: timeouts should only be used for HTTPRoutes + set: + route: + main: + kind: HTTPRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + timeouts: + backendRequest: 30s + grpc: + kind: GRPCRoute + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - name: test + namespace: test + matches: + - path: + type: PathPrefix + value: /test + timeouts: + backendRequest: 10s + asserts: + - documentSelector: + path: $[?(@.kind == "GRPCRoute")].metadata.name + value: release-name-grpc + notExists: + path: spec.rules[0].timeouts.backendRequest + - documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name-main + equal: + path: spec.rules[0].timeouts.backendRequest + value: 30s diff --git a/charts/library/common/test-chart/unittests/route/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/route/metadata_annotations_test.yaml new file mode 100644 index 00000000..47a94193 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/metadata_annotations_test.yaml @@ -0,0 +1,48 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + route.main.parentRefs: + - name: test + namespace: test +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + route.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + route.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/route/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/route/metadata_labels_test.yaml new file mode 100644 index 00000000..80587818 --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/metadata_labels_test.yaml @@ -0,0 +1,61 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + route.main.parentRefs: + - name: test + namespace: test +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + route.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + route.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "HTTPRoute")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/route/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/route/metadata_name_test.yaml new file mode 100644 index 00000000..18f00eee --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/metadata_name_test.yaml @@ -0,0 +1,189 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + route.main: + parentRefs: + - name: test + namespace: test +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name + any: true + + - it: forceRename + set: + route.main.forceRename: forceRename + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: forcerename + any: true + + - it: forceRename with template + set: + route.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: common-test + any: true + + - it: prefix + set: + route.main.prefix: prefix + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: prefix-release-name + any: true + + - it: prefix with template + set: + route.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: common-test-release-name + any: true + + - it: suffix + set: + route.main.suffix: suffix + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-suffix + any: true + + - it: suffix with template + set: + route.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + route.main.prefix: prefix + route.main.suffix: suffix + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + route.main.forceRename: forceRename + route.main.prefix: prefix + route.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + route.second: + parentRefs: + - name: test + namespace: test + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-main + any: true + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + route.second: + prefix: prefix + parentRefs: + - name: test + namespace: test + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-main + any: true + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + route.second: + suffix: suffix + parentRefs: + - name: test + namespace: test + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-main + any: true + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + route.second: + prefix: prefix + suffix: suffix + parentRefs: + - name: test + namespace: test + asserts: + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-main + any: true + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + route.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + parentRefs: + - name: test + namespace: test + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/route/metadata_test.yaml b/charts/library/common/test-chart/unittests/route/metadata_test.yaml deleted file mode 100644 index 20338560..00000000 --- a/charts/library/common/test-chart/unittests/route/metadata_test.yaml +++ /dev/null @@ -1,94 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: route metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - route.main: - parentRefs: - - name: test - namespace: test - asserts: - - documentIndex: &routeDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *routeDocument - notExists: - path: metadata.annotations - - documentIndex: *routeDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - route.main: - annotations: - test_annotation: test - labels: - test_label: test - parentRefs: - - name: test - namespace: test - asserts: - - documentIndex: &routeDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *routeDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *routeDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - route.main: - annotations: - test_annotation: test - labels: - test_label: test - parentRefs: - - name: test - namespace: test - asserts: - - documentIndex: &routeDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *routeDocument - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *routeDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/route/names_test.yaml b/charts/library/common/test-chart/unittests/route/names_test.yaml deleted file mode 100644 index f76c5858..00000000 --- a/charts/library/common/test-chart/unittests/route/names_test.yaml +++ /dev/null @@ -1,74 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: route names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default name - set: - route.main: - enabled: true - parentRefs: - - name: test - namespace: test - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME - asserts: - - exists: - path: metadata.name - - - it: custom name suffix - set: - route.main: - enabled: true - parentRefs: - - name: test - namespace: test - nameOverride: http - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-http - asserts: - - exists: - path: metadata.name - - - it: custom name suffix with template - set: - route.main: - enabled: true - parentRefs: - - name: test - namespace: test - nameOverride: "{{ .Chart.Name }}" - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-common-test - asserts: - - exists: - path: metadata.name - - - it: multiple routes - set: - route: - main: - parentRefs: - - name: main - namespace: main - test: - parentRefs: - - name: test - namespace: test - asserts: - - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-main - exists: - path: metadata.name - - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-test - exists: - path: metadata.name diff --git a/charts/library/common/test-chart/unittests/route/presence_test.yaml b/charts/library/common/test-chart/unittests/route/presence_test.yaml index cf4ef812..92fbe0b6 100644 --- a/charts/library/common/test-chart/unittests/route/presence_test.yaml +++ b/charts/library/common/test-chart/unittests/route/presence_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: route presence +suite: route - presence templates: - common.yaml values: @@ -12,7 +12,8 @@ tests: containsDocument: kind: HTTPRoute apiVersion: gateway.networking.k8s.io/v1alpha2 - name: RELEASE-NAME + name: release-name + any: true - it: an HTTPRoute is not created when disabled set: @@ -22,7 +23,8 @@ tests: containsDocument: kind: HTTPRoute apiVersion: gateway.networking.k8s.io/v1alpha2 - name: RELEASE-NAME + name: release-name + any: true - it: an HTTPRoute is created when explicitly enabled set: @@ -31,12 +33,12 @@ tests: parentRefs: - name: test namespace: test - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME asserts: - - exists: - path: metadata.name + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name + any: true - it: multiple HTTPRoute are created when configured set: @@ -50,13 +52,13 @@ tests: - name: test namespace: test asserts: - - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-main - exists: - path: metadata.name - - documentSelector: - path: $[?(@.kind == "HTTPRoute")].metadata.name - value: RELEASE-NAME-test - exists: - path: metadata.name + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-main + any: true + - containsDocument: + kind: HTTPRoute + apiVersion: gateway.networking.k8s.io/v1alpha2 + name: release-name-test + any: true diff --git a/charts/library/common/test-chart/unittests/route/validations_test.yaml b/charts/library/common/test-chart/unittests/route/validations_test.yaml new file mode 100644 index 00000000..e4467a4f --- /dev/null +++ b/charts/library/common/test-chart/unittests/route/validations_test.yaml @@ -0,0 +1,43 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: route - validations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: service reference to non-existing service should fail + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - identifier: main + port: 8080 + asserts: + - failedTemplate: + errorMessage: "No enabled Service found with this identifier. (route: 'main', identifier: 'main')" + + - it: backend refs with redirect filter should fail + set: + route.main: + parentRefs: + - name: parentName + namespace: parentNamespace + rules: + - backendRefs: + - group: test + name: pathService + port: 1234 + namespace: serviceNamespace + weight: 123 + filters: + - type: RequestRedirect + requestRedirect: + scheme: https + statusCode: 301 + asserts: + - failedTemplate: + errorMessage: "backend refs and request redirect filters cannot co-exist." diff --git a/charts/library/common/test-chart/unittests/route/values_test.yaml b/charts/library/common/test-chart/unittests/route/values_test.yaml deleted file mode 100644 index 51869213..00000000 --- a/charts/library/common/test-chart/unittests/route/values_test.yaml +++ /dev/null @@ -1,348 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: route values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: setting gateway should pass - set: - route.main: - parentRefs: - - name: parentName - namespace: parentNamespace - asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: - path: spec.parentRefs[0].name - value: parentName - - documentIndex: *HTTPRouteDocument - equal: - path: spec.parentRefs[0].namespace - value: parentNamespace - - - it: custom host and path should pass - set: - route.main: - parentRefs: - - name: parentName - namespace: parentNamespace - hostnames: - - chart-test.local - asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: - path: spec.hostnames[0] - value: chart-test.local - - - it: custom host with template - set: - route.main: - parentRefs: - - name: parentName - namespace: parentNamespace - hostnames: - - "{{ .Release.Name }}.local" - asserts: - - documentIndex: &HTTPRouteDocument 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: - path: spec.hostnames[0] - value: RELEASE-NAME.local - - - it: path matches should only be used for HTTPRoutes and GRPCRoutes - set: - route: - main: - kind: HTTPRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - kind: Service - weight: 1 - matches: - - path: - type: PathPrefix - value: /test - filters: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - timeouts: - backendRequest: 30s - grpc: - kind: GRPCRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - kind: Service - weight: 1 - matches: - - path: - type: PathPrefix - value: /test - filters: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - tcp: - kind: TCPRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - kind: Service - weight: 1 - matches: - - path: - type: PathPrefix - value: /test - filters: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - tls: - kind: TLSRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - kind: Service - weight: 1 - matches: - - path: - type: PathPrefix - value: /test - filters: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - udp: - kind: UDPRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - kind: Service - weight: 1 - matches: - - path: - type: PathPrefix - value: /test - filters: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - asserts: - - documentIndex: &GRPCRouteDocument 1 - isKind: - of: GRPCRoute - - documentIndex: *GRPCRouteDocument - equal: - path: spec.rules[0].matches - value: - - path: - type: PathPrefix - value: /test - - documentIndex: *GRPCRouteDocument - equal: - path: spec.rules[0].filters - value: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - - documentIndex: &HTTPRouteDocument 2 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: - path: spec.rules[0].matches - value: - - path: - type: PathPrefix - value: /test - - documentIndex: *HTTPRouteDocument - equal: - path: spec.rules[0].filters - value: - - type: URLRewrite - urlRewrite: - path: - type: ReplacePrefixMatch - replacePrefixMatch: "" - - documentIndex: &TCPRouteDocument 3 - isKind: - of: TCPRoute - - documentIndex: *TCPRouteDocument - notExists: - path: spec.rules[0].matches - - documentIndex: *TCPRouteDocument - notExists: - path: spec.rules[0].filters - - documentIndex: &TLSRouteDocument 4 - isKind: - of: TLSRoute - - documentIndex: *TLSRouteDocument - notExists: - path: spec.rules[0].matches - - documentIndex: *TLSRouteDocument - notExists: - path: spec.rules[0].filters - - documentIndex: &UDPRouteDocument 5 - isKind: - of: UDPRoute - - documentIndex: *UDPRouteDocument - notExists: - path: spec.rules[0].matches - - documentIndex: *UDPRouteDocument - notExists: - path: spec.rules[0].filters - - documentIndex: *UDPRouteDocument - notExists: - path: spec.rules[0].timeouts - - - it: hostnames shouldn't be used for TCPRoutes and UDPRoutes - set: - route: - main: - enabled: true - kind: TCPRoute - hostnames: - - chart-test.local - parentRefs: - - name: parentName - namespace: parentNamespace - udp: - enabled: true - kind: UDPRoute - hostnames: - - chart-test.local - parentRefs: - - name: parentName - namespace: parentNamespace - asserts: - - documentIndex: &TCPRouteDocument 1 - isKind: - of: TCPRoute - - documentIndex: *TCPRouteDocument - notExists: - path: spec.hostnames - - documentIndex: &UDPRouteDocument 2 - isKind: - of: UDPRoute - - documentIndex: *UDPRouteDocument - notExists: - path: spec.hostnames - - - it: sectionName in parentRefs should be optional - set: - route: - main: - enabled: true - parentRefs: - - name: parentName - namespace: parentNamespace - second: - enabled: true - parentRefs: - - name: parentName - namespace: parentNamespace - sectionName: parentSection - asserts: - - documentIndex: &HTTPRouteDocumentFirst 1 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocumentFirst - notExists: - path: spec.parentRefs[0].sectionName - - documentIndex: &HTTPRouteDocumentSecond 2 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocumentSecond - equal: - path: spec.parentRefs[0].sectionName - value: parentSection - - - it: timeouts should only be used for HTTPRoutes - set: - route: - main: - enabled: true - kind: HTTPRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - timeouts: - backendRequest: 30s - grpc: - enabled: true - kind: GRPCRoute - parentRefs: - - name: parentName - namespace: parentNamespace - rules: - - backendRefs: - - name: test - namespace: test - matches: - - path: - type: PathPrefix - value: /test - timeouts: - backendRequest: 10s - asserts: - - documentIndex: &GRPCRouteDocument 1 - isKind: - of: GRPCRoute - - documentIndex: *GRPCRouteDocument - notExists: - path: spec.rules[0].timeouts.backendRequest - - documentIndex: &HTTPRouteDocument 2 - isKind: - of: HTTPRoute - - documentIndex: *HTTPRouteDocument - equal: - path: spec.rules[0].timeouts.backendRequest - value: 30s diff --git a/charts/library/common/test-chart/unittests/secret/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/secret/metadata_annotations_test.yaml new file mode 100644 index 00000000..315bcb64 --- /dev/null +++ b/charts/library/common/test-chart/unittests/secret/metadata_annotations_test.yaml @@ -0,0 +1,49 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: secret - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + secrets: + secret: + stringData: + test: test +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + secrets.secret.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + secrets.secret.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/secret/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/secret/metadata_labels_test.yaml new file mode 100644 index 00000000..5a944bfd --- /dev/null +++ b/charts/library/common/test-chart/unittests/secret/metadata_labels_test.yaml @@ -0,0 +1,62 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: secret - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + secrets: + secret: + stringData: + test: test +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + secrets.secret.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + secrets.secret.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Secret")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/secret/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/secret/metadata_name_test.yaml new file mode 100644 index 00000000..e9fc1c8b --- /dev/null +++ b/charts/library/common/test-chart/unittests/secret/metadata_name_test.yaml @@ -0,0 +1,183 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: secret - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + secrets.main: + stringData: + test: test +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + secrets.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + secrets.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + secrets.main.prefix: prefix + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + secrets.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + secrets.main.suffix: suffix + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + secrets.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + secrets.main.prefix: prefix + secrets.main.suffix: suffix + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + secrets.main.forceRename: forceRename + secrets.main.prefix: prefix + secrets.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + secrets.second: + stringData: + test: test + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + secrets.second: + prefix: prefix + stringData: + test: test + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Secret + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + secrets.second: + suffix: suffix + stringData: + test: test + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + secrets.second: + prefix: prefix + suffix: suffix + stringData: + test: test + asserts: + - containsDocument: + kind: Secret + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Secret + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + secrets.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + stringData: + test: test + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/secret/metadata_test.yaml b/charts/library/common/test-chart/unittests/secret/metadata_test.yaml deleted file mode 100644 index 677904a2..00000000 --- a/charts/library/common/test-chart/unittests/secret/metadata_test.yaml +++ /dev/null @@ -1,118 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: secret metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - secrets: - secret: - stringData: - test: test - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - notExists: - path: metadata.annotations - - documentIndex: *SecretDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata should pass - set: - secrets: - secret: - stringData: - test: test - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - test_annotation: test - - documentIndex: *SecretDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata should pass - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - secrets: - secret: - stringData: - test: test - annotations: - test_annotation: test - labels: - test_label: test - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - documentIndex: *SecretDocument - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom secret type should pass - set: - secrets: - secret: - stringData: - test: test - type: &type kubernetes.io/service-account-token - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - equal: - path: type - value: *type diff --git a/charts/library/common/test-chart/unittests/secret/names_test.yaml b/charts/library/common/test-chart/unittests/secret/names_test.yaml deleted file mode 100644 index bb11abb9..00000000 --- a/charts/library/common/test-chart/unittests/secret/names_test.yaml +++ /dev/null @@ -1,93 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: secret names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default should pass - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: Secret - - - it: with disabled secret should pass - set: - secrets: - secret: - enabled: false - stringData: - test: test - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: Secret - - - it: with multiple secrets should pass - set: - secrets: - secret: - enabled: true - stringData: - foo: bar - secondary: - enabled: true - stringData: - test: test - asserts: - - hasDocuments: - count: 3 - - documentIndex: &FirstSecretDocument 1 - isKind: - of: Secret - - documentIndex: *FirstSecretDocument - isNotNullOrEmpty: - path: metadata.name - - documentIndex: &SecondSecretDocument 2 - isKind: - of: Secret - - documentIndex: *SecondSecretDocument - isNotNullOrEmpty: - path: metadata.name - - - it: default name should pass - set: - secrets: - secret: - stringData: - test: test - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - equal: - path: metadata.name - value: RELEASE-NAME-secret - - - it: with nameOverride should pass - set: - secrets: - secret: - stringData: - test: test - nameOverride: http - asserts: - - hasDocuments: - count: 2 - - documentIndex: &SecretDocument 1 - isKind: - of: Secret - - documentIndex: *SecretDocument - equal: - path: metadata.name - value: RELEASE-NAME-http diff --git a/charts/library/common/test-chart/unittests/secret/pod_metadata_test.yaml b/charts/library/common/test-chart/unittests/secret/pod_metadata_test.yaml deleted file mode 100644 index 0d1d52e8..00000000 --- a/charts/library/common/test-chart/unittests/secret/pod_metadata_test.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: secret Pod metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata should pass - set: - secrets: - secret_1: - stringData: - test: value 1 - secret_2: # default enabled - stringData: - test_1: value 1 - test_2: value 2 - test_not_in_checksum: - includeInChecksum: false - stringData: - test: value 1 - test_disabled: - enabled: false - stringData: - test: value 1 - asserts: - - documentIndex: &ControllerDoc 0 - isKind: - of: Deployment - - documentIndex: *ControllerDoc - equal: - path: spec.template.metadata.annotations - value: - checksum/secrets: cd4e5076088172611ca1c43c659a275232d9eeb887acc20575ac141038b9aacb diff --git a/charts/library/common/test-chart/unittests/secret/presence_test.yaml b/charts/library/common/test-chart/unittests/secret/presence_test.yaml new file mode 100644 index 00000000..2226a5ec --- /dev/null +++ b/charts/library/common/test-chart/unittests/secret/presence_test.yaml @@ -0,0 +1,64 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: secret - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: secret is not present by default + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: Secret + any: true + + - it: secrets are enabled by default + set: + secrets: + secret: + stringData: + test: test + asserts: + - containsDocument: + apiVersion: v1 + kind: Secret + any: true + name: release-name + + - it: secret is not present when disabled + set: + secrets: + secret: + enabled: false + stringData: + test: test + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: Secret + any: true + name: release-name + + - it: multiple secrets can be enabled + set: + secrets: + secret: + stringData: + foo: bar + secondary: + stringData: + test: test + asserts: + - containsDocument: + apiVersion: v1 + kind: Secret + any: true + name: release-name-secret + - containsDocument: + apiVersion: v1 + kind: Secret + any: true + name: release-name-secondary diff --git a/charts/library/common/test-chart/unittests/service/field_allocateLoadBalancerNodePorts_test.yaml b/charts/library/common/test-chart/unittests/service/field_allocateLoadBalancerNodePorts_test.yaml new file mode 100644 index 00000000..fd18388b --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_allocateLoadBalancerNodePorts_test.yaml @@ -0,0 +1,36 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - allocateLoadBalancerNodePorts +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: allocateLoadBalancerNodePorts can be set to true + set: + service: + main: + type: LoadBalancer + allocateLoadBalancerNodePorts: true + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.allocateLoadBalancerNodePorts + value: true + + - it: allocateLoadBalancerNodePorts can be set to false + set: + service: + main: + type: LoadBalancer + allocateLoadBalancerNodePorts: false + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.allocateLoadBalancerNodePorts + value: false diff --git a/charts/library/common/test-chart/unittests/service/field_externalName_test.yaml b/charts/library/common/test-chart/unittests/service/field_externalName_test.yaml new file mode 100644 index 00000000..b9f68422 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_externalName_test.yaml @@ -0,0 +1,22 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - externalName +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: externalName can be configured for ExternalName service + set: + service: + main: + type: ExternalName + externalName: my.database.example.com + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.externalName + value: my.database.example.com diff --git a/charts/library/common/test-chart/unittests/service/field_externalTrafficPolicy_test.yaml b/charts/library/common/test-chart/unittests/service/field_externalTrafficPolicy_test.yaml new file mode 100644 index 00000000..a15859e9 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_externalTrafficPolicy_test.yaml @@ -0,0 +1,36 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - externalTrafficPolicy +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: externalTrafficPolicy can be configured for NodePort service + set: + service: + main: + type: NodePort + externalTrafficPolicy: Local + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.externalTrafficPolicy + value: Local + + - it: externalTrafficPolicy can be configured for LoadBalancer service + set: + service: + main: + type: LoadBalancer + externalTrafficPolicy: Local + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.externalTrafficPolicy + value: Local diff --git a/charts/library/common/test-chart/unittests/service/field_internalTrafficPolicy_test.yaml b/charts/library/common/test-chart/unittests/service/field_internalTrafficPolicy_test.yaml new file mode 100644 index 00000000..cdc3e7c2 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_internalTrafficPolicy_test.yaml @@ -0,0 +1,21 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - internalTrafficPolicy +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: internalTrafficPolicy can be configured + set: + service: + main: + internalTrafficPolicy: Local + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.internalTrafficPolicy + value: Local diff --git a/charts/library/common/test-chart/unittests/service/field_ports_appProtocol_test.yaml b/charts/library/common/test-chart/unittests/service/field_ports_appProtocol_test.yaml new file mode 100644 index 00000000..29d1b153 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_ports_appProtocol_test.yaml @@ -0,0 +1,19 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - ports - appProtocol +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: appProtocol can be configured + set: + service.main.ports.http.appProtocol: kubernetes.io/h2c + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.ports[0].appProtocol + value: kubernetes.io/h2c diff --git a/charts/library/common/test-chart/unittests/service/port_protocols_test.yaml b/charts/library/common/test-chart/unittests/service/field_ports_protocol_test.yaml similarity index 56% rename from charts/library/common/test-chart/unittests/service/port_protocols_test.yaml rename to charts/library/common/test-chart/unittests/service/field_ports_protocol_test.yaml index ad3f98df..d312b730 100644 --- a/charts/library/common/test-chart/unittests/service/port_protocols_test.yaml +++ b/charts/library/common/test-chart/unittests/service/field_ports_protocol_test.yaml @@ -1,50 +1,49 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: service protocols +suite: service - fields - ports - protocol templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml tests: - - it: default should render - values: - - ../_values/service_main_default.yaml - documentSelector: &ServiceSelector + - it: protocol should default to TCP + documentSelector: path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - equal: path: spec.ports[0].protocol value: TCP - - it: explicit TCP should render - values: - - ../_values/service_main_default.yaml + - it: protocol can be explicitly set to TCP set: service.main.ports.http.protocol: TCP - documentSelector: *ServiceSelector + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports[0].protocol value: TCP - - it: explicit UDP should render - values: - - ../_values/service_main_default.yaml + - it: protocol can be explicitly set to UDP set: service.main.ports.http.protocol: UDP - documentSelector: *ServiceSelector + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports[0].protocol value: UDP - - it: explicit HTTP should render - values: - - ../_values/service_main_default.yaml + - it: protocol can be explicitly set to HTTP set: service.main.ports.http.protocol: HTTP - documentSelector: *ServiceSelector + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports[0].protocol @@ -52,36 +51,25 @@ tests: - notExists: path: metadata.annotations - - it: explicit HTTPS should render - values: - - ../_values/service_main_default.yaml + - it: protocol can be explicitly set to HTTPS set: service.main.ports.http.protocol: HTTPS - documentSelector: *ServiceSelector + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports[0].protocol value: TCP - - it: explicit appProtocol should render - values: - - ../_values/service_main_default.yaml - set: - service.main.ports.http.appProtocol: kubernetes.io/h2c - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.ports[0].appProtocol - value: kubernetes.io/h2c - - it: mixed protocols can be configured on the same port number - values: - - ../_values/service_main_default.yaml set: service.main.ports.udptest: port: 8081 protocol: UDP - documentSelector: *ServiceSelector + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports diff --git a/charts/library/common/test-chart/unittests/service/field_ports_targetPort_test.yaml b/charts/library/common/test-chart/unittests/service/field_ports_targetPort_test.yaml new file mode 100644 index 00000000..9f78ecfb --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/field_ports_targetPort_test.yaml @@ -0,0 +1,23 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - fields - ports - targetPort +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: targetPort can be configured + set: + service: + main: + ports: + http: + targetPort: 80 + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: spec.ports[0].targetPort + value: 80 diff --git a/charts/library/common/test-chart/unittests/service/ports_test.yaml b/charts/library/common/test-chart/unittests/service/field_ports_test.yaml similarity index 59% rename from charts/library/common/test-chart/unittests/service/ports_test.yaml rename to charts/library/common/test-chart/unittests/service/field_ports_test.yaml index 7f918e00..891d1b4d 100644 --- a/charts/library/common/test-chart/unittests/service/ports_test.yaml +++ b/charts/library/common/test-chart/unittests/service/field_ports_test.yaml @@ -1,17 +1,16 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: service ports +suite: service - fields - ports templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml tests: - - it: default should pass - values: - - ../_values/service_main_default.yaml - documentSelector: &ServiceSelector + - it: ports are enabled by default + documentSelector: path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME + value: release-name asserts: - equal: path: spec.ports[0] @@ -21,9 +20,7 @@ tests: protocol: TCP targetPort: 8081 - - it: custom name should pass - values: - - ../_values/service_main_default.yaml + - it: multiple ports can be configured set: service: main: @@ -33,32 +30,24 @@ tests: server: enabled: true port: 8080 - documentSelector: *ServiceSelector + secondary: + enabled: true + port: 8081 + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name asserts: - equal: path: spec.ports[0] + value: + name: secondary + port: 8081 + protocol: TCP + targetPort: 8081 + - equal: + path: spec.ports[1] value: name: server port: 8080 protocol: TCP targetPort: 8080 - - - it: custom target port should pass - values: - - ../_values/service_main_default.yaml - set: - service: - main: - ports: - http: - enabled: true - targetPort: 80 - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.ports[0] - value: - name: http - port: 8081 - protocol: TCP - targetPort: 80 diff --git a/charts/library/common/test-chart/unittests/service/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/service/metadata_annotations_test.yaml new file mode 100644 index 00000000..481a03fc --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/metadata_annotations_test.yaml @@ -0,0 +1,45 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + service.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + service.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/service/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/service/metadata_labels_test.yaml new file mode 100644 index 00000000..8efd2955 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/metadata_labels_test.yaml @@ -0,0 +1,61 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: release-name + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + service.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: release-name + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + service.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "Service")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: release-name + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/service/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/service/metadata_name_test.yaml new file mode 100644 index 00000000..d2fd37ea --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/metadata_name_test.yaml @@ -0,0 +1,195 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml + - ../_values/service_main_default.yaml +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + service.main.forceRename: forceRename + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + service.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + service.main.prefix: prefix + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + service.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + service.main.suffix: suffix + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + service.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + service.main.prefix: prefix + service.main.suffix: suffix + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + service.main.forceRename: forceRename + service.main.prefix: prefix + service.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + service: + second: + controller: main + ports: + ui: + port: 8082 + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + service: + second: + controller: main + prefix: prefix + ports: + ui: + port: 8082 + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Service + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + service: + second: + controller: main + suffix: suffix + ports: + ui: + port: 8082 + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + service: + second: + controller: main + prefix: prefix + suffix: suffix + ports: + ui: + port: 8082 + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Service + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + service: + second: + controller: main + forceRename: forceRename + prefix: prefix + suffix: suffix + ports: + ui: + port: 8082 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/service/metadata_test.yaml b/charts/library/common/test-chart/unittests/service/metadata_test.yaml deleted file mode 100644 index f26e4205..00000000 --- a/charts/library/common/test-chart/unittests/service/metadata_test.yaml +++ /dev/null @@ -1,84 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: service metadata -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default metadata - values: - - ../_values/service_main_default.yaml - documentSelector: &ServiceSelector - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME - asserts: - - notExists: - path: metadata.annotations - - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - - - it: custom metadata - values: - - ../_values/service_main_default.yaml - set: - service: - main: - annotations: - test_annotation: test - labels: - test_label: test - documentSelector: *ServiceSelector - asserts: - - equal: - path: metadata.annotations - value: - test_annotation: test - - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test_label: test - - - it: custom metadata with global metadata - values: - - ../_values/service_main_default.yaml - set: - global: - labels: - global_label: test - annotations: - global_annotation: test - service: - main: - annotations: - test_annotation: test - labels: - test_label: test - documentSelector: *ServiceSelector - asserts: - - equal: - path: metadata.annotations - value: - global_annotation: test - test_annotation: test - - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - global_label: test - helm.sh/chart: common-test-1.0.0 - test_label: test diff --git a/charts/library/common/test-chart/unittests/service/names_test.yaml b/charts/library/common/test-chart/unittests/service/names_test.yaml deleted file mode 100644 index 98e09346..00000000 --- a/charts/library/common/test-chart/unittests/service/names_test.yaml +++ /dev/null @@ -1,64 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: service names -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: default name - values: - - ../_values/service_main_default.yaml - documentSelector: - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME - asserts: - - equal: - path: metadata.name - value: RELEASE-NAME - - - it: custom name suffix - values: - - ../_values/service_main_default.yaml - set: - service.main.nameOverride: http - documentSelector: - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME-http - asserts: - - exists: - path: metadata.name - - - it: custom name suffix with template - values: - - ../_values/service_main_default.yaml - set: - service.main.nameOverride: "{{ .Chart.Name }}" - documentSelector: - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME-common-test - asserts: - - exists: - path: metadata.name - - - it: multiple services - values: - - ../_values/service_main_default.yaml - set: - service: - second: - controller: main - ports: - ui: - port: 8082 - asserts: - - documentSelector: - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME-main - exists: - path: metadata.name - - documentSelector: - path: $[?(@.kind == "Service")].metadata.name - value: RELEASE-NAME-second - exists: - path: metadata.name diff --git a/charts/library/common/test-chart/unittests/service/presence_test.yaml b/charts/library/common/test-chart/unittests/service/presence_test.yaml new file mode 100644 index 00000000..424210e9 --- /dev/null +++ b/charts/library/common/test-chart/unittests/service/presence_test.yaml @@ -0,0 +1,64 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: service - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: service is not present by default + asserts: + - not: true + containsDocument: + kind: Service + apiVersion: v1 + name: release-name + any: true + + - it: services are enabled by default + values: + - ../_values/service_main_default.yaml + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name + any: true + + - it: service is not present when disabled + values: + - ../_values/service_main_default.yaml + set: + service: + main: + enabled: false + asserts: + - not: true + containsDocument: + kind: Service + apiVersion: v1 + name: release-name + any: true + + - it: multiple services can be enabled + values: + - ../_values/service_main_default.yaml + set: + service: + second: + primary: true + controller: main + ports: + ui: + port: 8082 + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: Service + apiVersion: v1 + name: release-name-second + any: true diff --git a/charts/library/common/test-chart/unittests/service/validations_test.yaml b/charts/library/common/test-chart/unittests/service/validations_test.yaml index f2322125..6a0d663f 100644 --- a/charts/library/common/test-chart/unittests/service/validations_test.yaml +++ b/charts/library/common/test-chart/unittests/service/validations_test.yaml @@ -1,6 +1,6 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: Service validations +suite: service - validations templates: - common.yaml values: @@ -14,3 +14,44 @@ tests: asserts: - failedTemplate: errorMessage: "No enabled controller found with this identifier. (service: 'main', controller: 'other')" + + - it: automatic controller determination should fail when no controller is enabled + set: + controllers: + main: + enabled: false + service: + main: {} + asserts: + - failedTemplate: + errorMessage: "controller field is required because automatic controller detection is not possible. (service: main)" + + - it: automatic controller determination should fail when >1 controller is enabled + set: + controllers: + second: + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + + service: + main: {} + asserts: + - failedTemplate: + errorMessage: "controller field is required because automatic controller detection is not possible. (service: main)" + + + - it: no ports enabled should fail + values: + - ../_values/service_main_default.yaml + set: + service: + main: + ports: + http: + enabled: false + asserts: + - failedTemplate: + errorMessage: "No ports are enabled for Service with this identifier. (service: 'main')" diff --git a/charts/library/common/test-chart/unittests/service/values_test.yaml b/charts/library/common/test-chart/unittests/service/values_test.yaml deleted file mode 100644 index 324a4a7b..00000000 --- a/charts/library/common/test-chart/unittests/service/values_test.yaml +++ /dev/null @@ -1,122 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: service values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: ports and services are enabled by default - set: - service: - second: - type: ClusterIP - controller: main - ports: - first: - port: 80 - documentSelector: &ServiceSelector - path: kind - value: Service - asserts: - - containsDocument: - kind: Service - apiVersion: v1 - name: RELEASE-NAME - - - it: service not present when disabled - values: - - ../_values/service_main_default.yaml - set: - service: - main: - enabled: false - asserts: - - not: true - containsDocument: - kind: Service - apiVersion: v1 - name: RELEASE-NAME - - - it: externalTrafficPolicy can be configured for NodePort service - values: - - ../_values/service_main_default.yaml - set: - service: - main: - type: NodePort - externalTrafficPolicy: Local - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.externalTrafficPolicy - value: Local - - - it: internalTrafficPolicy can be configured - values: - - ../_values/service_main_default.yaml - set: - service: - main: - internalTrafficPolicy: Local - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.internalTrafficPolicy - value: Local - - - it: externalTrafficPolicy can be configured for LoadBalancer service - values: - - ../_values/service_main_default.yaml - set: - service: - main: - type: LoadBalancer - externalTrafficPolicy: Local - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.externalTrafficPolicy - value: Local - - - it: allocateLoadBalancerNodePorts can be set to true - values: - - ../_values/service_main_default.yaml - set: - service: - main: - type: LoadBalancer - allocateLoadBalancerNodePorts: true - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.allocateLoadBalancerNodePorts - value: true - - - it: allocateLoadBalancerNodePorts can be set to false - values: - - ../_values/service_main_default.yaml - set: - service: - main: - type: LoadBalancer - allocateLoadBalancerNodePorts: false - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.allocateLoadBalancerNodePorts - value: false - - - it: externalName can be configured for ExternalName service - values: - - ../_values/service_main_default.yaml - set: - service: - main: - type: ExternalName - externalName: my.database.example.com - documentSelector: *ServiceSelector - asserts: - - equal: - path: spec.externalName - value: my.database.example.com diff --git a/charts/library/common/test-chart/unittests/serviceAccount/field_secrets_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/field_secrets_test.yaml new file mode 100644 index 00000000..40dafd57 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceAccount/field_secrets_test.yaml @@ -0,0 +1,56 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceAccount - fields - secrets +templates: + - common.yaml +set: + serviceAccount.main: {} +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: serviceAccount is created without a static token by default + asserts: + - documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + notExists: + path: secrets + - not: true + containsDocument: + apiVersion: v1 + kind: Secret + name: release-name-main-sa-token + any: true + + - it: serviceAccount can be created without a static token + set: + serviceAccount.main.staticToken: false + asserts: + - documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + notExists: + path: secrets + - not: true + containsDocument: + apiVersion: v1 + kind: Secret + name: release-name-main-sa-token + any: true + + - it: serviceAccount can be created with a static token + set: + serviceAccount.main.staticToken: true + asserts: + - documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + equal: + path: secrets + value: + - name: release-name-main-sa-token + - containsDocument: + apiVersion: v1 + kind: Secret + name: release-name-main-sa-token + any: true diff --git a/charts/library/common/test-chart/unittests/serviceAccount/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/metadata_annotations_test.yaml new file mode 100644 index 00000000..f35efa51 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceAccount/metadata_annotations_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceAccount - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceAccount: + main: {} +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + serviceAccount.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + serviceAccount.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/serviceAccount/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/metadata_labels_test.yaml new file mode 100644 index 00000000..3329f91c --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceAccount/metadata_labels_test.yaml @@ -0,0 +1,60 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceAccount - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceAccount: + main: {} +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + serviceAccount.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + serviceAccount.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "ServiceAccount")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/serviceAccount/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/metadata_name_test.yaml new file mode 100644 index 00000000..bb8c2e1f --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceAccount/metadata_name_test.yaml @@ -0,0 +1,171 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceAccount - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceAccount.main: {} +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name + any: true + + - it: forceRename + set: + serviceAccount.main.forceRename: forceRename + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: forcerename + any: true + + - it: forceRename with template + set: + serviceAccount.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: common-test + any: true + + - it: prefix + set: + serviceAccount.main.prefix: prefix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + serviceAccount.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: common-test-release-name + any: true + + - it: suffix + set: + serviceAccount.main.suffix: suffix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + serviceAccount.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + serviceAccount.main.prefix: prefix + serviceAccount.main.suffix: suffix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + serviceAccount.main.forceRename: forceRename + serviceAccount.main.prefix: prefix + serviceAccount.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + serviceAccount.second: {} + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + serviceAccount.second: + prefix: prefix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + serviceAccount.second: + suffix: suffix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + serviceAccount.second: + prefix: prefix + suffix: suffix + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + serviceAccount.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/serviceAccount/presence_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/presence_test.yaml new file mode 100644 index 00000000..97d96ceb --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceAccount/presence_test.yaml @@ -0,0 +1,65 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceAccount - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: serviceAccount is not created by default + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: ServiceAccount + any: true + + - it: serviceAccounts are enabled by default + set: + serviceAccount: + main: {} + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name + any: true + + - it: serviceAccounts can be disabled + set: + serviceAccount: + default: + enabled: false + asserts: + - not: true + containsDocument: + apiVersion: v1 + kind: ServiceAccount + name: release-name + any: true + + - it: multiple serviceAccounts can be enabled + set: + serviceAccount: + myAccount: {} + mySA: {} + mySA2: + enabled: false + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: release-name-myaccount + any: true + - not: true + containsDocument: + apiVersion: v1 + kind: ServiceAccount + name: release-name-mysa2 + any: true + - not: true + containsDocument: + apiVersion: v1 + kind: Secret + name: release-name-mysa2-sa-token + any: true diff --git a/charts/library/common/test-chart/unittests/serviceAccount/serviceaccount_test.yaml b/charts/library/common/test-chart/unittests/serviceAccount/serviceaccount_test.yaml deleted file mode 100644 index 1c44598b..00000000 --- a/charts/library/common/test-chart/unittests/serviceAccount/serviceaccount_test.yaml +++ /dev/null @@ -1,256 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: serviceAccount values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: a serviceAccount is not created by default - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: ServiceAccount - - - it: a serviceAccount is not created when disabled - set: - serviceAccount: - create: false - asserts: - - hasDocuments: - count: 1 - - documentIndex: 0 - not: true - isKind: - of: ServiceAccount - - - it: controller uses named ServiceAccount by default - set: - serviceAccount: - create: false - name: &ServiceAccountName test - - asserts: - - hasDocuments: - count: 1 - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *ServiceAccountName - - - it: controller uses `default` ServiceAccount if flag is enabled - set: - enforceServiceAccountCreation: true - serviceAccount: - create: false - name: test - - asserts: - - hasDocuments: - count: 1 - - documentIndex: &DeploymentDocument 0 - isKind: - of: Deployment - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: default - - - it: a serviceAccount and Secret are created when enabled - set: - serviceAccount: - create: true - asserts: - - hasDocuments: - count: 3 - - documentIndex: &ServiceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &DeploymentDocument 1 - isKind: - of: Deployment - - documentIndex: &SecretDocument 2 - isKind: - of: Secret - - documentIndex: *ServiceAccountDocument - equal: - path: metadata.name - value: &ServiceAccountName RELEASE-NAME - - documentIndex: *ServiceAccountDocument - equal: - path: secrets - value: - - name: RELEASE-NAME-default-sa-token - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *ServiceAccountName - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: RELEASE-NAME - - - it: a serviceAccount and Secret are created with custom name - set: - serviceAccount: - create: true - name: &ServiceAccountName myAccount - asserts: - - hasDocuments: - count: 3 - - documentIndex: &ServiceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &DeploymentDocument 1 - isKind: - of: Deployment - - documentIndex: &SecretDocument 2 - isKind: - of: Secret - - documentIndex: *ServiceAccountDocument - equal: - path: metadata.name - value: *ServiceAccountName - - documentIndex: *ServiceAccountDocument - equal: - path: secrets - value: - - name: RELEASE-NAME-default-sa-token - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *ServiceAccountName - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: *ServiceAccountName - - - it: multiple serviceAccounts and Secrets are created when enabled - set: - serviceAccount: - create: true - name: &ServiceAccountName myAccount - extraServiceAccounts: - mySA: - create: true - asserts: - - hasDocuments: - count: 5 - - documentIndex: &ServiceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &ServiceAccountDocument2 1 - isKind: - of: ServiceAccount - - documentIndex: &DeploymentDocument 2 - isKind: - of: Deployment - - documentIndex: &SecretDocument 3 - isKind: - of: Secret - - documentIndex: &SecretDocument2 4 - isKind: - of: Secret - - documentIndex: *ServiceAccountDocument - equal: - path: metadata.name - value: *ServiceAccountName - - documentIndex: *ServiceAccountDocument2 - equal: - path: metadata.name - value: RELEASE-NAME-mySA - - documentIndex: *ServiceAccountDocument - equal: - path: secrets - value: - - name: RELEASE-NAME-default-sa-token - - documentIndex: *ServiceAccountDocument2 - equal: - path: secrets - value: - - name: RELEASE-NAME-mySA-sa-token - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *ServiceAccountName - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: *ServiceAccountName - - documentIndex: *SecretDocument2 - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: RELEASE-NAME-mySA - - - it: multiple serviceAccounts and Secrets are created with custom names - set: - serviceAccount: - create: true - name: &ServiceAccountName myAccount - extraServiceAccounts: - mySA: - create: true - name: &ServiceAccountName2 mySAcustom - mySA2: - create: false - name: &ServiceAccountName3 mySAcustom2 - asserts: - - hasDocuments: - count: 5 - - documentIndex: &ServiceAccountDocument 0 - isKind: - of: ServiceAccount - - documentIndex: &ServiceAccountDocument2 1 - isKind: - of: ServiceAccount - - documentIndex: &DeploymentDocument 2 - isKind: - of: Deployment - - documentIndex: &SecretDocument 3 - isKind: - of: Secret - - documentIndex: &SecretDocument2 4 - isKind: - of: Secret - - documentIndex: *ServiceAccountDocument - equal: - path: metadata.name - value: *ServiceAccountName - - documentIndex: *ServiceAccountDocument2 - equal: - path: metadata.name - value: *ServiceAccountName2 - - documentIndex: *ServiceAccountDocument - equal: - path: secrets - value: - - name: RELEASE-NAME-default-sa-token - - documentIndex: *ServiceAccountDocument2 - equal: - path: secrets - value: - - name: RELEASE-NAME-mySA-sa-token - - documentIndex: *DeploymentDocument - equal: - path: spec.template.spec.serviceAccountName - value: *ServiceAccountName - - documentIndex: *SecretDocument - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: *ServiceAccountName - - documentIndex: *SecretDocument2 - equal: - path: metadata.annotations - value: - kubernetes.io/service-account.name: *ServiceAccountName2 diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/field_endpoints_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/field_endpoints_test.yaml new file mode 100644 index 00000000..4daf3cc8 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/field_endpoints_test.yaml @@ -0,0 +1,96 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - fields - endpoints +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: a serviceMonitor can be configured with regular endpoints + set: + serviceMonitor: + main: + labels: + test.label: testvalue + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: spec.namespaceSelector + value: + matchNames: + - NAMESPACE + - equal: + path: spec.jobLabel + value: release-name + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: RELEASE-NAME + - equal: + path: spec.endpoints + value: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test.label: testvalue + + + - it: a serviceMonitor can be configured with templated endpoints + set: + serviceMonitor: + main: + labels: + test.label: testvalue + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + basicAuth: + username: + name: "{{.Release.Name}}-secret" + key: USERNAME + password: + name: "{{.Release.Name}}-secret" + key: PASSWORD + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: spec.endpoints + value: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + basicAuth: + username: + name: RELEASE-NAME-secret + key: USERNAME + password: + name: RELEASE-NAME-secret + key: PASSWORD diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/field_selector_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/field_selector_test.yaml new file mode 100644 index 00000000..7e06c1d7 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/field_selector_test.yaml @@ -0,0 +1,31 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - fields - selector +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: a custom selector can be configured + set: + serviceMonitor: + main: + selector: + matchExpressions: + - {key: k8s-app, operator: Exists} + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: spec.selector + value: + matchExpressions: + - key: k8s-app + operator: Exists diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/field_serviceName_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/field_serviceName_test.yaml new file mode 100644 index 00000000..0a5a37ab --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/field_serviceName_test.yaml @@ -0,0 +1,29 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - fields - serviceName +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: a templated service can be configured + set: + serviceMonitor: + main: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: spec.selector.matchLabels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/name: RELEASE-NAME + app.kubernetes.io/service: RELEASE-NAME diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/field_targetLabels_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/field_targetLabels_test.yaml new file mode 100644 index 00000000..57011a12 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/field_targetLabels_test.yaml @@ -0,0 +1,31 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - field - targetLabels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: targetLabels can be configured + set: + serviceMonitor: + main: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + targetLabels: + - testlabel1 + - testlabel2 + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: spec.targetLabels + value: + - testlabel1 + - testlabel2 diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_annotations_test.yaml new file mode 100644 index 00000000..42474d59 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_annotations_test.yaml @@ -0,0 +1,54 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceMonitor: + main: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + serviceMonitor.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + serviceMonitor.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_labels_test.yaml new file mode 100644 index 00000000..ec88b78e --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_labels_test.yaml @@ -0,0 +1,67 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceMonitor: + main: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + serviceMonitor.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + serviceMonitor.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "ServiceMonitor")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_name_test.yaml new file mode 100644 index 00000000..02a6fe88 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/metadata_name_test.yaml @@ -0,0 +1,213 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + serviceMonitor.main: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name + any: true + + - it: forceRename + set: + serviceMonitor.main.forceRename: forceRename + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + serviceMonitor.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: common-test + any: true + + - it: prefix + set: + serviceMonitor.main.prefix: prefix + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + serviceMonitor.main.prefix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: common-test-release-name + any: true + + - it: suffix + set: + serviceMonitor.main.suffix: suffix + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + serviceMonitor.main.suffix: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-common-test + any: true + + - it: both prefix and suffix + set: + serviceMonitor.main.prefix: prefix + serviceMonitor.main.suffix: suffix + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + serviceMonitor.main.forceRename: forceRename + serviceMonitor.main.prefix: prefix + serviceMonitor.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + serviceMonitor.second: + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + serviceMonitor.second: + prefix: prefix + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + serviceMonitor.second: + suffix: suffix + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + serviceMonitor.second: + prefix: prefix + suffix: suffix + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: release-name-main + any: true + - containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + serviceMonitor.second: + forceRename: forceRename + prefix: prefix + suffix: suffix + serviceName: "{{ .Release.Name }}" + endpoints: + - port: http + scheme: http + path: /metrics + interval: 1m + scrapeTimeout: 10s + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/presence_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/presence_test.yaml new file mode 100644 index 00000000..b7a79f43 --- /dev/null +++ b/charts/library/common/test-chart/unittests/serviceMonitor/presence_test.yaml @@ -0,0 +1,30 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: serviceMonitor - presence +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: a serviceMonitor is not created by default + asserts: + - not: true + containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: RELEASE-NAME + any: true + + - it: a serviceMonitor is not created when disabled + set: + serviceMonitor: + main: + enabled: false + serviceName: test + asserts: + - not: true + containsDocument: + kind: ServiceMonitor + apiVersion: monitoring.coreos.com/v1 + name: RELEASE-NAME + any: true diff --git a/charts/library/common/test-chart/unittests/serviceMonitor/servicemonitor_test.yaml b/charts/library/common/test-chart/unittests/serviceMonitor/servicemonitor_test.yaml deleted file mode 100644 index aaf23cc0..00000000 --- a/charts/library/common/test-chart/unittests/serviceMonitor/servicemonitor_test.yaml +++ /dev/null @@ -1,218 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: serviceMonitor values -templates: - - common.yaml -values: - - ../_values/controllers_main_default_container.yaml -tests: - - it: a serviceMonitor is not created by default - asserts: - - not: true - containsDocument: - kind: ServiceMonitor - apiVersion: monitoring.coreos.com/v1 - name: RELEASE-NAME - - - it: a serviceMonitor is not created when disabled - set: - serviceMonitor: - main: - enabled: false - serviceName: "{{ .Release.Name }}" - asserts: - - not: true - containsDocument: - kind: ServiceMonitor - apiVersion: monitoring.coreos.com/v1 - name: RELEASE-NAME - - - it: a serviceMonitor can be configured - set: - serviceMonitor: - main: - labels: - test.label: testvalue - serviceName: "{{ .Release.Name }}" - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - documentSelector: &ServiceMonitorSelector - path: $[?(@.kind == "ServiceMonitor")].metadata.name - value: RELEASE-NAME - asserts: - - equal: - path: spec.namespaceSelector - value: - matchNames: - - NAMESPACE - - equal: - path: spec.jobLabel - value: RELEASE-NAME - - equal: - path: spec.selector.matchLabels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - - equal: - path: spec.endpoints - value: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - - equal: - path: metadata.labels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: RELEASE-NAME - helm.sh/chart: common-test-1.0.0 - test.label: testvalue - - - it: a serviceMonitor can be created with a nameOverride - set: - serviceMonitor: - main: - nameOverride: test - serviceName: "{{ .Release.Name }}" - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - documentSelector: - path: $[?(@.kind == "ServiceMonitor")].metadata.name - value: RELEASE-NAME-test - asserts: - - equal: - path: spec.selector.matchLabels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - - - it: a templated service can be configured - set: - serviceMonitor: - main: - serviceName: "{{ .Release.Name }}" - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - documentSelector: *ServiceMonitorSelector - asserts: - - equal: - path: spec.selector.matchLabels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - - - it: a custom selector can be configured - set: - serviceMonitor: - main: - selector: - matchExpressions: - - {key: k8s-app, operator: Exists} - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - documentSelector: *ServiceMonitorSelector - asserts: - - equal: - path: spec.selector - value: - matchExpressions: - - key: k8s-app - operator: Exists - - - it: targetLabels can be configured - set: - serviceMonitor: - main: - enabled: true - serviceName: "{{ .Release.Name }}" - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - targetLabels: - - testlabel1 - - testlabel2 - documentSelector: *ServiceMonitorSelector - asserts: - - equal: - path: spec.selector.matchLabels - value: - app.kubernetes.io/instance: RELEASE-NAME - app.kubernetes.io/name: RELEASE-NAME - app.kubernetes.io/service: RELEASE-NAME - - equal: - path: spec.endpoints - value: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - - equal: - path: spec.targetLabels - value: - - testlabel1 - - testlabel2 - - - it: a serviceMonitor can be configured with templated endpoints - set: - serviceMonitor: - main: - labels: - test.label: testvalue - serviceName: "{{ .Release.Name }}" - endpoints: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - basicAuth: - username: - name: "{{.Release.Name}}-secret" - key: USERNAME - password: - name: "{{.Release.Name}}-secret" - key: PASSWORD - documentSelector: &ServiceMonitorSelector - path: $[?(@.kind == "ServiceMonitor")].metadata.name - value: RELEASE-NAME - asserts: - - equal: - path: spec.endpoints - value: - - port: http - scheme: http - path: /metrics - interval: 1m - scrapeTimeout: 10s - basicAuth: - username: - name: RELEASE-NAME-secret - key: USERNAME - password: - name: RELEASE-NAME-secret - key: PASSWORD diff --git a/charts/library/common/test-chart/unittests/statefulset/field_revisionhistorylimit_test.yaml b/charts/library/common/test-chart/unittests/statefulset/field_revisionhistorylimit_test.yaml new file mode 100644 index 00000000..051c3ddf --- /dev/null +++ b/charts/library/common/test-chart/unittests/statefulset/field_revisionhistorylimit_test.yaml @@ -0,0 +1,42 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: statefulset - fields - revisionHistoryLimit +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: statefulset +tests: + - it: default should pass + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 3 + + - it: custom revisionHistoryLimit + set: + controllers.main: + revisionHistoryLimit: 8 + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 8 + + - it: explicit revisionHistoryLimit 0 should pass + set: + controllers.main: + revisionHistoryLimit: 0 + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: spec.revisionHistoryLimit + value: 0 diff --git a/charts/library/common/test-chart/unittests/persistence/volumeclaimtemplates_test.yaml b/charts/library/common/test-chart/unittests/statefulset/field_volumeclaimtemplates_test.yaml similarity index 72% rename from charts/library/common/test-chart/unittests/persistence/volumeclaimtemplates_test.yaml rename to charts/library/common/test-chart/unittests/statefulset/field_volumeclaimtemplates_test.yaml index 1261a96c..39fa1451 100644 --- a/charts/library/common/test-chart/unittests/persistence/volumeclaimtemplates_test.yaml +++ b/charts/library/common/test-chart/unittests/statefulset/field_volumeclaimtemplates_test.yaml @@ -1,38 +1,35 @@ --- # yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json -suite: persistence volumeclaimtemplates +suite: statefulset - fields - volumeClaimTemplates templates: - common.yaml values: - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: statefulset tests: - it: default should pass - set: - controllers.main: - type: statefulset + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - notExists: + - notExists: path: spec.volumeClaimTemplates - it: volumeClaimTemplates should pass set: controllers.main: - type: statefulset statefulset: volumeClaimTemplates: - name: "storage" size: "10Gi" accessMode: "ReadWriteOnce" + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.volumeClaimTemplates[0] value: metadata: @@ -47,7 +44,6 @@ tests: - it: volumeClaimTemplates with dataSource should pass set: controllers.main: - type: statefulset statefulset: volumeClaimTemplates: - name: "storage" @@ -57,12 +53,11 @@ tests: apiGroup: snapshot.storage.k8s.io kind: VolumeSnapshot name: MySnapshot + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.volumeClaimTemplates[0].spec.dataSource value: apiGroup: snapshot.storage.k8s.io @@ -72,7 +67,6 @@ tests: - it: volumeClaimTemplates with templated dataSource name should pass set: controllers.main: - type: statefulset statefulset: volumeClaimTemplates: - name: "storage" @@ -82,11 +76,10 @@ tests: apiGroup: snapshot.storage.k8s.io kind: VolumeSnapshot name: "{{ .Release.Name }}-config" + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name asserts: - - documentIndex: &StatefulSetDoc 0 - isKind: - of: StatefulSet - - documentIndex: *StatefulSetDoc - equal: + - equal: path: spec.volumeClaimTemplates[0].spec.dataSource.name value: RELEASE-NAME-config diff --git a/charts/library/common/test-chart/unittests/statefulset/metadata_annotations_test.yaml b/charts/library/common/test-chart/unittests/statefulset/metadata_annotations_test.yaml new file mode 100644 index 00000000..22bef4fd --- /dev/null +++ b/charts/library/common/test-chart/unittests/statefulset/metadata_annotations_test.yaml @@ -0,0 +1,47 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: statefulset - metadata - annotations +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: statefulset +tests: + - it: no annotations are set by default + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - notExists: + path: metadata.annotations + + - it: custom annotations + set: + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + test_annotation: test + + - it: custom annotations mixed with global annotations + set: + global.annotations: + global_annotation: test + controllers.main.annotations: + test_annotation: test + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.annotations + value: + global_annotation: test + test_annotation: test diff --git a/charts/library/common/test-chart/unittests/statefulset/metadata_labels_test.yaml b/charts/library/common/test-chart/unittests/statefulset/metadata_labels_test.yaml new file mode 100644 index 00000000..b37848c5 --- /dev/null +++ b/charts/library/common/test-chart/unittests/statefulset/metadata_labels_test.yaml @@ -0,0 +1,63 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: statefulset - metadata - labels +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main: + type: statefulset +tests: + - it: default labels + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + + - it: custom labels + set: + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + test_label: test + + - it: custom labels mixed with global labels + set: + global.labels: + global_label: test + controllers.main.labels: + test_label: test + documentSelector: + path: $[?(@.kind == "StatefulSet")].metadata.name + value: release-name + asserts: + - equal: + path: metadata.labels + value: + app.kubernetes.io/controller: main + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + global_label: test + helm.sh/chart: common-test-1.0.0 + test_label: test diff --git a/charts/library/common/test-chart/unittests/statefulset/metadata_name_test.yaml b/charts/library/common/test-chart/unittests/statefulset/metadata_name_test.yaml new file mode 100644 index 00000000..d8bec7f8 --- /dev/null +++ b/charts/library/common/test-chart/unittests/statefulset/metadata_name_test.yaml @@ -0,0 +1,206 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: statefulset - metadata - name +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +set: + controllers.main.type: statefulset +tests: + - it: name defaults to chart fullName + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name + any: true + + - it: forceRename + set: + controllers.main.forceRename: forceRename + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: forcerename + any: true + + - it: forceRename with template + set: + controllers.main.forceRename: "{{ .Chart.Name }}" + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: common-test + any: true + + - it: prefix + set: + controllers.main.prefix: prefix + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: prefix-release-name + any: true + + - it: prefix with template + set: + controllers.main.prefix: "{{ .Chart.Name }}-prefix" + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: common-test-prefix-release-name + any: true + + - it: suffix + set: + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-suffix + any: true + + - it: suffix with template + set: + controllers.main.suffix: "{{ .Chart.Name }}-suffix" + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-common-test-suffix + any: true + + - it: both prefix and suffix + set: + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: prefix-release-name-suffix + any: true + + - it: prefix, suffix and forceRename (illegal combination) + set: + controllers.main.forceRename: forceRename + controllers.main.prefix: prefix + controllers.main.suffix: suffix + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" + + - it: multiple items + set: + controllers: + second: + type: statefulset + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-second + any: true + + - it: multiple items with prefix + set: + controllers: + second: + type: statefulset + prefix: prefix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: prefix-release-name-second + any: true + + - it: multiple items with suffix + set: + controllers: + second: + type: statefulset + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-second-suffix + any: true + + - it: multiple items with prefix and suffix + set: + controllers: + second: + type: statefulset + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: release-name-main + any: true + - containsDocument: + kind: StatefulSet + apiVersion: apps/v1 + name: prefix-release-name-second-suffix + any: true + + - it: multiple items with prefix, suffix and forceRename (illegal combination) + set: + controllers: + second: + type: statefulset + forceRename: forceRename + prefix: prefix + suffix: suffix + containers: + main: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - failedTemplate: + errorPattern: "values don't meet the specifications of the schema" diff --git a/charts/library/common/values.schema.json b/charts/library/common/values.schema.json index fddf14c0..72eed6d8 100644 --- a/charts/library/common/values.schema.json +++ b/charts/library/common/values.schema.json @@ -1,90 +1,151 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.7.3/charts/library/common/values.schema.json", + "$id": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json", "type": "object", "properties": { "global": { + "description": "Allows for configuring chart-wide settings", "type": "object", "properties": { "nameOverride": { + "description": "Override the chart name", "type": [ "string", "null" ] }, "fullnameOverride": { + "description": "Override the chart fullname definition", "type": [ "string", "null" ] }, "propagateGlobalMetadataToPods": { + "description": "Propagate global metadata to Pod labels", "type": "boolean", "default": false }, "labels": { + "description": "Set additional global labels. Helm templates can be used.", + "type": "object", "$ref": "schemas/definitions.json#/labels" }, "annotations": { + "description": "Set additional global annotations. Helm templates can be used.", + "type": "object", "$ref": "schemas/definitions.json#/annotations" } } }, + "defaultPodOptionsStrategy": { + "description": "Set the strategy for the default pod options.\noverwrite: If pod-level options are set, use those instead of the defaults.\nmerge: If pod-level options are set, merge them with the defaults.", + "type": "string", + "default": "overwrite", + "enum": [ + "overwrite", + "merge" + ] + }, "defaultPodOptions": { + "description": "Define defaults for pod-level configuration options", + "type": "object", "$ref": "schemas/pod.json#/options" }, "controllers": { + "description": "Define the Pod controllers to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/controllers.json#/instance" } }, - "enforceServiceAccountCreation": { - "type": "boolean" - }, "serviceAccount": { - "$ref": "schemas/serviceAccount.json#/settings" + "description": "Kubernetes serviceAccount objects to be generated by the chart", + "type": "object", + "additionalProperties": { + "$ref": "schemas/serviceAccount.json#/instance" + } }, "configMaps": { + "description": "Kubernetes ConfigMaps to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/configmap.json#/instance" } }, "secrets": { + "description": "Kubernetes Secrets to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/secret.json#/instance" } }, "ingress": { + "description": "Kubernetes Ingress objects to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/ingress.json#/instance" } }, "route": { + "description": "Kubernetes Gateway API *Route objects to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/route.json#/instance" } }, "service": { + "description": "Kubernetes Service objects to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/service.json#/instance" } }, "serviceMonitor": { + "description": "serviceMonitor objects to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/serviceMonitor.json#/instance" } }, "networkpolicies": { + "description": "networkPolicy objects to be generated by the chart", + "type": "object", "additionalProperties": { "$ref": "schemas/networkpolicy.json#/instance" } }, "persistence": { + "description": "Options to configure persistent storage and mount options", + "type": "object", "additionalProperties": { "$ref": "schemas/persistence.json#/item" } }, + "rbac": { + "description": "Configure the Roles and Role Bindings for the chart here", + "type": "object", + "properties": { + "roles": { + "description": "(Cluster)Role objects to be generated by the chart", + "type": "object", + "additionalProperties": { + "$ref": "schemas/rbac.json#/role" + } + }, + "bindings": { + "description": "(Cluster)RoleBinding objects to be generated by the chart", + "type": "object", + "additionalProperties": { + "$ref": "schemas/rbac.json#/roleBinding" + } + } + }, + "additionalProperties": false + }, "rawResources": { + "description": "Allows for the inclusion of raw Kubernetes resources that are not supported by the chart otherwise​", + "type": "object", "additionalProperties": { "$ref": "schemas/rawResource.json#/instance" } diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index cce9ab99..2aa6188e 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -11,6 +11,12 @@ global: # -- Set additional global annotations. Helm templates can be used. annotations: {} +# -- Set the strategy for the default pod options. Defaults to +# overwrite: If pod-level options are set, use those instead of the defaults. +# merge: If pod-level options are set, merge them with the defaults +# @default -- overwrite +defaultPodOptionsStrategy: overwrite + # -- Set default options for all controllers / pods here # Each of these options can be overridden on a Controller level defaultPodOptions: @@ -408,37 +414,12 @@ controllers: {} # # Each initContainer should have its own key # initContainers: {} -# -- If true forces the controllers to use the `default` ServiceAccount for the namespace if one is not explicitly defined. -# This feature flag will be removed on future versions where this will be the default behavior. -enforceServiceAccountCreation: false - serviceAccount: - # -- Specifies whether a service account should be created - # The identifier for this ServiceAccount will be `default` - create: false - - # -- Annotations to add to the service account - annotations: {} - - # -- Labels to add to the service account - labels: {} - - # -- The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - - # -- Additional Service Accounts to create - # Each extra service account admit the same keys as the main service account - extraServiceAccounts: {} - # serviceAccount2: - # create: true - # annotations: - # test: test - # serviceAccount3: - # create: true - # name: custom-service-account - # labels: - # test: test + {} + # default: + # enabled: false + # annotations: {} + # labels: {} # -- Use this to populate secrets with the values you specify. # Be aware that these values are not encrypted by default, and could therefore visible diff --git a/charts/other/app-template/Chart.yaml b/charts/other/app-template/Chart.yaml index 6e3de9a1..bddab183 100644 --- a/charts/other/app-template/Chart.yaml +++ b/charts/other/app-template/Chart.yaml @@ -2,22 +2,24 @@ apiVersion: v2 description: A common powered chart template. This can be useful for small projects that don't have their own chart. name: app-template -version: 3.7.3 -kubeVersion: ">=1.22.0-0" +version: 4.0.0 +kubeVersion: ">=1.28.0-0" maintainers: - name: bjw-s email: me@bjw-s.dev dependencies: - name: common repository: https://bjw-s-labs.github.io/helm-charts - version: 3.7.3 + version: 4.0.0 sources: - https://github.com/bjw-s-labs/helm-charts annotations: artifacthub.io/changes: |- - - kind: fixed + - kind: changed description: |- - Fixed name suffix for HTTPRoute - - kind: fixed - description: |- - Fixed incorrect default backendRefs values in HTTPRoute + Upgraded the common library to v4.0.0 + links: + - name: Upgrade notes + url: https://bjw-s-labs.github.io/helm-charts/docs/app-template/upgrade-instructions/ + - name: Detailed release notes + url: https://github.com/bjw-s-labs/helm-charts/releases/tag/common-4.0.0 diff --git a/charts/other/app-template/README.md b/charts/other/app-template/README.md index 8940794f..a4e4bbc0 100644 --- a/charts/other/app-template/README.md +++ b/charts/other/app-template/README.md @@ -1,29 +1,38 @@ # app-template -![Version: 3.7.3](https://img.shields.io/badge/Version-3.7.3-informational?style=flat-square) +![Version: 4.0.0](https://img.shields.io/badge/Version-4.0.0-informational?style=flat-square) A common powered chart template. This can be useful for small projects that don't have their own chart. ## Requirements -Kubernetes: `>=1.22.0-0` +Kubernetes: `>=1.28.0-0` ## Dependencies | Repository | Name | Version | |------------|------|---------| -| https://bjw-s-labs.github.io/helm-charts | common | 3.7.3 | +| https://bjw-s-labs.github.io/helm-charts | common | 4.0.0 | ## Installing the Chart +### Helm repository + ```bash # Add the repository -helm repo add bjw-s https://bjw-s-labs.github.io/helm-charts/ +helm repo add bjw-s {{template "custom.helm.url"}} # Install the chart helm install bjw-s app-template -f values.yaml ``` +### OCI + +```bash +# Install the chart +helm install oci://ghcr.io/bjw-s/helm/app-template -f values.yaml +``` + ## Configuration Read through the [values.yaml](../../library/common/values.yaml) file of the [common library](../../library/common/) chart. It has several commented out suggested values. diff --git a/charts/other/app-template/README.md.gotmpl b/charts/other/app-template/README.md.gotmpl index 10654734..cbf35483 100644 --- a/charts/other/app-template/README.md.gotmpl +++ b/charts/other/app-template/README.md.gotmpl @@ -20,6 +20,8 @@ https://bjw-s-labs.github.io/helm-charts/ ## Installing the Chart +### Helm repository + ```bash # Add the repository helm repo add bjw-s {{template "custom.helm.url"}} @@ -28,6 +30,13 @@ helm repo add bjw-s {{template "custom.helm.url"}} helm install bjw-s app-template -f values.yaml ``` +### OCI + +```bash +# Install the chart +helm install oci://ghcr.io/bjw-s/helm/app-template -f values.yaml +``` + ## Configuration Read through the [values.yaml](../../library/common/values.yaml) file of the [common library](../../library/common/) chart. It has several commented out suggested values. diff --git a/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json b/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json index 84f22928..e32dac7e 100644 --- a/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json +++ b/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json @@ -726,7 +726,7 @@ "values": { "description": "Values holds the values for this Helm release.", "x-kubernetes-preserve-unknown-fields": true, - "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.7.3/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" }, "valuesFrom": { "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease,\nand information about how they should be merged.", diff --git a/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json b/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json index 5b859e68..fd53fd47 100644 --- a/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json +++ b/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json @@ -727,7 +727,7 @@ "values": { "description": "Values holds the values for this Helm release.", "x-kubernetes-preserve-unknown-fields": true, - "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.7.3/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" }, "valuesFrom": { "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease, and information about how they should be merged.", diff --git a/charts/other/app-template/values.schema.json b/charts/other/app-template/values.schema.json index a8969d15..00e67961 100644 --- a/charts/other/app-template/values.schema.json +++ b/charts/other/app-template/values.schema.json @@ -1,3 +1,3 @@ { - "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.7.3/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-4.0.0/charts/library/common/values.schema.json" } diff --git a/docs/app-template/index.md b/docs/app-template/index.md index ef8e48c9..07731106 100644 --- a/docs/app-template/index.md +++ b/docs/app-template/index.md @@ -31,342 +31,7 @@ examples/helm/vaultwarden/values.yaml ## Upgrade instructions -### From 2.x.x to 3.0.x - -The main changes from v2.x to v3.x are the removal of the default `main` objects and the introduction of JSON schema validation. - -!!! warning - - **IMPORTANT** The introduction of the json schema adds additional validations and restrictions on the contents of your chart values. - Things may have been missed during the initial schema creation, so if you run in to any unexpected validation errors please [raise an issue](https://github.com/bjw-s-labs/helm-charts/issues/new?assignees=bjw-s&labels=bug&projects=&template=bug-report.md&title=) - -Given the following real-life example values.yaml for app-template v2: - -
-Expand - -```yaml ---- -defaultPodOptions: - securityContext: - runAsUser: 568 - runAsGroup: 568 - fsGroup: 568 - fsGroupChangePolicy: "OnRootMismatch" - supplementalGroups: - - 65539 - -controllers: - main: - containers: - main: - image: - repository: ghcr.io/onedr0p/sabnzbd - tag: latest - pullPolicy: IfNotPresent - -service: - main: - ports: - http: - port: 8080 - -ingress: - media: - enabled: true - className: "ingress-nginx" - hosts: - - host: sabnzbd.bjw-s.dev - paths: - - path: / - service: - name: main - port: http - -persistence: - media: - existingClaim: nas-media - globalMounts: - - path: /data/nas-media -``` - -
- -The values for app-template v3.x would become this: - -```yaml ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.2.0/charts/library/common/values.schema.json -defaultPodOptions: - enableServiceLinks: true - securityContext: - runAsUser: 568 - runAsGroup: 568 - fsGroup: 568 - fsGroupChangePolicy: "OnRootMismatch" - supplementalGroups: - - 65539 - -controllers: - sabnzbd: # this can now be any name you wish - containers: - app: # this can now be any name you wish - image: - repository: ghcr.io/onedr0p/sabnzbd - tag: latest - pullPolicy: IfNotPresent - - probes: - liveness: - enabled: true - readiness: - enabled: true - startup: - enabled: true - spec: - failureThreshold: 30 - periodSeconds: 5 - -service: - app: # this can now be any name you wish - controller: sabnzbd - ports: - http: - port: 8080 - -ingress: - media: # this can now be any name you wish - className: "ingress-nginx" - hosts: - - host: sabnzbd.bjw-s.dev - paths: - - path: / - service: - identifier: app - port: http - -persistence: - media: - existingClaim: nas-media - globalMounts: - - path: /data/nas-media -``` - -#### 🚧 Diff view - -
-Expand - -```diff ---- old -+++ new -@@ -1,42 +1,55 @@ ---- -+# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s-labs/helm-charts/common-3.2.0/charts/library/common/values.schema.json - defaultPodOptions: -+ enableServiceLinks: true - securityContext: - runAsUser: 568 - runAsGroup: 568 - fsGroup: 568 - fsGroupChangePolicy: "OnRootMismatch" - supplementalGroups: - - 65539 - - controllers: -- main: -+ sabnzbd: # this can now be any name you wish - containers: -- main: -+ app: # this can now be any name you wish - image: - repository: ghcr.io/onedr0p/sabnzbd - tag: latest - pullPolicy: IfNotPresent - -+ probes: -+ liveness: -+ enabled: true -+ readiness: -+ enabled: true -+ startup: -+ enabled: true -+ spec: -+ failureThreshold: 30 -+ periodSeconds: 5 -+ - service: -- main: -+ app: # this can now be any name you wish -+ controller: sabnzbd - ports: - http: - port: 8080 - - ingress: -- media: -- enabled: true -+ media: # this can now be any name you wish - className: "ingress-nginx" - hosts: - - host: sabnzbd.bjw-s.dev - paths: - - path: / - service: -- name: main -+ identifier: app - port: http - - persistence: - media: - existingClaim: nas-media - globalMounts: - - path: /data/nas-media - -``` - -
- -#### Changes in this example - -This is not meant as an exhaustive list of changes, but rather a "most common" example. - -- The `main` object for controllers, containers, services and ingress has been removed from `values.yaml` and will therefore no longer provide any (both expected and unexpected) default values. -- The `config` object for persistence has been removed from `values.yaml` and will therefore no longer provide any (both expected and unexpected) default values. -- `enableServiceLinks` has been disabled by default. In order to explicitly enable serviceLinks, set the value to `true`. -- `ingress.*.hosts.*.paths.*.service` Service references now require either `name` or `identifier` to be set. -- Persistence items of type `configMap` and `secret` object references now allow either `name` or `identifier` to be set. - -### From 1.x.x to 2.0.x - -!!! warning - - **IMPORTANT** Because a new label has been introduced in the controller labelSelector (which is an immutable field), Deployments cannot be upgraded in place! - [More details](https://www.datree.io/resources/kubernetes-error-codes-field-is-immutable) - -!!! info - - Some items (Ingress, ports, persistence items, etc) now default to being enabled by default. However, this is not always the case for some of the `items due to overrides in the default `values.yaml`. - [More background](https://github.com/bjw-s-labs/helm-charts/issues/205) - -Given the following real-life example values.yaml for app-template v1: - -
-Expand - -```yaml -image: - repository: ghcr.io/onedr0p/sabnzbd - tag: latest - pullPolicy: IfNotPresent - -podSecurityContext: - runAsUser: 568 - runAsGroup: 568 - fsGroup: 568 - fsGroupChangePolicy: "OnRootMismatch" - supplementalGroups: - - 65539 - -service: - main: - ports: - http: - port: 8080 - -ingress: - media: - enabled: true - ingressClassName: "ingress-nginx" - hosts: - - host: sabnzbd.bjw-s.dev - paths: - - path: / - -persistence: - media: - enabled: true - existingClaim: nas-media - globalMounts: - - path: /data/nas-media - -probes: - liveness: - enabled: false - readiness: - enabled: false - startup: - enabled: false -``` - -
- -The values for app-template v2.x would become this: - -```yaml -defaultPodOptions: - securityContext: - runAsUser: 568 - runAsGroup: 568 - fsGroup: 568 - fsGroupChangePolicy: "OnRootMismatch" - supplementalGroups: - - 65539 - -controllers: - main: - containers: - main: - image: - repository: ghcr.io/onedr0p/sabnzbd - tag: latest - pullPolicy: IfNotPresent - - probes: - liveness: - enabled: false - readiness: - enabled: false - startup: - enabled: false - -service: - main: - ports: - http: - port: 8080 - -ingress: - media: - enabled: true - className: "ingress-nginx" - hosts: - - host: sabnzbd.bjw-s.dev - paths: - - path: / - service: - name: main - port: http - -persistence: - media: - existingClaim: nas-media - globalMounts: - - path: /data/nas-media -``` - -#### Changes in this example - -This is not meant as an exhaustive list of changes, but rather a "most common" example. - -- `podSecurityContext` has been moved to `defaultPodOptions.securityContext`. It is also possible to configure this on a controller-specific basis by moving it to `controllers.main.pod.securityContext` instead. -- `image` has been moved to `controllers.main.containers.main.image` so that multiple containers can be configured. -- `ingress.media.ingressClassName` has been renamed to `ingress.main.className`. -- `ingress.media.enabled` can be removed, since items are considered enabled by default (they can still be disabled by adding `enabled: false`). -- `ingress.media.hosts.*.paths.*.service` is now required since there is no more concept of a default "primary" service. -- `persistence.media.mountPath` has been moved to `persistence.media.globalMounts.*.path` to allow multiple mountPaths for the same persistence item. -- `persistence.media.enabled` can be removed, since items are considered enabled by default (they can still be disabled by adding `enabled: false`). -- `probes` has been moved to `controllers.main.containers.main.probes` so that multiple containers can be configured. +Upgrade instructions for major versions can be found [here](upgrade-instructions.md). ## Source code diff --git a/docs/app-template/upgrade-instructions.md b/docs/app-template/upgrade-instructions.md new file mode 100644 index 00000000..28a06ca7 --- /dev/null +++ b/docs/app-template/upgrade-instructions.md @@ -0,0 +1,375 @@ +# Upgrade instructions + +## From 3.x.x to 4.0.x + +Migrating from v3.x to v4.x introduces a number of breaking changes. Additionally, the minimum required Kubernetes version has been increased to version **1.28.x**. + +#### Resource names + +The second breaking change is the new and consistent resource naming scheme. See [here](../common-library/resources/names.md) for more information on how the new naming scheme works. + +This change may lead to generated resources getting new names, causing resources with the old naming scheme to be removed. + +!!! warning + + **IMPORTANT** As with any major software version upgrade, please verify that you have a working backup of your data. + +#### serviceAccounts + +##### Tokens + +When creating a serviceAccount in v3, this would always also create a Secret containing a static long-lived Service Account token. Nowadays it is preferable to use short-lived tokens and have Kubernetes manage them automatically. + +If a static long-lived token is still required for a serviceAccount, this can be configured by setting the `staticToken` key of the serviceAccount to `true`. + +##### Creation + +The syntax for creating service accounts has changed. Instead of configuring a `default` serviceAccount and optional `extraServiceAccounts` the syntax has been brought in line with other resources: + +```yaml +serviceAccount: + myServiceAccount: {} + mySecondServiceAccount: + staticToken: true + myThirdServiceAccount: + enabled: false + +controllers: + main: + serviceAccount: + identifier: myServiceAccount +``` + +#### Controller labels + +The hardcoded `app.kubernetes.io/component` label that is used to target specific controllers has been renamed to `app.kubernetes.io/controller`. + +## From 2.x.x to 3.0.x + +The main changes from v2.x to v3.x are the removal of the default `main` objects and the introduction of JSON schema validation. + +Given the following real-life example values.yaml for app-template v2: + +
+Expand + +```yaml +--- +defaultPodOptions: + securityContext: + runAsUser: 568 + runAsGroup: 568 + fsGroup: 568 + fsGroupChangePolicy: "OnRootMismatch" + supplementalGroups: + - 65539 + +controllers: + main: + containers: + main: + image: + repository: ghcr.io/onedr0p/sabnzbd + tag: latest + pullPolicy: IfNotPresent + +service: + main: + ports: + http: + port: 8080 + +ingress: + media: + enabled: true + className: "ingress-nginx" + hosts: + - host: sabnzbd.bjw-s.dev + paths: + - path: / + service: + name: main + port: http + +persistence: + media: + existingClaim: nas-media + globalMounts: + - path: /data/nas-media +``` + +
+ +The values for app-template v3.x would become this: + +```yaml +--- +defaultPodOptions: + enableServiceLinks: true + securityContext: + runAsUser: 568 + runAsGroup: 568 + fsGroup: 568 + fsGroupChangePolicy: "OnRootMismatch" + supplementalGroups: + - 65539 + +controllers: + sabnzbd: # this can now be any name you wish + containers: + app: # this can now be any name you wish + image: + repository: ghcr.io/onedr0p/sabnzbd + tag: latest + pullPolicy: IfNotPresent + + probes: + liveness: + enabled: true + readiness: + enabled: true + startup: + enabled: true + spec: + failureThreshold: 30 + periodSeconds: 5 + +service: + app: # this can now be any name you wish + controller: sabnzbd + ports: + http: + port: 8080 + +ingress: + media: # this can now be any name you wish + className: "ingress-nginx" + hosts: + - host: sabnzbd.bjw-s.dev + paths: + - path: / + service: + identifier: app + port: http + +persistence: + media: + existingClaim: nas-media + globalMounts: + - path: /data/nas-media +``` + +#### 🚧 Diff view + +
+Expand + +```diff +--- old ++++ new +@@ -1,42 +1,55 @@ +--- + defaultPodOptions: ++ enableServiceLinks: true + securityContext: + runAsUser: 568 + runAsGroup: 568 + fsGroup: 568 + fsGroupChangePolicy: "OnRootMismatch" + supplementalGroups: + - 65539 + + controllers: +- main: ++ sabnzbd: # this can now be any name you wish + containers: +- main: ++ app: # this can now be any name you wish + image: + repository: ghcr.io/onedr0p/sabnzbd + tag: latest + pullPolicy: IfNotPresent + ++ probes: ++ liveness: ++ enabled: true ++ readiness: ++ enabled: true ++ startup: ++ enabled: true ++ spec: ++ failureThreshold: 30 ++ periodSeconds: 5 ++ + service: +- main: ++ app: # this can now be any name you wish ++ controller: sabnzbd + ports: + http: + port: 8080 + + ingress: +- media: +- enabled: true ++ media: # this can now be any name you wish + className: "ingress-nginx" + hosts: + - host: sabnzbd.bjw-s.dev + paths: + - path: / + service: +- name: main ++ identifier: app + port: http + + persistence: + media: + existingClaim: nas-media + globalMounts: + - path: /data/nas-media + +``` + +
+ +#### Changes in this example + +This is not meant as an exhaustive list of changes, but rather a "most common" example. + +- The `main` object for controllers, containers, services and ingress has been removed from `values.yaml` and will therefore no longer provide any (both expected and unexpected) default values. +- The `config` object for persistence has been removed from `values.yaml` and will therefore no longer provide any (both expected and unexpected) default values. +- `enableServiceLinks` has been disabled by default. In order to explicitly enable serviceLinks, set the value to `true`. +- `ingress.*.hosts.*.paths.*.service` Service references now require either `name` or `identifier` to be set. +- Persistence items of type `configMap` and `secret` object references now allow either `name` or `identifier` to be set. + +## From 1.x.x to 2.0.x + +!!! warning + + **IMPORTANT** Because a new label has been introduced in the controller labelSelector (which is an immutable field), Deployments cannot be upgraded in place! + [More details](https://www.datree.io/resources/kubernetes-error-codes-field-is-immutable) + +!!! info + + Some items (Ingress, ports, persistence items, etc) now default to being enabled by default. However, this is not always the case for some of the `items due to overrides in the default `values.yaml`. + [More background](https://github.com/bjw-s-labs/helm-charts/issues/205) + +Given the following real-life example values.yaml for app-template v1: + +
+Expand + +```yaml +image: + repository: ghcr.io/onedr0p/sabnzbd + tag: latest + pullPolicy: IfNotPresent + +podSecurityContext: + runAsUser: 568 + runAsGroup: 568 + fsGroup: 568 + fsGroupChangePolicy: "OnRootMismatch" + supplementalGroups: + - 65539 + +service: + main: + ports: + http: + port: 8080 + +ingress: + media: + enabled: true + ingressClassName: "ingress-nginx" + hosts: + - host: sabnzbd.bjw-s.dev + paths: + - path: / + +persistence: + media: + enabled: true + existingClaim: nas-media + globalMounts: + - path: /data/nas-media + +probes: + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false +``` + +
+ +The values for app-template v2.x would become this: + +```yaml +defaultPodOptions: + securityContext: + runAsUser: 568 + runAsGroup: 568 + fsGroup: 568 + fsGroupChangePolicy: "OnRootMismatch" + supplementalGroups: + - 65539 + +controllers: + main: + containers: + main: + image: + repository: ghcr.io/onedr0p/sabnzbd + tag: latest + pullPolicy: IfNotPresent + + probes: + liveness: + enabled: false + readiness: + enabled: false + startup: + enabled: false + +service: + main: + ports: + http: + port: 8080 + +ingress: + media: + enabled: true + className: "ingress-nginx" + hosts: + - host: sabnzbd.bjw-s.dev + paths: + - path: / + service: + name: main + port: http + +persistence: + media: + existingClaim: nas-media + globalMounts: + - path: /data/nas-media +``` + +#### Changes in this example + +This is not meant as an exhaustive list of changes, but rather a "most common" example. + +- `podSecurityContext` has been moved to `defaultPodOptions.securityContext`. It is also possible to configure this on a controller-specific basis by moving it to `controllers.main.pod.securityContext` instead. +- `image` has been moved to `controllers.main.containers.main.image` so that multiple containers can be configured. +- `ingress.media.ingressClassName` has been renamed to `ingress.main.className`. +- `ingress.media.enabled` can be removed, since items are considered enabled by default (they can still be disabled by adding `enabled: false`). +- `ingress.media.hosts.*.paths.*.service` is now required since there is no more concept of a default "primary" service. +- `persistence.media.mountPath` has been moved to `persistence.media.globalMounts.*.path` to allow multiple mountPaths for the same persistence item. +- `persistence.media.enabled` can be removed, since items are considered enabled by default (they can still be disabled by adding `enabled: false`). +- `probes` has been moved to `controllers.main.containers.main.probes` so that multiple containers can be configured. diff --git a/docs/common-library/howto/default-pod-options.md b/docs/common-library/howto/default-pod-options.md new file mode 100644 index 00000000..01af6c2f --- /dev/null +++ b/docs/common-library/howto/default-pod-options.md @@ -0,0 +1,84 @@ +--- +hide: + - toc +--- + +# Setting default Pod options + +It is possible to configure default Pod options under the `defaultPodOptions` key. These options will be applied to all Pods specified in the chart values. + +To see which fields can be configured, please take a look at the Chart values schema specific to your Common library version. The latest version can be found here: https://github.com/bjw-s-labs/helm-charts/blob/main/charts/library/common/schemas/pod.json + +## Default value strategies + +### Overwrite + +The default strategy for configuring default Pod options is `overwrite`. This means that if a controller has an entry for a default Pod option it will be overwritten entirely by the Pod-specific configuration. + +This behavior can be set explicitly by setting `defaultPodOptionsStrategy` to `overwrite`. + +An (abbreviated) example of the `overwrite` strategy: + +```yaml +defaultPodOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + +controllers: + main: + pod: + resources: + requests: + cpu: 100m + + containers: + main: + ... +``` + +The expected `resources` field on the `main` Deployment is expected to look like this: + +```yaml +resources: + requests: + cpu: 100m +``` + +### Merge + +An alternative strategy for configuring default Pod options is `merge`. This means that if a Pod has an entry for a default Pod option it will be merged with the Pod-specific configuration. + +This behavior can be set explicitly by setting `defaultPodOptionsStrategy` to `merge`. + +An (abbreviated) example of the `merge` strategy: + +```yaml +defaultPodOptionsStrategy: merge +defaultPodOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + +controllers: + main: + pod: + resources: + requests: + cpu: 100m + + containers: + main: + ... +``` + +The expected `resources` field on the `main` Deployment is expected to look like this: + +```yaml +resources: + requests: + memory: 1Gi + cpu: 100m +``` diff --git a/docs/common-library/resources/names.md b/docs/common-library/resources/names.md new file mode 100644 index 00000000..360c3e01 --- /dev/null +++ b/docs/common-library/resources/names.md @@ -0,0 +1,42 @@ +# Names + +### Configuration + +Each resource that can be created by the Common library supports the following fields to control the generated resource name, along with the resource identifier. + +All of these fields support the use of Helm templates for advanced naming requirements. + +#### forceRename + +Override the default resource name entirely. + +!!! info + The `forceRename` field is mutually exclusive with the `prefix` and `suffix` fields. + +#### prefix + +Prefix to prepend to the resource name. + +#### suffix + +Suffix to append to the resource name. Defaults to the resource identifier if there are multiple enabled items, otherwise it defaults to an empty value. + +### Behavior + +Assuming a Helm Release with the name `base_name`, the following table gives an overview of how the resource name is generated: + +| item key | enabled items | `prefix` | `suffix` | `forceRename` | Generated name | +|----------|---------------|----------|----------|----------------------------|------------------------| +| `id` | 1 | | | `random_name` | `random_name` | +| `id` | 1 | | | `{{ .Release.Namespace }}` | `default` | +| `id` | 1 | | | | `base_name` | +| `id` | 1 | `pfx` | | | `pfx-base_name` | +| `id` | 1 | | `sfx` | | `base_name-sfx` | +| `id` | 2 | | | | `base_name-id` | +| `id` | 1 | `pfx` | `sfx` | | `pfx-base_name-sfx` | +| `id` | 2 | `pfx` | | | `pfx-base_name-id` | +| `id` | 2 | | `sfx` | | `base_name-id-sfx` | +| `id` | 2 | `pfx` | `sfx` | | `pfx-base_name-id-sfx` | +| `id` | 1 | | `sfx` | | `base_name-sfx` | +| `id` | 1 | `pfx` | | | `pfx-base_name` | +| `id` | 1 | `pfx` | `sfx` | | `pfx-base_name-sfx` | diff --git a/docs/common-library/storage/globalOptions.md b/docs/common-library/storage/globalOptions.md index 80482b12..944f4272 100644 --- a/docs/common-library/storage/globalOptions.md +++ b/docs/common-library/storage/globalOptions.md @@ -45,6 +45,10 @@ Specify if the volume should be mounted read-only Specifies a sub-path inside the referenced volume instead of its root. +### subPathExpr + +Use the `subPathExpr` field to construct `subPath` directory names from downward API environment variables. See the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment) for more information. + ## advancedMounts Explicitly configure mounts for specific controllers and containers. @@ -86,3 +90,7 @@ Specify if the volume should be mounted read-only ### subPath Specifies a sub-path inside the referenced volume instead of its root. + +### subPathExpr + +Use the `subPathExpr` field to construct `subPath` directory names from downward API environment variables. See the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath-expanded-environment) for more information.