Skip to content

Commit

Permalink
Merge pull request #390 from mbaldessari/common-automatic-update
Browse files Browse the repository at this point in the history
common automatic update
  • Loading branch information
mbaldessari authored Jun 29, 2024
2 parents d97644d + 7a4b050 commit 0a6d59e
Show file tree
Hide file tree
Showing 24 changed files with 574 additions and 150 deletions.
2 changes: 1 addition & 1 deletion common/acm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ description: A Helm chart to configure Advanced Cluster Manager for OpenShift.
keywords:
- pattern
name: acm
version: 0.0.1
version: 0.0.2
44 changes: 44 additions & 0 deletions common/acm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,47 @@ Default always defined valueFiles to be included when pushing the cluster wide a
# hub's cluster version, whereas we want to include the spoke cluster version
- '/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}.yaml'
{{- end }} {{- /*acm.app.policies.valuefiles */}}

{{- define "acm.app.policies.multisourcevaluefiles" -}}
- "$patternref/values-global.yaml"
- "$patternref/values-{{ .name }}.yaml"
- '$patternref/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}.yaml'
- '$patternref/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}.yaml'
- '$patternref/values-{{ `{{ (lookup "config.openshift.io/v1" "Infrastructure" "" "cluster").spec.platformSpec.type }}` }}-{{ .name }}.yaml'
# We cannot use $.Values.global.clusterVersion because that gets resolved to the
# hub's cluster version, whereas we want to include the spoke cluster version
- '$patternref/values-{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}.yaml'
{{- end }} {{- /*acm.app.policies.multisourcevaluefiles */}}

