Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
example template update (#1)
Browse files Browse the repository at this point in the history
* Provide more subscription defaults

* Review and simplify argo sync options

* Ignore objects derived from our ACM policies

* See if we can set SkipDryRunOnMissingResource att the application level

* Revert "See if we can set SkipDryRunOnMissingResource att the application level"

It was not possible

This reverts commit 2ca42ed.

* Add more subscription defaults

* Support to kustomize targets

* Support applications using plugins

* Cannot assume the subscription name and csv prefix match

* Allow custom ignoreDifferences values

* Helper for deploying the repo accurately

* Include the site name in the initial app

* Simple site to test argo plugins

* Pass site value files when using the helm-with-kustomize plugin

* Use the app name when rendering the helm template

* Add missing file

* kustomize debugging

* The helm-with-kustomize example is useful to keep around

* Additional help targets

* Support loading just the site application on install

* Make it easy to drive the bootstrap option from the helper

* Make it easy to kustomize the secrets location from the helper

* Limit helm's template name to under 53 chars

* Create the application name ordered by significance

* Site name is included in the site's .Release.Name

* Try to stay under helm's name template max of 53 chars

* Fix the application role binding to refer to the actual policy

* Use the managed site name for the application and values file

* Enforce quoting of helmOverrides for acm policy applications

* Provide a default path to the site chart

* Drop references to manuela in common

* Allow namespaces without operatorgroups for charts that already include them

* Add argocd secret handling

* Add argosecret target

* Remove unneeded util dir

* Explain how to use common makefile

* Allow namespaces without operatorgroups for charts that already include them

* Add template toplevel makefile

* Allow templates to know which namespace they're being deployed into

* Refresh the kustomize-renderer example

* Refresh the sample datacenter from manuela

* Don't assume the install symlink is present

* Attempt new template format

* Ensure password has length before exiting wait loop

* Replace makefile template and make embedded shell wait for password to have length as well as 0 exit

* Add then

* Make script explain what it's doing

* make output clearer

* Revert "Attempt new template format"

This reverts commit c463cbc.

* Try putting applications into a dedicated argo instance

* All namespaces are created by the site chart

* Fix default applicaiton namespace handling

* Make the pattern name availble to argo applications

* Give preference to whatever was specified in the secrets file

* Strip off any auth tokens when calculating the target repo

* Ensure there are no spaces in the namespace

* Fix namespace for applications

* Fix namespace for application acm policies

* Include the pattern name to ensure uniqueness

* Update repo name

* Try putting applications into a dedicated argo instance

* All namespaces are created by the site chart

* Fix default applicaiton namespace handling

* Make the pattern name availble to argo applications

* Give preference to whatever was specified in the secrets file

* Strip off any auth tokens when calculating the target repo

* Ensure there are no spaces in the namespace

* Fix namespace for applications

* Fix namespace for application acm policies

* Include the pattern name to ensure uniqueness

* Fix the destination namespace for datacenter manifests

* Try a simpler argo name

* Use a shorter namespace

* acm: Fix the target namespace for the site application policy

* Fix application namespace

* The application name is already unique to the namespace

* Restore gitops to the name of the argocd CR

* Match the service accounts to the argocd name

* Document what argocd values need to be kept in sync

* Updated note regarding argo name

* Change the default 'name' label for namespaces

* Update common Makefile to have more parameters for secret making

* Re-factor install to not require .ONESHELL features as Mac doesn't support them out of the box

* Update Makefile doc and SECRET_NAME parameter

* Don't hardcode SECRET_NAME here

* Move script to scripts dir and call it from there

* New s3 secrets file for central-s3 support

* Took care of merge conflicts with s3-secret.yaml

* Adding functionalist to have a list of namespaces for a particular subscription

* Enhance compatibility with older versions of git

* Trim the example datacenter site

* Support real helm charts too

* Adds the if control to force booleans to be string type for argo on helm/vault overrides

* Improved secrets handling in pipelines (#10)

* Update common with new secret management

* Add values-global to Makefile

Co-authored-by: Wolfgang Kulhanek <WolfgangKulhanek@gmail.com>

* Add note regarding tekton annotation

* Add note regarding tekon annotation

* Ensure updated secret template variables are defined

* Missing template variable

* Update values.yaml

* Avoid assumptions about the site being called datacenter leaking into patterns

* Add missing template variables

* Standardize on Values.secrets for usernames as well as passwords

* Sync the example global values file with the i-e pattern

* Sync the plugin example application with the i-e pattern

* Ensure helm options stay in sync and add a simple test

* Make the test more stable and add missing values

* Extend the unit tests to the acm and site charts

* Ensure the global.repoURL variable is set consistently in tests

* Add some elements to .gitignore

* Fix whitespace in repoURL value in a POSIX-friendly way

* Remove manuela-specific elements and secrets

* Modify tests to match removal of secrets and namespace

* Remove cruft from makefile

* Loosen regex to extract target repo

* Add structure for vault

* Remove vault subdir to prep for alternate inclusion

* Squashed 'vault/' content from commit 9fa25e9

git-subtree-dir: vault
git-subtree-split: 9fa25e97c806073c7dd3274a851181cbb3d67868

* Change site to clustername to allow for multiple clusters in a config group

* Remove staging and adjust tests to reflect that

* Update examples for recent cleanups

* Support ocp authentication for namespaced argos

* Update examples for recent cleanups

* Support ocp authentication for namespaced argos

* Make sure that argo can manage cluster-wide resources from the relevant namespaces

Otherwise we can error out with:

  Cluster level ClusterRoleBinding vault-server-binding cannot be managed
  when in namespaced mode

By setting ARGOCD_CLUSTER_CONFIG_NAMESPACES to the namespaces where
argocd instance is installed we allow it to create cluster wide
resources for all namespaces.

Tested this and now I am correctly able to invoke the vault helm chart
from argo without the above error.

References:
- argoproj/argo-cd#5886
- argoproj-labs/argocd-operator#385

* Add some vault utilities and add a gitignore entry

* Add Makefile target to init and unseal vault

* Add an unseal target and provide it a default in the script

* Initial import of chart from 9348383 of https://github.com/external-secrets/external-secrets

* Remove vault and external secrets - we can install from helm directly

* Protect ourselves from calling vault-init twice

Without this we risk to easily overwrite the seal + token file and hence
lose future access to the vault.

* Add script for copying vault-token

* Add Hub cluster domain as a global variable based on ingress config

* Add code to extract root token

* Add function to wrap an exec including the token

* Add pki init to vault init makefile target

* Expand the PKI domain (knock off the first two domains for the hub cluster, e.g. apps and the next one up to allow the PKI to be bigger

* Correct pki role and domain creation

* Add more functions for secrets management

* pki init is done in vault_init, no need to have a separate makefile task

* Fix the name of the function to initialize the kubernetes backend

Otherwise we'll error out with:
common/scripts/vault-utils.sh: line 85: vault_k8s_init: command not found

* Add --interactive to the oc vault exec calls

This allows us to read stdin and push a file via stdin.
This is particularly useful when configuring the vault policy

* Add a policy init function to setup initial policy for the vault

* Add variable qualification to prevent helm template errors

* Add vault-route to workaround hard-coding of passthrough mode in vault helm chart 0.18.0

* Correct route resource, remove namespace and spell variable correctly

* Fix TTL lease typo in vault-init

Current wrong command:
bash-4.4$ vault secrets tune -max-lease=8760h pki
flag provided but not defined: -max-lease

Add -ttl at the end to fix it:
bash-4.4$ vault secrets tune --max-lease-ttl=8760h pki
Success! Tuned the secrets engine at: pki/

* Remove extra duplicate subcription YAML and force quoting in application install for consistency

* Add local domain to ACM policy

* Propogate localdomain setting to non-privileged argo

* Fix some tests

* Fix remaining tests

* Remove manuela tag from clustergroup chart

* Add extra framework options to level with clustergroup implementation

* Remove vault-route application

Now that vault-helm v0.19.0 has been released we can use it directly to
create the vault route with tls.termination set to 'edge', hence this is
not needed anymore.

* Remove vault-route application

Now that vault-helm v0.19.0 has been released we can use it directly to
create the vault route with tls.termination set to 'edge', hence this is
not needed anymore.

* Supply hubClusterDomain for localHubCluster where we don't have ACM to populate the lookup

* Don't conditionalize lookups when we know we need them

* Remove bashism in vault_exec

We currently uase "bash -c" inside vault_exec. This only works when
using UBI-based images. Let's move to 'sh -c' to be a bit more robust
in case we're in the presence of the upstream vault images which do not
have bash installed.

Tested a 'vault-init' on UBI images and it correctly worked with no
errors whatsoever in the log.

* Add namespace support to the regional gitops installations

This allows argo on regional clusters to have more rights.
Specifically this is needed to create the clusterbindingrole needed
for the k8s-external-secret operator.

As a first pass we'll use the '*' namespace. In a second iteration
we'll need to look at restricting that to openshift-gitops and the
namespace of the regional gitops instance. At this point of time
such a change is too invasive and is at risk of breaking existing
patterns.

Tested this on multicloud gitops and I correctly get argo to create
the clusterrolebinding in the k8s-external-secret:

  $ oc get clusterrolebinding | grep k8s-extern
  k8s-external-secrets-kubernetes-external-secrets          ClusterRole/k8s-external-secrets-kubernetes-external-secrets
  k8s-external-secrets-kubernetes-external-secrets-auth     ClusterRole/system:auth-delegator

Previously this would fail with:
  Cluster level CustomResourceDefinition "externalsecrets.kubernetes-client.io" can not be managed when in namespaced mode

* Add code to validate origin for install/upgrade

* Add better domain alternation logic and Makefile validation

* Stop using echo when returning a string in a function

This is not portable [1] and in some shells and also on bash depending
on the version [2] it may or may not automatically interpret switches (like -n).
Let's switch to printf which is the POSIX-blessed way of doing things
[3].

Tested this on my environment and was able to still do a vault-init
without any errors.

[1] https://wiki.bash-hackers.org/scripting/nonportable#echo_command
[2] https://stackoverflow.com/questions/11193466/echo-n-prints-n
[3] https://wiki.bash-hackers.org/commands/builtin/printf

* Add support for pushing the kube-root-ca.crt from the HUB to the managed clusters

By default this ACM templates is inactive and will only be activated if
asked explicitely via the .pushHubCA parameter.
It will pull the ca.crt field from the the kube-root-ca.crt ConfigMap on
the hub into a secret on the managed cluster. This will then be used
by the external-secrets pod so it can trust the https://vault-vault.apps.hub-domain...
API endpoint of the vault.

Tested with this change and once enabled via .pushHubCA the
kubernetes-external-secrets pod could correctly connect to the vault
running on the HUB (without this we'd get self-signed certs errors)

* Fix the TARGET_REPO calculation

* Fix common/ make test

Currently we fail in a bunch of tests. Let's fix these up so we'll be
able to introduce some unit testing CI soon.

Tested with:
  $ make test |grep FAIL
  Testing install chart (naked)
  Testing clustergroup chart (naked)
  Testing acm chart (naked)
  Testing install chart (normal)
  Testing clustergroup chart (normal)
  Testing acm chart (normal)

* Remove clusterselector for cases where we want the vault-ca installed on the hub cluster as well

* Fix common/ make test

Currently we fail in a bunch of tests. Let's fix these up so we'll be
able to introduce some unit testing CI soon.

Tested with:
  $ make test |grep FAIL
  Testing install chart (naked)
  Testing clustergroup chart (naked)
  Testing acm chart (naked)
  Testing install chart (normal)
  Testing clustergroup chart (normal)
  Testing acm chart (normal)

* Replicate validatedpatterns/multicloud-gitops#36

* Remove policy to deploy vault CA as unnecessary

* Changes to vault-utils to support vault/external-secrets combo

* Rename the namespace and serviceaccounts to the name of the new golang-based external secrets operator

We're moving to the newer golang-based external secrets operator at https://external-secrets.io/
To be more explicit about our intention we name namespaces and
serviceaccounts golang-external-secrets. Let's rename it in the hub
config as well.

Tested with the other related golang changes and everything worked as
expected.

* Add golang-external-secrets chart

* Add script to push vault secrets

* Fix test error in clustergroup example

This fixed the following:
Testing clustergroup chart (naked)
--- tests/clustergroup-naked.expected.yaml      2022-02-27 18:06:11.474410537 +0100
+++ tests/.clustergroup-naked.expected.yaml     2022-02-27 19:29:17.534554450 +0100
@@ -61,6 +61,7 @@
   # Changing the name affects the ClusterRoleBinding, the generated secret,
   # route URL, and argocd.argoproj.io/managed-by annotations
   name: example-gitops
+  namespace: common-example
   annotations:
     argocd.argoproj.io/compare-options: IgnoreExtraneous
 spec:
FAIL on clustergroup naked with opts []
make: *** [Makefile:34: test] Error 1

* Fix acm naked example test

Currently errors out with:
Testing acm chart (naked)
--- tests/acm-naked.expected.yaml       2022-02-27 18:06:11.474410537 +0100
+++ tests/.acm-naked.expected.yaml      2022-02-27 19:38:40.898341311 +0100
@@ -2,13 +2,6 @@
 # Source: acm/templates/policies/application-policies.yaml
 # TODO: Also create a GitOpsCluster.apps.open-cluster-management.io
 ---
-# Source: acm/templates/policies/hub-certificate-authority.yaml
-# We only push the hub CA to the regional clusters when the user explicitely tells us so
-# This template fetches "ca.crt" from the "kube-root-ca.crt" configMap from the hub
-# (this configmap is present in all namespaces) and puts it in the vault-ca secret inside
-# the k8s-external-secrets namespace so the external-secrets pod knows how to trust
-# the https://vault-vault.apps.hub-domain... endpoint
----
 # Source: acm/templates/multiclusterhub.yaml
 apiVersion: operator.open-cluster-management.io/v1
 kind: MultiClusterHub
FAIL on acm naked with opts []
make: *** [Makefile:34: test] Error 1

This was just a leftover for when we removed the hub-ca app that pushed
it around to managed clusters.

* Fix tests/clustergroup-normal.expected.yaml test

* Add initial checking github action on every pull/push

At the moment this only runs "make test".
We'll later expand this to do some additional linting.

* Add a helmlint target that runs helm lint over the charts

❯ make helmlint
==> Linting install
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
==> Linting clustergroup
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
==> Linting acm
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

* Run make helmlint on every push/pull request

* Add golang-external-secrets to the charts being tested

* Add right params to helmlint

❯ make helmlint
==> Linting install
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
==> Linting clustergroup
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
==> Linting acm
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
==> Linting golang-external-secrets
[INFO] Chart.yaml: icon is recommended
[WARNING] /home/michele/Engineering/cloud-patterns/common/golang-external-secrets: chart directory is missing these dependencies: external-secrets

1 chart(s) linted, 0 chart(s) failed

* Move make_common_subtree.sh to common from multicloud-gitops

* Updated values-datacenter example values file with working content

* adding working information to values-global

* updated readme with useable Makefile

* Removed previous version of common to convert to subtree from https://github.com/hybrid-cloud-patterns/common.git main

* updating options in values-datacenter

* generalizing README

Co-authored-by: Andrew Beekhof <andrew@beekhof.net>
Co-authored-by: Martin Jackson <martjack@redhat.com>
Co-authored-by: Martin Jackson <mhjacks@redhat.com>
Co-authored-by: Lester Claudio <claudiol@redhat.com>
Co-authored-by: Wolfgang Kulhanek <WolfgangKulhanek@gmail.com>
Co-authored-by: Michele Baldessari <michele@acksyn.org>
Co-authored-by: day0hero <jonny@redhat.com>
  • Loading branch information
8 people committed Mar 1, 2022
1 parent 6bfb654 commit 262d3ae
Show file tree
Hide file tree
Showing 60 changed files with 4,976 additions and 11 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# A template of a basic GitOps based pattern

### Example Makefile
The below Makefile is an example that can be used to trigger your deployments:
```sh
BOOTSTRAP=1
ARGO_TARGET_NAMESPACE=demo-namespace
PATTERN=vessel-id
COMPONENT=datacenter
SECRET_NAME="argocd-env"
TARGET_REPO=$(shell git remote show origin | grep Push | sed -e 's/.*URL://' -e 's%:[a-z].*@%@%' -e 's%:%/%' -e 's%git@%https://%' )
CHART_OPTS=-f common/examples/values-secret.yaml -f values-global.yaml -f values-datacenter.yaml --set global.targetRevision=main --set global.valuesDirectoryURL="https://github.com/pattern-clone/pattern/raw/main/" --set global.pattern="dema-pattern" --set global.namespace="pattern-namespace"
NAME=$(shell basename `pwd`)

.PHONY: default
default: show

%:
echo "Delegating $* target"
make -f common/Makefile $*

install: deploy
ifeq ($(BOOTSTRAP),1)
echo "Bootstrapping Demo Pattern"
endif

predeploy:
./scripts/precheck.sh

update: upgrade
ifeq ($(BOOTSTRAP),1)
echo "Bootstrapping Demo Pattern"
make bootstrap
endif

bootstrap:

test:
make -f common/Makefile CHARTS="$(wildcard charts/datacenter/*)" PATTERN_OPTS="-f values-datacenter.yaml" test
make -f common/Makefile CHARTS="$(wildcard charts/factory/*)" PATTERN_OPTS="-f values-factory.yaml" test
```
1 change: 0 additions & 1 deletion common
Submodule common deleted from 2f3bec
6 changes: 6 additions & 0 deletions common/.github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"default": true,
"MD003": false,
"MD013": false,
"MD033": false
}
56 changes: 56 additions & 0 deletions common/.github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Unit test common

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
on: [push, pull_request]

###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Unit common/ Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Setup helm
uses: azure/setup-helm@v1
# with:
# version: '<version>' # default is latest stable
id: install

################################
# Run Linter against code base #
################################
# - name: Lint Code Base
# uses: github/super-linter@v4
# env:
# VALIDATE_ALL_CODEBASE: false
# DEFAULT_BRANCH: main
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run make test
run: |
make test
- name: Run make helmlint
run: |
make helmlint
7 changes: 7 additions & 0 deletions common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*~
*.swp
*.swo
values-secret.yaml
.*.expected.yaml
pattern-vault.init
vault.init
62 changes: 62 additions & 0 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
BOOTSTRAP=1
SECRETS=~/values-secret.yaml
NAME=$(shell basename `pwd`)
# This is to ensure that whether we start with a git@ or https:// URL, we end up with an https:// URL
# This is because we expect to use tokens for repo authentication as opposed to SSH keys
TARGET_REPO=$(shell git remote show origin | grep Push | sed -e 's/.*URL:[[:space:]]*//' -e 's%^git@%%' -e 's%^https://%%' -e 's%:%/%' -e 's%^%https://%')
# git branch --show-current is also available as of git 2.22, but we will use this for compatibility
TARGET_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
HUBCLUSTER_APPS_DOMAIN=$(shell oc get ingresses.config/cluster -o jsonpath={.spec.domain})

# --set values always take precedence over the contents of -f
HELM_OPTS=-f values-global.yaml -f $(SECRETS) --set main.git.repoURL="$(TARGET_REPO)" --set main.git.revision=$(TARGET_BRANCH) --set main.options.bootstrap=$(BOOTSTRAP) --set global.hubClusterDomain=$(HUBCLUSTER_APPS_DOMAIN)
TEST_OPTS= -f common/examples/values-secret.yaml -f values-global.yaml --set global.repoURL="https://github.com/pattern-clone/mypattern" --set main.git.repoURL="https://github.com/pattern-clone/mypattern" --set main.git.revision=main --set main.options.bootstrap=$(BOOTSTRAP) --set global.valuesDirectoryURL="https://github.com/pattern-clone/mypattern/raw/main" --set global.pattern="mypattern" --set global.namespace="pattern-namespace" --set global.hubClusterDomain=hub.example.com --set global.localClusterDomain=region.example.com
PATTERN_OPTS=-f common/examples/values-example.yaml

# Makefiles that use this target must provide:
# PATTERN: The name of the pattern that is using it. This will be used programmatically for the source namespace
# TARGET_NAMESPACE: target namespace to install the secret into
# COMPONENT: The component of the target namespace. In industrial edge, factory or datacenter - and for the secret
# it needs to be datacenter because that's where the CI components run.
# SECRET_NAME: The name of the secret to manage
argosecret:
PATTERN="$(PATTERN)" TARGET_NAMESPACE="$(TARGET_NAMESPACE)" COMPONENT="$(COMPONENT)" SECRET_NAME="$(SECRET_NAME)" common/scripts/secret.sh

# Makefiles in the individual patterns should call these targets explicitly
# e.g. from industrial-edge: make -f common/Makefile show
show:
helm template common/install/ --name-template $(NAME) $(HELM_OPTS)

CHARTS=install clustergroup acm golang-external-secrets

test:
# Test that all values used by the chart are in values.yaml with the same defaults as the pattern
@for t in $(CHARTS); do common/scripts/test.sh $$t naked ""; if [ $$? != 0 ]; then exit 1; fi; done
# Test the charts as the pattern would drive them
@for t in $(CHARTS); do common/scripts/test.sh $$t normal "$(TEST_OPTS) $(PATTERN_OPTS)"; if [ $$? != 0 ]; then exit 1; fi; done

helmlint:
@for t in $(CHARTS); do helm lint $(TEST_OPTS) $(PATTERN_OPTS) $$t; if [ $$? != 0 ]; then exit 1; fi; done

validate-origin:
git ls-remote $(TARGET_REPO)

init:
git submodule update --init --recursive

deploy: validate-origin
helm install $(NAME) common/install/ $(HELM_OPTS)

upgrade: validate-origin
helm upgrade $(NAME) common/install/ $(HELM_OPTS)

uninstall:
helm uninstall $(NAME)

vault-init:
common/scripts/vault-utils.sh vault_init common/pattern-vault.init

vault-unseal:
common/scripts/vault-utils.sh vault_unseal common/pattern-vault.init

.phony: install test
16 changes: 16 additions & 0 deletions common/Makefile.toplevel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BOOTSTRAP=1
ARGO_TARGET_NAMESPACE=replaceme

.PHONY: default
default: show

%:
make -f common/Makefile $*

install: deploy
ifeq ($(BOOTSTRAP),1)
make -f common/Makefile TARGET_NAMESPACE=$(ARGO_TARGET_NAMESPACE) argosecret
endif

secret:
make -f common/Makefile TARGET_NAMESPACE=$(ARGO_TARGET_NAMESPACE) argosecret
6 changes: 6 additions & 0 deletions common/acm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
description: A Helm chart to configure Advanced Cluster Manager for OpenShift
keywords:
- pattern
name: acm
version: 0.0.1
8 changes: 8 additions & 0 deletions common/acm/templates/multiclusterhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: operator.open-cluster-management.io/v1
kind: MultiClusterHub
metadata:
name: multiclusterhub
namespace: open-cluster-management
annotations:
argocd.argoproj.io/sync-wave: "-1"
spec: {}
108 changes: 108 additions & 0 deletions common/acm/templates/policies/application-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# TODO: Also create a GitOpsCluster.apps.open-cluster-management.io
{{- range .Values.clusterGroup.managedClusterGroups }}
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: {{ .name }}-clustergroup-policy
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/compare-options: IgnoreExtraneous
spec:
remediationAction: enforce
disabled: false
policy-templates:
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: {{ .name }}-clustergroup-config
spec:
remediationAction: enforce
severity: med
namespaceSelector:
exclude:
- kube-*
include:
- default
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: {{ $.Values.global.pattern }}-{{ .name }}
namespace: openshift-gitops
finalizers:
- argoproj.io/finalizer
spec:
project: default
source:
repoURL: {{ coalesce .repoURL $.Values.global.repoURL }}
targetRevision: {{ coalesce .targetRevision $.Values.global.targetRevision }}
path: {{ default "common/clustergroup" .path }}
helm:
valueFiles:
- "{{ coalesce .valuesDirectoryURL $.Values.global.valuesDirectoryURL }}/values-global.yaml"
- "{{ coalesce .valuesDirectoryURL $.Values.global.valuesDirectoryURL }}/values-{{ .name }}.yaml"
parameters:
- name: global.repoURL
value: $ARGOCD_APP_SOURCE_REPO_URL
- name: global.targetRevision
value: $ARGOCD_APP_SOURCE_TARGET_REVISION
- name: global.namespace
value: $ARGOCD_APP_NAMESPACE
- name: global.pattern
value: {{ $.Values.global.pattern }}
- name: global.valuesDirectoryURL
value: {{ coalesce .valuesDirectoryURL $.Values.global.valuesDirectoryURL }}
- name: global.hubClusterDomain
value: {{ $.Values.global.hubClusterDomain }}
- name: global.localClusterDomain
value: '{{ `{{ (lookup "config.openshift.io/v1" "Ingress" "" "cluster").spec.domain }}` }}'
{{- range .helmOverrides }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
destination:
server: https://kubernetes.default.svc
namespace: {{ $.Values.global.pattern }}-{{ .name }}
syncPolicy:
automated:
prune: false
selfHeal: true
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas
- group: route.openshift.io
kind: Route
jsonPointers:
- /status
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: {{ .name }}-placement-binding
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
placementRef:
name: {{ .name }}-placement
kind: PlacementRule
apiGroup: apps.open-cluster-management.io
subjects:
- name: {{ .name }}-clustergroup-policy
kind: Policy
apiGroup: policy.open-cluster-management.io
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
name: {{ .name }}-placement
spec:
clusterConditions:
- status: 'True'
type: ManagedClusterConditionAvailable
clusterSelector: {{ .clusterSelector | toPrettyJson }}
---
{{- end }}
Loading

0 comments on commit 262d3ae

Please sign in to comment.