Skip to content

Commit b4d00ce

Browse files
authored
feat(flux): add flux-implementation (#2)
* feat(flux): add flux-implementation Signed-off-by: Christopher Haar <[email protected]> * style(comment): add comment for empty result patch Signed-off-by: Christopher Haar <[email protected]> --------- Signed-off-by: Christopher Haar <[email protected]>
1 parent b3c4fe9 commit b4d00ce

File tree

7 files changed

+307
-8
lines changed

7 files changed

+307
-8
lines changed

Makefile

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ UPTEST_VERSION = v0.6.1
1919
# ====================================================================================
2020
# Setup XPKG
2121
XPKG_DIR = $(shell pwd)
22-
XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml
22+
XPKG_IGNORE = .github/workflows/*.yaml,.github/workflows/*.yml,examples/*.yaml,.work/uptest-datasource.yaml,test/provider/*.yaml
2323
XPKG_REG_ORGS ?= xpkg.upbound.io/upbound
2424
# NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are
2525
# inferred.
@@ -59,17 +59,11 @@ build.init: $(UP)
5959
# End to End Testing
6060

6161
# This target requires the following environment variables to be set:
62-
# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat ~/.aws/credentials)
63-
# - To ensure the proper functioning of the end-to-end test resource pre-deletion hook, it is crucial to arrange your resources appropriately.
64-
# You can check the basic implementation here: https://github.com/upbound/uptest/blob/main/internal/templates/01-delete.yaml.tmpl.
65-
# - UPTEST_DATASOURCE_PATH (optional), see https://github.com/upbound/uptest#injecting-dynamic-values-and-datasource
6662
uptest: $(UPTEST) $(KUBECTL) $(KUTTL)
6763
@$(INFO) running automated tests
68-
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e examples/flux-xr.yaml,examples/eks-xr.yaml --data-source="${UPTEST_DATASOURCE_PATH}" --setup-script=test/setup.sh --default-timeout=2400 || $(FAIL)
64+
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e examples/flux-xr.yaml --setup-script=test/setup.sh --default-timeout=2400 || $(FAIL)
6965
@$(OK) running automated tests
7066

71-
# This target requires the following environment variables to be set:
72-
# - UPTEST_CLOUD_CREDENTIALS, cloud credentials for the provider being tested, e.g. export UPTEST_CLOUD_CREDENTIALS=$(cat ~/.aws/credentials)
7367
e2e: build controlplane.up local.xpkg.deploy.configuration.$(PROJECT_NAME) uptest
7468

7569
.PHONY: uptest e2e

apis/composition.yaml

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: xflux.gitops.platform.upbound.io
5+
labels:
6+
type: gitops
7+
spec:
8+
writeConnectionSecretsToNamespace: upbound-system
9+
compositeTypeRef:
10+
apiVersion: gitops.platform.upbound.io/v1alpha1
11+
kind: XFlux
12+
patchSets:
13+
- name: Common
14+
patches:
15+
- type: FromCompositeFieldPath
16+
fromFieldPath: metadata.labels
17+
toFieldPath: metadata.labels
18+
- type: FromCompositeFieldPath
19+
fromFieldPath: metadata.annotations
20+
toFieldPath: metadata.annotations
21+
- type: FromCompositeFieldPath
22+
fromFieldPath: spec.parameters.providerConfigName
23+
toFieldPath: spec.providerConfigRef.name
24+
- type: FromCompositeFieldPath
25+
fromFieldPath: spec.parameters.deletionPolicy
26+
toFieldPath: spec.deletionPolicy
27+
resources:
28+
- name: releaseFlux
29+
base:
30+
apiVersion: helm.crossplane.io/v1beta1
31+
kind: Release
32+
spec:
33+
forProvider:
34+
namespace: flux-system
35+
chart:
36+
name: flux2
37+
values:
38+
imageAutomationController:
39+
create: false
40+
imageReflectionController:
41+
create: false
42+
patches:
43+
- type: PatchSet
44+
patchSetName: Common
45+
- fromFieldPath: spec.parameters.operators.flux.version
46+
toFieldPath: spec.forProvider.chart.version
47+
- type: CombineFromComposite
48+
combine:
49+
variables:
50+
- fromFieldPath: spec.parameters.operators.flux.version
51+
strategy: string
52+
string:
53+
fmt: https://github.com/fluxcd-community/helm-charts/releases/download/flux2-%[1]s/flux2-%[1]s.tgz
54+
toFieldPath: spec.forProvider.chart.url
55+
56+
- name: syncFlux
57+
base:
58+
apiVersion: helm.crossplane.io/v1beta1
59+
kind: Release
60+
spec:
61+
forProvider:
62+
namespace: flux-system
63+
chart:
64+
name: flux2-sync
65+
repository: https://fluxcd-community.github.io/helm-charts
66+
values:
67+
gitRepository:
68+
spec:
69+
gitImplementation: go-git
70+
kustomization:
71+
spec:
72+
sourceRef:
73+
kind: GitRepository
74+
patches:
75+
- type: PatchSet
76+
patchSetName: Common
77+
- fromFieldPath: spec.parameters.operators.flux-sync.version
78+
toFieldPath: spec.forProvider.chart.version
79+
- fromFieldPath: spec.parameters.providerConfigName
80+
toFieldPath: metadata.annotations[crossplane.io/external-name]
81+
- fromFieldPath: spec.parameters.source.git.timeout
82+
toFieldPath: spec.forProvider.values.gitRepository.spec.timeout
83+
- fromFieldPath: spec.parameters.source.git.interval
84+
toFieldPath: spec.forProvider.values.gitRepository.spec.interval
85+
- fromFieldPath: spec.parameters.source.git.interval
86+
toFieldPath: spec.forProvider.values.kustomization.spec.interval
87+
- fromFieldPath: spec.parameters.source.git.ref.name
88+
toFieldPath: spec.forProvider.values.gitRepository.spec.ref.name
89+
- fromFieldPath: spec.parameters.source.git.url
90+
toFieldPath: spec.forProvider.values.gitRepository.spec.url
91+
- fromFieldPath: spec.parameters.source.git.path
92+
toFieldPath: spec.forProvider.values.kustomization.spec.path
93+
- fromFieldPath: spec.parameters.kubeConfigSecretRef.name
94+
toFieldPath: spec.forProvider.values.kustomization.spec.kubeConfig.secretRef.name
95+
- fromFieldPath: spec.parameters.kubeConfigSecretRef.key
96+
toFieldPath: spec.forProvider.values.kustomization.spec.kubeConfig.secretRef.key
97+
# the sync helm-chart defines ref.branch master per default in values
98+
# https://github.com/fluxcd-community/helm-charts/blob/flux2-sync-1.7.2/charts/flux2-sync/values.yaml#L46
99+
# we want to use ref.name because server-side-apply is an issue when using ref.tag or ref.branch switch
100+
- fromFieldPath: spec.parameters.providerConfigName
101+
toFieldPath: spec.forProvider.values.gitRepository.spec.ref.branch
102+
transforms:
103+
- type: match
104+
match:
105+
patterns:
106+
- type: regexp
107+
regexp: '.*'
108+
result: ''

apis/definition.yaml

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: CompositeResourceDefinition
3+
metadata:
4+
name: xflux.gitops.platform.upbound.io
5+
spec:
6+
group: gitops.platform.upbound.io
7+
names:
8+
kind: XFlux
9+
plural: xflux
10+
versions:
11+
- name: v1alpha1
12+
served: true
13+
referenceable: true
14+
schema:
15+
openAPIV3Schema:
16+
type: object
17+
properties:
18+
spec:
19+
type: object
20+
properties:
21+
parameters:
22+
type: object
23+
description: Flux configuration parameters.
24+
properties:
25+
providerConfigName:
26+
type: string
27+
description: Crossplane ProviderConfig to use for provisioning this resources
28+
deletionPolicy:
29+
description: Delete the external resources when the Claim/XR is deleted. Defaults to Delete
30+
enum:
31+
- Delete
32+
- Orphan
33+
type: string
34+
default: Delete
35+
kubeConfigSecretRef:
36+
description: The KubeConfig for reconciling the Kustomization on a
37+
remote cluster.
38+
type: object
39+
properties:
40+
name:
41+
description: Name of the Secret
42+
type: string
43+
key:
44+
description: Key in the Secret
45+
type: string
46+
default: kubeconfig
47+
operators:
48+
description: Configuration for operators.
49+
type: object
50+
default:
51+
flux:
52+
version: "2.10.6"
53+
flux-sync:
54+
version: "1.7.2"
55+
properties:
56+
flux:
57+
description: Configuration for the Flux GitOps operator.
58+
type: object
59+
properties:
60+
version:
61+
description: flux helm-chart version to run.
62+
type: string
63+
default: "2.10.6"
64+
required:
65+
- version
66+
flux-sync:
67+
description: Configuration for the Flux Sync Helm-Chart.
68+
type: object
69+
properties:
70+
version:
71+
description: flux sync helm-chart version to run.
72+
type: string
73+
default: "1.7.2"
74+
required:
75+
- version
76+
source:
77+
type: object
78+
properties:
79+
git:
80+
type: object
81+
properties:
82+
interval:
83+
default: "5m0s"
84+
description: Interval at which the GitRepository URL is checked for
85+
updates. This interval is approximate and may be subject to jitter
86+
to ensure efficient use of resources.
87+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
88+
type: string
89+
timeout:
90+
default: "60s"
91+
description: Timeout for Git operations like cloning, defaults to
92+
60s.
93+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
94+
type: string
95+
url:
96+
description: URL specifies the Git repository URL, it can be an HTTP/S
97+
or SSH address.
98+
pattern: ^(http|https|ssh)://.*$
99+
type: string
100+
path:
101+
type: string
102+
default: "/"
103+
ref:
104+
description: Reference specifies the Git reference to resolve and
105+
monitor for changes.
106+
type: object
107+
properties:
108+
name:
109+
description: "Name of the reference to check out; takes precedence
110+
over Branch, Tag and SemVer. \n It must be a valid Git reference:
111+
https://git-scm.com/docs/git-check-ref-format#_description Examples:
112+
\"refs/heads/main\", \"refs/tags/v0.1.0\", \"refs/pull/420/head\",
113+
\"refs/merge-requests/1/head\""
114+
type: string
115+
required:
116+
- interval
117+
- timeout
118+
- url
119+
- path
120+
- ref
121+
required:
122+
- git
123+
required:
124+
- providerConfigName
125+
- deletionPolicy
126+
- source

crossplane.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: meta.pkg.crossplane.io/v1alpha1
2+
kind: Configuration
3+
metadata:
4+
name: configuration-gitops-flux
5+
annotations:
6+
meta.crossplane.io/maintainer: Upbound <[email protected]>
7+
meta.crossplane.io/source: github.com/upbound/configuration-gitops-flux
8+
meta.crossplane.io/license: Apache-2.0
9+
meta.crossplane.io/description: |
10+
This Crossplane configuration is a starting point to use gitops in your own internal cloud.
11+
meta.crossplane.io/readme: |
12+
This Crossplane configuration is a starting point to use gitops in your own internal cloud.
13+
To learn more checkout the [GitHub repo](https://github.com/upbound/configuration-gitops-flux/)
14+
that you can copy and customize to meet the exact needs of your organization!
15+
spec:
16+
crossplane:
17+
version: ">=v1.13.2-0"
18+
dependsOn:
19+
- provider: xpkg.upbound.io/crossplane-contrib/provider-helm
20+
version: ">=v0.15.0"

examples/flux-xr.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: gitops.platform.upbound.io/v1alpha1
2+
kind: XFlux
3+
metadata:
4+
name: configuration-gitops-flux
5+
spec:
6+
parameters:
7+
providerConfigName: configuration-gitops-flux
8+
source:
9+
git:
10+
url: https://github.com/upbound/platform-ref-aws/
11+
ref:
12+
# refs/heads/main
13+
# refs/tags/v0.1.0
14+
# refs/pull/420/head
15+
# refs/merge-requests/1/head
16+
name: refs/heads/main

test/provider/providerconfigs.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: helm.crossplane.io/v1beta1
2+
kind: ProviderConfig
3+
metadata:
4+
name: configuration-gitops-flux
5+
spec:
6+
credentials:
7+
source: InjectedIdentity

test/setup.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -aeuo pipefail
3+
4+
echo "Running setup.sh"
5+
CROSSPLANE_NAMESPACE="upbound-system"
6+
SCRIPT_DIR=$( cd -- $( dirname -- "${BASH_SOURCE[0]}" ) &> /dev/null && pwd )
7+
8+
echo "Waiting until all configurations are healthy/installed..."
9+
"${KUBECTL}" wait configuration.pkg --all --for=condition=Healthy --timeout 5m
10+
"${KUBECTL}" wait configuration.pkg --all --for=condition=Installed --timeout 5m
11+
12+
echo "Waiting until all installed provider packages are healthy..."
13+
"${KUBECTL}" wait provider.pkg --all --for condition=Healthy --timeout 5m
14+
15+
echo "Waiting for all pods to come online..."
16+
"${KUBECTL}" -n upbound-system wait --for=condition=Available deployment --all --timeout=5m
17+
18+
echo "Waiting for all XRDs to be established..."
19+
"${KUBECTL}" wait xrd --all --for condition=Established
20+
21+
echo "Installing providerconfigs"
22+
"${KUBECTL}" apply -f ${SCRIPT_DIR}/provider/providerconfigs.yaml
23+
echo "Installed providerconfigs"
24+
25+
echo "Adding provider-helm Service Account permissions"
26+
SA=$("${KUBECTL}" -n ${CROSSPLANE_NAMESPACE} get sa -o name|grep provider-helm | sed -e "s|serviceaccount\/|${CROSSPLANE_NAMESPACE}:|g")
27+
"${KUBECTL}" create clusterrolebinding provider-helm-admin-binding --clusterrole cluster-admin --serviceaccount="${SA}"
28+
echo "Added provider-helm Service Account permissions"

0 commit comments

Comments
 (0)