Skip to content

Commit

Permalink
Merge pull request #2 from upbound/feature/argocd
Browse files Browse the repository at this point in the history
feat(argo): add composition for argo
  • Loading branch information
haarchri authored Nov 17, 2023
2 parents bd62872 + aab879e commit 402613d
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 1 deletion.
248 changes: 248 additions & 0 deletions apis/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xargo.gitops.platform.upbound.io
labels:
type: gitops
spec:
writeConnectionSecretsToNamespace: upbound-system
compositeTypeRef:
apiVersion: gitops.platform.upbound.io/v1alpha1
kind: XArgo
patchSets:
- name: Common
patches:
- type: FromCompositeFieldPath
fromFieldPath: metadata.labels
toFieldPath: metadata.labels
- type: FromCompositeFieldPath
fromFieldPath: metadata.annotations
toFieldPath: metadata.annotations
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.providerConfigRef.name
- type: FromCompositeFieldPath
fromFieldPath: spec.parameters.deletionPolicy
toFieldPath: spec.deletionPolicy
resources:
- name: releaseArgo
base:
apiVersion: helm.crossplane.io/v1beta1
kind: Release
spec:
forProvider:
namespace: argocd
chart:
name: argo-cd
repository: https://argoproj.github.io/argo-helm
values:
dex:
enabled: false
redis-ha:
enabled: true
controller:
replicas: 1
metrics:
enabled: true
service:
annotations:
prometheus.io/scrape: true
env:
- name: ARGOCD_K8S_CLIENT_QPS
value: "300"
repoServer:
autoscaling:
enabled: true
minReplicas: 1
resources:
requests:
cpu : "100m"
memory : "256Mi"
limits:
cpu: "200m"
memory: "512Mi"
metrics:
enabled: true
service:
annotations:
prometheus.io/scrape: true
applicationSet:
replicaCount: 1
metrics:
enabled: true
service:
annotations:
prometheus.io/scrape: true
server:
autoscaling:
enabled: true
minReplicas: 1
resources:
requests:
cpu : "100m"
memory : "256Mi"
limits:
cpu: "200m"
memory: "512Mi"
metrics:
enabled: true
service:
annotations:
prometheus.io/scrape: true
service:
type: "LoadBalancer"
configs:
params:
application.namespaces: "cluster-*"
cm:
application.resourceTrackingMethod: "annotation"
resource.exclusions: |
- kinds:
- ProviderConfigUsage
apiGroups:
- "*"
resource.customizations: |
"*.upbound.io/*":
health.lua: |
health_status = {
status = "Progressing",
message = "Provisioning ..."
}
if obj.status == nil or obj.status.conditions == nil then
return health_status
end
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "LastAsyncOperation" then
if condition.status == "False" then
health_status.status = "Degraded"
health_status.message = condition.message
return health_status
end
end
if condition.type == "Synced" then
if condition.status == "False" then
health_status.status = "Degraded"
health_status.message = condition.message
return health_status
end
end
if condition.type == "Ready" then
if condition.status == "True" then
health_status.status = "Healthy"
health_status.message = "Resource is up-to-date."
return health_status
end
end
end
return health_status
"*.crossplane.io/*":
health.lua: |
health_status = {
status = "Progressing",
message = "Provisioning ..."
}
if obj.status == nil or obj.status.conditions == nil then
return health_status
end
for i, condition in ipairs(obj.status.conditions) do
if condition.type == "LastAsyncOperation" then
if condition.status == "False" then
health_status.status = "Degraded"
health_status.message = condition.message
return health_status
end
end
if condition.type == "Synced" then
if condition.status == "False" then
health_status.status = "Degraded"
health_status.message = condition.message
return health_status
end
end
if condition.type == "Ready" then
if condition.status == "True" then
health_status.status = "Healthy"
health_status.message = "Resource is up-to-date."
return health_status
end
end
end
return health_status
patches:
- type: PatchSet
patchSetName: Common
- fromFieldPath: spec.parameters.operators.argocd.version
toFieldPath: spec.forProvider.chart.version
- fromFieldPath: spec.parameters.providerConfigName
toFieldPath: metadata.annotations[crossplane.io/external-name]
transforms:
- type: match
match:
patterns:
- type: regexp
regexp: '.*'
result: argocd

