diff --git a/dysnix/app/component-values.yaml b/dysnix/app/component-values.yaml new file mode 100644 index 00000000..d61ed215 --- /dev/null +++ b/dysnix/app/component-values.yaml @@ -0,0 +1,195 @@ +workload: deployment +reuse: false +containers: {} +initContainers: {} +env: {} +envFrom: [] +volumes: {} +volumeMounts: {} +configMaps: {} +secrets: {} +templateChecksums: [] +kubeVersion: "" +nameOverride: "" +fullnameOverride: "" +namespaceOverride: "" +clusterDomain: cluster.local +extraDeploy: [] +diagnosticMode: + enabled: false + command: + - sleep + args: + - infinity +image: + registry: "" + repository: "" + tag: "" + digest: "" + pullPolicy: IfNotPresent + pullSecrets: [] + debug: false +replicaCount: 1 +containerPorts: {} +livenessProbe: + enabled: false + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + successThreshold: 1 +readinessProbe: + enabled: false + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + successThreshold: 1 +startupProbe: + enabled: false + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + successThreshold: 1 +customLivenessProbe: {} +customReadinessProbe: {} +customStartupProbe: {} +resources: + limits: {} + requests: {} +podSecurityContext: + enabled: true + fsGroup: 1001 +containerSecurityContext: + enabled: true + runAsUser: 1001 + runAsNonRoot: true + readOnlyRootFilesystem: false +command: [] +args: [] +hostAliases: [] +podLabels: {} +podAnnotations: {} +podAffinityPreset: "" +podAntiAffinityPreset: soft +pdb: + create: false + minAvailable: 1 + maxUnavailable: "" +autoscaling: + enabled: false + minReplicas: "" + maxReplicas: "" + targetCPU: "" + targetMemory: "" + behavior: {} +nodeAffinityPreset: + type: "" + key: "" + values: [] +affinity: {} +nodeSelector: {} +tolerations: [] +updateStrategy: + type: RollingUpdate +dnsPolicy: +hostNetwork: +automountServiceAccountToken: +podManagementPolicy: OrderedReady +priorityClassName: "" +topologySpreadConstraints: [] +schedulerName: "" +terminationGracePeriodSeconds: "" +lifecycleHooks: {} +extraEnvVars: [] +extraEnvVarsCM: "" +extraEnvVarsSecret: "" +extraVolumes: [] +extraVolumeMounts: [] +sidecars: [] +extraInitContainers: [] +service: + type: ClusterIP + ports: {} + clusterIP: "" + loadBalancerIP: "" + loadBalancerSourceRanges: [] + externalTrafficPolicy: Cluster + annotations: {} + extraPorts: [] + sessionAffinity: None + sessionAffinityConfig: {} +ingress: + enabled: false + namespace: "" + customName: "" + serviceName: "" + servicePort: + pathType: ImplementationSpecific + apiVersion: "" + hostname: app.local + ingressClassName: "" + path: / + annotations: {} + tls: false + selfSigned: false + selfSignedDays: 365 + extraHosts: [] + extraPaths: [] + extraTls: [] + secrets: [] + extraRules: [] +persistence: + enabled: false + emptyDir: false + mountName: data + mountPath: /data + subPath: "" + storageClass: "" + annotations: {} + accessModes: + - ReadWriteOnce + size: 8Gi + existingClaim: "" + selector: {} + dataSource: {} +volumePermissions: + command: [] + image: + registry: docker.io + repository: bitnami/bitnami-shell + tag: 11-debian-11 + pullPolicy: Always + pullSecrets: [] + resources: + limits: {} + requests: {} + containerSecurityContext: + runAsUser: 0 +minReadySeconds: 0 +rbac: + create: false + rules: [] +serviceAccount: + create: true + name: "" + annotations: {} + automountServiceAccountToken: true +metrics: + enabled: false + serviceMonitor: + enabled: false + path: "" + port: + targetPort: + namespace: "" + annotations: {} + labels: {} + jobLabel: "" + honorLabels: false + interval: "" + scrapeTimeout: "" + metricRelabelings: [] + relabelings: [] + selector: {} diff --git a/dysnix/app/templates/_resources.tpl b/dysnix/app/templates/_resources.tpl index b2ab5df7..2faaa5c6 100644 --- a/dysnix/app/templates/_resources.tpl +++ b/dysnix/app/templates/_resources.tpl @@ -1,15 +1,15 @@ {{/* vim: set filetype=helm: */}} {{/* -Includes the given resource. +Includes the given resource from the app chart templates. Note that if component is not provided we assume it's default. Usage {{- include "app.resource.include" (dict "_include" (dict "resource" "deployment" "top" $) }} {{- include "app.resource.include" (dict "_include" (dict "resource" "deployment" "component" "foo" "values" .Path.Values "top" $)) }} - It also supports custom parameters, especially during nested invocation such + It also supports custom parameters, especially used during nested invocations such as in configmaps or secrets. Pay attention to mergeOverwrite since we need to - overwrite existing fieleds such _include.resource + overwrite existing the _include fields (including resource). {{- include "app.resources.include" (dict "_include" (dict "resource" "configmap" "name" $name "data" $data) | mergeOverwrite $) }} */}} @@ -35,9 +35,13 @@ Usage {{- printf "Component %s has no values at path %s" ._include.component $pathstr | fail -}} {{- end -}} + {{- /* Component's values can be provided explicitly via ._include.values */ -}} + {{- $baseDefaults := ._include.top.Files.Get "component-values.yaml" | fromYaml -}} + {{- $componentValues = ._include.values | default $componentValues | mergeOverwrite $baseDefaults -}} + {{/* Specific global values are always injected into the render context */}} {{- $global := pick ._include.top.Values "commonLabels" "commonAnnotations" "global" -}} - {{- $values := $global | mergeOverwrite (._include.values | default $componentValues) -}} + {{- $values := $global | mergeOverwrite $componentValues -}} {{- $context := omit ._include.top "Values" | merge (dict "Values" $values "_include" ._include) -}} {{- include (printf "app.resources.%s" ._include.resource) $context -}} @@ -82,8 +86,7 @@ Usage: {{/* Give precedence to .Values.app.components path settings */}} {{- $componentPaths = default dict $top.Values.app.components | mergeOverwrite $componentPaths -}} - - {{/* Render all components which are not explicitly disabled (nulled) */}} + {{/* Render all components which are not explicitly disabled */}} {{- range $component := keys $componentPaths | sortAlpha -}} {{- $path := get $componentPaths $component | toString -}} {{- if ne $path "false" -}} diff --git a/dysnix/app/tests/components-multi_test.yaml b/dysnix/app/tests/components-multi_test.yaml new file mode 100644 index 00000000..569348b5 --- /dev/null +++ b/dysnix/app/tests/components-multi_test.yaml @@ -0,0 +1,84 @@ +suite: components +templates: + - service-account.yaml + - deployment.yaml +tests: + - + it: two Deployment resources for both components + values: + - ./values/components.yaml + template: deployment.yaml + set: + app.components: + "": true + component: mycomponent + asserts: + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + - equal: + path: metadata.name + value: RELEASE-NAME-multi + documentIndex: 0 + - equal: + path: metadata.name + value: RELEASE-NAME-multi-component + documentIndex: 1 + - equal: + path: spec.template.spec.containers[0].image + value: image + documentIndex: 1 + - + it: one ServiceAccount, component's one is disabled + values: + - ./values/components.yaml + template: service-account.yaml + set: + app.components: + "": true + component: mycomponent + asserts: + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + - equal: + path: metadata.name + value: RELEASE-NAME-multi + documentIndex: 0 + - hasDocuments: + count: 1 + - + it: component lablels and selectors + values: + - ./values/components.yaml + template: deployment.yaml + asserts: + - isSubset: + path: metadata.labels + content: + app.kubernetes.io/component: component + - isSubset: + path: spec.selector.matchLabels + content: + app.kubernetes.io/component: component + - + it: globals/commons are respected + values: + - ./values/components.yaml + set: + global.imageRegistry: global + commonLabels: + component-has: label + template: deployment.yaml + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: global/image + - isSubset: + path: metadata.labels + content: + component-has: label + - isSubset: + path: spec.template.metadata.labels + content: + component-has: label diff --git a/dysnix/app/tests/values/components.yaml b/dysnix/app/tests/values/components.yaml new file mode 100644 index 00000000..8130cd45 --- /dev/null +++ b/dysnix/app/tests/values/components.yaml @@ -0,0 +1,11 @@ +app: + name: multi + components: + "": false + component: mycomponent + +mycomponent: + serviceAccount: + create: false + image: + repository: image