From d3272b9c4bba32ad8f22db08e63c5b94b9dd42ba Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Wed, 6 Mar 2024 14:22:58 +0100 Subject: [PATCH] feat(argo): more configuration options and generic git sync via matrix (#29) Signed-off-by: Christopher Haar --- .github/workflows/yamllint.yaml | 15 +++++++ Makefile | 2 +- apis/composition.yaml | 73 ++++++++++++++++++++++++++------- apis/definition.yaml | 6 +++ examples/argocd-xr.yaml | 30 ++++++++++++-- gitops/infrastructure.yaml | 9 ++++ 6 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/yamllint.yaml create mode 100644 gitops/infrastructure.yaml diff --git a/.github/workflows/yamllint.yaml b/.github/workflows/yamllint.yaml new file mode 100644 index 0000000..54684f4 --- /dev/null +++ b/.github/workflows/yamllint.yaml @@ -0,0 +1,15 @@ +name: yamllint +on: [pull_request] +jobs: + yamllint: + name: runner / yamllint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: yamllint + uses: reviewdog/action-yamllint@e419e43894e391d358ebf996800673d72de6c69b # v1.11.0 + with: + reporter: github-pr-review + filter_mode: nofilter + yamllint_flags: 'apis/' + fail_on_error: true diff --git a/Makefile b/Makefile index 37c4d09..150daa6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ UPTEST_VERSION = v0.11.1 # ==================================================================================== # Setup XPKG XPKG_DIR = $(shell pwd) -XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml,test/provider/*.yaml +XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml,test/provider/*.yaml,gitops/*.yaml XPKG_REG_ORGS ?= xpkg.upbound.io/upbound # NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are # inferred. diff --git a/apis/composition.yaml b/apis/composition.yaml index 228ec12..5fd6671 100644 --- a/apis/composition.yaml +++ b/apis/composition.yaml @@ -62,7 +62,32 @@ spec: message = "Provisioning ..." } + local function contains (table, val) + for i, v in ipairs(table) do + if v == val then + return true + end + end + return false + end + + local has_no_status = { + "ProviderConfig", + "ProviderConfigUsage" + } + + if obj.status == nil and contains(has_no_status, obj.kind) then + health_status.status = "Healthy" + health_status.message = "Resource is up-to-date." + return health_status + end + if obj.status == nil or obj.status.conditions == nil then + if obj.kind == "ProviderConfig" and obj.status.users ~= nil then + health_status.status = "Healthy" + health_status.message = "Resource is in use." + return health_status + end return health_status end @@ -101,6 +126,27 @@ spec: message = "Provisioning ..." } + local function contains (table, val) + for i, v in ipairs(table) do + if v == val then + return true + end + end + return false + end + + local has_no_status = { + "Composition", + "CompositionRevision", + "DeploymentRuntimeConfig", + "ControllerConfig" + } + if obj.status == nil and contains(has_no_status, obj.kind) then + health_status.status = "Healthy" + health_status.message = "Resource is up-to-date." + return health_status + end + if obj.status == nil or obj.status.conditions == nil then return health_status end @@ -122,7 +168,7 @@ spec: end end - if condition.type == "Ready" then + if contains({"Ready", "Healthy", "Offered", "Established"}, condition.type) then if condition.status == "True" then health_status.status = "Healthy" health_status.message = "Resource is up-to-date." @@ -132,11 +178,6 @@ spec: end return health_status - resource.exclusions: | - - kinds: - - ProviderConfigUsage - apiGroups: - - "*" params: application.namespaces: cluster-* controller: @@ -204,6 +245,12 @@ spec: - type: FromCompositeFieldPath fromFieldPath: spec.parameters.oidcConfig toFieldPath: spec.forProvider.values.server.config[oidc.config] + - type: FromCompositeFieldPath + fromFieldPath: spec.parameters.resourceInclusions + toFieldPath: spec.forProvider.values.configs.cm[resource.inclusions] + - type: FromCompositeFieldPath + fromFieldPath: spec.parameters.resourceExclusions + toFieldPath: spec.forProvider.values.configs.cm[resource.exclusions] - type: FromCompositeFieldPath fromFieldPath: spec.parameters.operators.argocd.version toFieldPath: spec.forProvider.chart.version @@ -247,14 +294,12 @@ spec: spec: destination: namespace: '{{.namespace}}' - server: https://kubernetes.default.svc - project: default - sources: - - chart: '{{.chart}}' - helm: - releaseName: '{{.releaseName}}' - repoURL: '{{.repoUrl}}' - targetRevision: '{{.version}}' + server: '{{.server}}' + project: '{{.project}}' + source: + repoURL: '{{.repoUrl}}' + targetRevision: '{{.version}}' + path: '{{.folder}}' syncPolicy: automated: selfHeal: true diff --git a/apis/definition.yaml b/apis/definition.yaml index dd19c86..32bf603 100644 --- a/apis/definition.yaml +++ b/apis/definition.yaml @@ -31,6 +31,12 @@ spec: oidcConfig: type: string description: set oidc config for argocd server + resourceInclusions: + type: string + description: configure the list of included resources + resourceExclusions: + type: string + description: configure the list of exclude resources deletionPolicy: description: Delete the external resources when the Claim/XR is deleted. Defaults to Delete enum: diff --git a/examples/argocd-xr.yaml b/examples/argocd-xr.yaml index 11c5c34..2447dd0 100644 --- a/examples/argocd-xr.yaml +++ b/examples/argocd-xr.yaml @@ -5,17 +5,39 @@ metadata: spec: parameters: # this configuration is needed if you want to configure argocd with oidc - # ingressUrl: argocd-platform-ref-aws-cnoe.upboundrocks.cloud + # ingressUrl: configuration-gitops-argocd.example.com # oidcConfig: | # name: Keycloak - # issuer: https://keycloak-platform-ref-aws-cnoe.upboundrocks.cloud/realms/master + # issuer: https://configuration-gitops-argocd.example.com/realms/master # clientID: argocd # clientSecret: 0000000000000000000 # requestedScopes: ['openid', 'profile', 'email', 'groups'] + resourceExclusions: | + - kinds: + - ProviderConfigUsage + apiGroups: + - "*" + - kinds: + - "Nodes" + apiGroups: + - "*" + clusters: + - "ctp-*" + resourceInclusions: | + - apiGroups: + - "*" + kinds: + - Provider + - Function + - Configuration + - CompositeResourceDefinition + - Composition + clusters: + - "ctp-*" providerConfigName: configuration-gitops-argocd source: git: - url: https://github.com/haarchri/gitops-argocd.git - path: configuration-gitops-argocd/infrastructure.yaml + url: https://github.com/upbound/configuration-gitops-argocd.git + path: gitops ref: name: HEAD diff --git a/gitops/infrastructure.yaml b/gitops/infrastructure.yaml new file mode 100644 index 0000000..8b3be40 --- /dev/null +++ b/gitops/infrastructure.yaml @@ -0,0 +1,9 @@ +key: + components: + - name: spaces-reference-architecture + namespace: upbound-system + server: https://kubernetes.default.svc + project: default + repoUrl: https://github.com/upbound/spaces-reference-architecture.git + version: HEAD + folder: "bootstrap/"