- name: argoApplicationSet
base:
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: Object
spec:
forProvider:
manifest:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- matrix:
generators:
- git: {}
- list:
# https://github.com/argoproj/argo-cd/issues/15341
elements: []
elementsYaml: "{{ .key.components | toJson }}"
template:
metadata:
name: '{{.name}}'
spec:
project: default
syncPolicy:
automated:
selfHeal: true
syncOptions:
- CreateNamespace=true
sources:
- chart: '{{.chart}}'
repoURL: '{{.repoUrl}}'
targetRevision: '{{.version}}'
helm:
releaseName: '{{.releaseName}}'
destination:
server: https://kubernetes.default.svc
namespace: '{{.namespace}}'
patches:
- type: PatchSet
patchSetName: Common
- fromFieldPath: spec.parameters.providerConfigName
toFieldPath: spec.forProvider.manifest.metadata.name
- fromFieldPath: spec.parameters.source.git.url
toFieldPath: spec.forProvider.manifest.spec.generators[0].matrix.generators[0].git.repoURL
- fromFieldPath: spec.parameters.source.git.path
toFieldPath: spec.forProvider.manifest.spec.generators[0].matrix.generators[0].git.files[0].path
- fromFieldPath: spec.parameters.source.git.ref.name
toFieldPath: spec.forProvider.manifest.spec.generators[0].matrix.generators[0].git.revision
92 changes: 92 additions & 0 deletions apis/definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
name: xargo.gitops.platform.upbound.io
spec:
group: gitops.platform.upbound.io
names:
kind: XArgo
plural: xargo
versions:
- name: v1alpha1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
parameters:
type: object
description: ArgoCD configuration parameters.
properties:
providerConfigName:
type: string
description: Crossplane ProviderConfig to use for provisioning this resources
deletionPolicy:
description: Delete the external resources when the Claim/XR is deleted. Defaults to Delete
enum:
- Delete
- Orphan
type: string
default: Delete
kubeConfigSecretRef:
description: The KubeConfig for reconciling the Kustomization on a
remote cluster.
type: object
properties:
name:
description: Name of the Secret
type: string
key:
description: Key in the Secret
type: string
default: kubeconfig
operators:
description: Configuration for operators.
type: object
default:
argocd:
version: "5.51.1"
properties:
argocd:
description: Configuration for the ArgoCD operator.
type: object
properties:
version:
description: ArgoCD helm-chart version to run.
type: string
default: "5.51.1"
required:
- version
source:
type: object
properties:
git:
type: object
properties:
url:
description: URL specifies the Git repository URL, it can be an HTTP/S address.
pattern: ^(http|https)://.*\.git$
type: string
path:
type: string
ref:
description: Reference specifies the Git reference to resolve and
monitor for changes.
type: object
properties:
name:
description: "Name of the reference to check out"
type: string
required:
- url
- ref
required:
- git
required:
- providerConfigName
- deletionPolicy
- source
2 changes: 1 addition & 1 deletion build
Submodule build updated 1 files
+3 −3 makelib/controlplane.mk
2 changes: 2 additions & 0 deletions crossplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ spec:
dependsOn:
- provider: xpkg.upbound.io/crossplane-contrib/provider-helm
version: ">=v0.15.0"
- provider: xpkg.upbound.io/crossplane-contrib/provider-kubernetes
version: ">=v0.9.0"
13 changes: 13 additions & 0 deletions examples/argocd-xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: gitops.platform.upbound.io/v1alpha1
kind: XArgo
metadata:
name: configuration-gitops-argocd
spec:
parameters:
providerConfigName: configuration-gitops-argocd
source:
git:
url: https://github.com/haarchri/gitops-argocd.git
path: configuration-gitops-argocd/infrastructure.yaml
ref:
name: HEAD
8 changes: 8 additions & 0 deletions test/provider/providerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ metadata:
spec:
credentials:
source: InjectedIdentity
---
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: configuration-gitops-argocd
spec:
credentials:
source: InjectedIdentity
5 changes: 5 additions & 0 deletions test/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ echo "Adding provider-helm Service Account permissions"
SA=$("${KUBECTL}" -n ${CROSSPLANE_NAMESPACE} get sa -o name|grep provider-helm | sed -e "s|serviceaccount\/|${CROSSPLANE_NAMESPACE}:|g")
"${KUBECTL}" create clusterrolebinding provider-helm-admin-binding --clusterrole cluster-admin --serviceaccount="${SA}"
echo "Added provider-helm Service Account permissions"

echo "Adding provider-kubernetes Service Account permissions"
SA=$("${KUBECTL}" -n ${CROSSPLANE_NAMESPACE} get sa -o name|grep provider-kubernetes | sed -e "s|serviceaccount\/|${CROSSPLANE_NAMESPACE}:|g")
"${KUBECTL}" create clusterrolebinding provider-kubernetes-admin-binding --clusterrole cluster-admin --serviceaccount="${SA}"
echo "Added provider-kubernetes Service Account permissions"

0 comments on commit 402613d

Please sign in to comment.