{{- define "acm.app.policies.helmparameters" -}}
- name: global.repoURL
value: {{ $.Values.global.repoURL }}
- name: global.targetRevision
value: {{ $.Values.global.targetRevision }}
- name: global.namespace
value: $ARGOCD_APP_NAMESPACE
- name: global.pattern
value: {{ $.Values.global.pattern }}
- name: global.hubClusterDomain
value: {{ $.Values.global.hubClusterDomain }}
- name: global.localClusterDomain
value: '{{ `{{ (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain }}` }}'
- name: global.clusterDomain
value: '{{ `{{ (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain | replace "apps." "" }}` }}'
- name: global.clusterVersion
value: '{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}'
- name: global.localClusterName
value: '{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}'
- name: global.clusterPlatform
value: {{ $.Values.global.clusterPlatform }}
- name: global.multiSourceSupport
value: {{ $.Values.global.multiSourceSupport | quote }}
- name: global.multiSourceRepoUrl
value: {{ $.Values.global.multiSourceRepoUrl }}
- name: global.multiSourceTargetRevision
value: {{ $.Values.global.multiSourceTargetRevision }}
- name: global.privateRepo
value: {{ $.Values.global.privateRepo | quote }}
- name: global.experimentalCapabilities
value: {{ $.Values.global.experimentalCapabilities }}
{{- end }} {{- /*acm.app.policies.helmparameters */}}
64 changes: 42 additions & 22 deletions common/acm/templates/policies/application-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,46 @@ spec:
- resources-finalizer.argocd.argoproj.io/foreground
spec:
project: default
{{- if $.Values.global.multiSourceSupport }}
sources:
- repoURL: {{ coalesce .repoURL $.Values.global.repoURL }}
targetRevision: {{ coalesce .targetRevision $.Values.global.targetRevision }}
ref: patternref
- repoURL: {{ $.Values.global.multiSourceRepoUrl }}
targetRevision: {{ $.Values.global.multiSourceTargetRevision }}
helm:
ignoreMissingValueFiles: true
values: |
extraParametersNested:
{{- range $k, $v := $.Values.extraParametersNested }}
{{ $k }}: {{ printf "%s" $v | quote }}
{{- end }}
valueFiles:
{{- include "acm.app.policies.multisourcevaluefiles" . | nindent 26 }}
{{- range $valueFile := .extraValueFiles }}
- {{ $valueFile | quote }}
{{- end }}
parameters:
{{- include "acm.app.policies.helmparameters" $ | nindent 26 }}
- name: clusterGroup.name
value: {{ $group.name }}
{{- range $k, $v := $.Values.extraParametersNested }}
- name: {{ $k }}
value: {{ printf "%s" $v | quote }}
{{- end }}
{{- range .helmOverrides }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
{{- if .fileParameters }}
fileParameters:
{{- range .fileParameters }}
- name: {{ .name }}
path: {{ .path }}
{{- end }}
{{- end }}

{{- else }}
source:
repoURL: {{ coalesce .repoURL $.Values.global.repoURL }}
targetRevision: {{ coalesce .targetRevision $.Values.global.targetRevision }}
Expand All @@ -53,30 +93,9 @@ spec:
- {{ $valueFile | quote }}
{{- end }}
parameters:
- name: global.repoURL
value: {{ $.Values.global.repoURL }}
- name: global.targetRevision
value: {{ $.Values.global.targetRevision }}
- name: global.namespace
value: $ARGOCD_APP_NAMESPACE
- name: global.pattern
value: {{ $.Values.global.pattern }}
- name: global.hubClusterDomain
value: {{ $.Values.global.hubClusterDomain }}
- name: global.localClusterDomain
value: '{{ `{{ (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain }}` }}'
- name: global.clusterDomain
value: '{{ `{{ (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain | replace "apps." "" }}` }}'
- name: global.clusterVersion
value: '{{ `{{ printf "%d.%d" ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Major) ((semver (index (lookup "config.openshift.io/v1" "ClusterVersion" "" "version").status.history 0).version).Minor) }}` }}'
- name: global.localClusterName
value: '{{ `{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}` }}'
- name: global.clusterPlatform
value: {{ $.Values.global.clusterPlatform }}
{{- include "acm.app.policies.helmparameters" $ | nindent 22 }}
- name: clusterGroup.name
value: {{ $group.name }}
- name: global.experimentalCapabilities
value: {{ $.Values.global.experimentalCapabilities }}
{{- range $k, $v := $.Values.extraParametersNested }}
- name: {{ $k }}
value: {{ printf "%s" $v | quote }}
Expand All @@ -92,6 +111,7 @@ spec:
path: {{ .path }}
{{- end }}
{{- end }}
{{- end }}{{/* if $.Values.global.multiSourceSupport */}}
destination:
server: https://kubernetes.default.svc
namespace: {{ $.Values.global.pattern }}-{{ .name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def inject_field(
for prefix in prefixes:
cmd = (
f"oc exec -n {self.namespace} {self.pod} -i -- sh -c "
f"\"vault kv {verb} -mount={mount} {prefix}/{secret_name} {fieldname}='{fieldvalue}'\""
f"\"vault kv {verb} -mount={mount} {prefix}/{secret_name} {fieldname}='\"'{fieldvalue}'\"'\""
)
self._run_command(cmd, attempts=3)
return
Expand Down
12 changes: 6 additions & 6 deletions common/ansible/tests/unit/test_vault_load_parsed_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_ensure_value_injection_works(self):
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret hub/config-demo secret='value123'\"",
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret hub/config-demo secret='\"'value123'\"'\"", # noqa: E501
attempts=3,
),
]
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_ensure_b64_value_injection_works(self):
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret hub/config-demo secret='dmFsdWUxMjMK'\"", # noqa: E501
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret hub/config-demo secret='\"'dmFsdWUxMjMK'\"'\"", # noqa: E501
attempts=3,
),
]
Expand Down Expand Up @@ -198,11 +198,11 @@ def test_ensure_file_injection_works(self):
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/region-one/config-demo secret='value123'\"", # noqa: E501
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/region-one/config-demo secret='\"'value123'\"'\"", # noqa: E501
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/snowflake.blueprints.rhecoeng.com/config-demo secret='value123'\"", # noqa: E501
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/snowflake.blueprints.rhecoeng.com/config-demo secret='\"'value123'\"'\"", # noqa: E501
attempts=3,
),
call(
Expand Down Expand Up @@ -249,11 +249,11 @@ def test_ensure_file_b64_injection_works(self):
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/region-one/config-demo secret='value123'\"", # noqa: E501
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/region-one/config-demo secret='\"'value123'\"'\"", # noqa: E501
attempts=3,
),
call(
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/snowflake.blueprints.rhecoeng.com/config-demo secret='value123'\"", # noqa: E501
"oc exec -n vault vault-0 -i -- sh -c \"vault kv put -mount=secret secret/snowflake.blueprints.rhecoeng.com/config-demo secret='\"'value123'\"'\"", # noqa: E501
attempts=3,
),
call(
Expand Down
10 changes: 8 additions & 2 deletions common/clustergroup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Default always defined top-level variables for helm charts
*/}}
{{- define "clustergroup.app.globalvalues.helmparameters" -}}
- name: global.repoURL
value: $ARGOCD_APP_SOURCE_REPO_URL
value: {{ $.Values.global.repoURL }}
- name: global.targetRevision
value: $ARGOCD_APP_SOURCE_TARGET_REVISION
value: {{ $.Values.global.targetRevision }}
- name: global.namespace
value: $ARGOCD_APP_NAMESPACE
- name: global.pattern
Expand All @@ -18,6 +18,12 @@ Default always defined top-level variables for helm charts
value: "{{ $.Values.global.clusterPlatform }}"
- name: global.hubClusterDomain
value: {{ $.Values.global.hubClusterDomain }}
- name: global.multiSourceSupport
value: {{ $.Values.global.multiSourceSupport | quote }}
- name: global.multiSourceRepoUrl
value: {{ $.Values.global.multiSourceRepoUrl }}
- name: global.multiSourceTargetRevision
value: {{ $.Values.global.multiSourceTargetRevision }}
- name: global.localClusterDomain
value: {{ coalesce $.Values.global.localClusterDomain $.Values.global.hubClusterDomain }}
- name: global.privateRepo
Expand Down
2 changes: 1 addition & 1 deletion common/golang-external-secrets/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A Helm chart to configure the golang-based external-secrets.
keywords:
- pattern
name: golang-external-secrets
version: 0.0.3
version: 0.0.4
dependencies:
- name: external-secrets
version: "0.9.19"
Expand Down
2 changes: 1 addition & 1 deletion common/hashicorp-vault/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A Helm chart to configure Hashicorp's vault.
keywords:
- pattern
name: hashicorp-vault
version: 0.0.1
version: 0.0.2
dependencies:
- name: vault
version: "0.28.0"
Expand Down
12 changes: 10 additions & 2 deletions common/tests/acm-industrial-edge-hub.expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,18 @@ spec:
value: '{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}'
- name: global.clusterPlatform
value: aws
- name: clusterGroup.name
value: factory
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.privateRepo
value:
- name: global.experimentalCapabilities
value:
- name: clusterGroup.name
value: factory
- name: clusterGroup.isHubCluster
value: "false"
destination:
Expand Down
12 changes: 10 additions & 2 deletions common/tests/acm-medical-diagnosis-hub.expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,18 @@ spec:
value: '{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}'
- name: global.clusterPlatform
value: aws
- name: clusterGroup.name
value: region-one
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.privateRepo
value:
- name: global.experimentalCapabilities
value:
- name: clusterGroup.name
value: region-one
- name: clusterGroup.isHubCluster
value: "false"
destination:
Expand Down
36 changes: 30 additions & 6 deletions common/tests/acm-normal.expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1389,10 +1389,18 @@ spec:
value: '{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}'
- name: global.clusterPlatform
value: aws
- name: clusterGroup.name
value: acm-edge
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.privateRepo
value:
- name: global.experimentalCapabilities
value:
- name: clusterGroup.name
value: acm-edge
- name: clusterGroup.isHubCluster
value: "false"
destination:
Expand Down Expand Up @@ -1487,10 +1495,18 @@ spec:
value: '{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}'
- name: global.clusterPlatform
value: aws
- name: clusterGroup.name
value: acm-provision-edge
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.privateRepo
value:
- name: global.experimentalCapabilities
value:
- name: clusterGroup.name
value: acm-provision-edge
- name: clusterGroup.isHubCluster
value: "false"
destination:
Expand Down Expand Up @@ -1585,10 +1601,18 @@ spec:
value: '{{ (split "." (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain)._1 }}'
- name: global.clusterPlatform
value: aws
- name: clusterGroup.name
value: acm-provision-on-deploy
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.privateRepo
value:
- name: global.experimentalCapabilities
value:
- name: clusterGroup.name
value: acm-provision-on-deploy
destination:
server: https://kubernetes.default.svc
namespace: mypattern-acm-provision-on-deploy
Expand Down
10 changes: 8 additions & 2 deletions common/tests/clustergroup-industrial-edge-factory.expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,9 @@ spec:
- "/values-4.12-factory.yaml"
parameters:
- name: global.repoURL
value: $ARGOCD_APP_SOURCE_REPO_URL
value: https://github.com/pattern-clone/mypattern
- name: global.targetRevision
value: $ARGOCD_APP_SOURCE_TARGET_REVISION
value: main
- name: global.namespace
value: $ARGOCD_APP_NAMESPACE
- name: global.pattern
Expand All @@ -665,6 +665,12 @@ spec:
value: "aws"
- name: global.hubClusterDomain
value: apps.hub.example.com
- name: global.multiSourceSupport
value:
- name: global.multiSourceRepoUrl
value:
- name: global.multiSourceTargetRevision
value:
- name: global.localClusterDomain
value: apps.region.example.com
- name: global.privateRepo
Expand Down
Loading

0 comments on commit 0a6d59e

Please sign in to comment.