Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ArgoCD ordering #533

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ docs-serve: ## Preview the documentation
test: commodore_args += -f tests/$(instance).yml
test: .compile ## Compile the component
.PHONY: gen-golden
gen-golden: commodore_args += -f tests/$(instance).yml
gen-golden: commodore_args += -f tests/$(instance).yml
gen-golden: clean .compile ## Update the reference version for target `golden-diff`.
@rm -rf tests/golden/$(instance)
@mkdir -p tests/golden/$(instance)
Expand Down Expand Up @@ -95,3 +95,14 @@ clean: ## Clean the project
.PHONY: pre-commit-hook
pre-commit-hook: ## Install pre-commit hook in .git/hooks
/usr/bin/cp -fa .githooks/pre-commit .git/hooks/pre-commit

.PHONY: push-golden
push-golden: commodore_args += -f tests/$(instance).yml
push-golden: clean .compile ## Update the reference version for target `golden-diff`.
yq eval-all '. as $$item ireduce ({}; . * $$item )' hack/base_app.yaml tests/golden/vshn/appcat/apps/appcat.yaml | kubectl apply -f -
cd compiled/appcat/appcat && \
git init && \
git add . && \
git commit -m "update" && \
git remote add origin http://gitea_admin:admin@forgejo.127.0.0.1.nip.io:8088/gitea_admin/appcat.git && \
git push -u origin master --force
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ There is currently no easy way to run it locally. You need to apply the compiled

This process is not suitable for installing the component on a production system.

## Use ArgoCD in kindev

Kindev provides a forgejo instance and ArgoCD that we can use the git repositories from it. ArgoCD is available at http://argocd.127.0.0.1.nip.io:8088/.

To push any of the golden tests to it you can use `gmake push-golden -e instance=vshn`, it will:
* Compile the given golden test
* Push it to forgejo
* Create or update an ArgoCD app according to the app config in the component

There's a known issue:
On the very first sync after setting up kindev, ArgoCD doesn't recognize the `server-side` flag. Thus, the sync will fail. Simply click sync again in the ArgoCD GUI to trigger it again.

## ArgoCD SyncWaves

There's a postprocess function that will add ArgoCD syn annotations to each object of the given kind.
If any new types are introduced that need specific ordering, the `add_argo_annotations.jsonnet` is the right place.

## Documentation

The rendered documentation for this component is available on the [Commodore Components Hub](https://hub.syn.tools/appcat).
Expand Down
28 changes: 28 additions & 0 deletions class/appcat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,31 @@ parameters:
- type: jsonnet
filter: postprocess/patch_operator_deployment.jsonnet
path: ${_instance}/crossplane/helmchart/crossplane/templates
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}
- type: jsonnet
filter: postprocess/add_argo_wave_crossplane.jsonnet
path: ${_instance}/crossplane/helmchart/crossplane/templates
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/sli_exporter
enabled: ${appcat:slos:enabled}
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/sla_reporter
enabled: ${appcat:slos:sla_reporter:enabled}
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/apiserver
enabled: ${appcat:apiserver:enabled}
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/cloud_billing
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/controllers/appcat
enabled: ${appcat:controller:enabled}
- type: jsonnet
filter: postprocess/add_argo_annotations.jsonnet
path: ${_instance}/controllers/sts-resizer
1 change: 0 additions & 1 deletion component/common.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ local syncOptions = {
metadata+: {
annotations+: {
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
'argocd.argoproj.io/sync-wave': '10',
},
},
};
Expand Down
4 changes: 4 additions & 0 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,8 @@ local haPrometheusRule = {
'10_appcat_ha_monitoring': haPrometheusRule,
[if params.services.vshn.enabled && params.services.emailAlerting.enabled then '10_mailgun_secret']: emailSecret,
[if params.billing.enableMockOrgInfo then '10_mock_org_info']: mockOrgInfo,
// This is ugly, but otherwise the post-processing will fail for
// golden tests where things get dynamically enabeld or disabled, so we
// can't use an enabled filter in the post processing...
'controllers/sts-resizer/.keep': '',
}
22 changes: 22 additions & 0 deletions hack/base_app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: appcat
namespace: argocd
operation:
initiatedBy:
automated: true
retry:
limit: 5
sync:
prune: true
spec:
destination:
server: https://kubernetes.default.svc
project: default
source:
path: .
repoURL: http://forgejo-http.forgejo.svc:3000/gitea_admin/appcat
targetRevision: HEAD
directory:
recurse: true
63 changes: 63 additions & 0 deletions postprocess/add_argo_annotations.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
local com = import 'lib/commodore.libjsonnet';
local inv = com.inventory();

local annotationMap = {
Namespace: {
'argocd.argoproj.io/sync-wave': '-100',
},
ServiceAccount: {
'argocd.argoproj.io/sync-wave': '-100',
},
Role: {
'argocd.argoproj.io/sync-wave': '-100',
},
ClusterRole: {
'argocd.argoproj.io/sync-wave': '-100',
},
RoleBinding: {
'argocd.argoproj.io/sync-wave': '-100',
},
Secrets: {
'argocd.argoproj.io/sync-wave': '-100',
},
ClusterRoleBinding: {
'argocd.argoproj.io/sync-wave': '-100',
},
ObjectBucket: {
'argocd.argoproj.io/sync-options': 'Prune=false,SkipDryRunOnMissingResource=true',
},
DeploymentRuntimeConfig: {
'argocd.argoproj.io/sync-wave': '-90',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
Provider: {
'argocd.argoproj.io/sync-wave': '-80',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
CompositeResourceDefinition: {
'argocd.argoproj.io/sync-wave': '-70',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
Composition: {
'argocd.argoproj.io/sync-wave': '-60',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
ProviderConfig: {
'argocd.argoproj.io/sync-wave': '-50',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
Function: {
'argocd.argoproj.io/sync-wave': '-40',
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
};

local addArgoWave(obj) =
local annotations = std.get(annotationMap, obj.kind, if std.objectHas(obj.metadata, 'annotations') then obj.metadata.annotations else null);
if std.type(obj) == 'object' then obj {
metadata+: {
[if std.type(annotations) != 'null' then 'annotations']+: annotations,
},
} else obj;

com.fixupDir(std.extVar('output_path'), addArgoWave)
13 changes: 13 additions & 0 deletions postprocess/add_argo_wave_crossplane.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local com = import 'lib/commodore.libjsonnet';
local inv = com.inventory();

local addArgoWave(obj) =
obj {
metadata+: {
annotations: {
'argocd.argoproj.io/sync-wave': '-100',
},
},
};

com.fixupDir(std.extVar('output_path'), addArgoWave)
2 changes: 1 addition & 1 deletion postprocess/patch_operator_deployment.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local run_as_user = {
};

local fixup(obj) =
if obj.kind == 'Deployment' then
if std.type(obj) == 'object' && obj.kind == 'Deployment' then
obj {
spec+: {
template+: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: '-100'
openshift.io/node-selector: node-role.kubernetes.io/infra=
labels:
name: syn-appcat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
rbac.crossplane.io/aggregate-to-crossplane: 'true'
name: crossplane:appcat:finalizer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: appcat-services-read
name: appcat:services:read
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
rbac.authorization.k8s.io/aggregate-to-admin: 'true'
rbac.authorization.k8s.io/aggregate-to-edit: 'true'
Expand Down
3 changes: 3 additions & 0 deletions tests/golden/apiserver/appcat/appcat/10_function_appcat.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '-40'
name: function-appcat
spec:
package: ghcr.io/vshn/appcat:v4.105.2-func
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '-40'
name: function-patch-and-transform
spec:
package: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.1.4
Expand Down
14 changes: 10 additions & 4 deletions tests/golden/apiserver/appcat/appcat/10_provider_sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Provider
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '10'
argocd.argoproj.io/sync-wave: '-80'
labels:
name: provider-sql
name: provider-sql
Expand All @@ -15,6 +15,9 @@ spec:
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '-90'
name: provider-sql
spec:
deploymentTemplate:
Expand All @@ -31,7 +34,8 @@ spec:
apiVersion: v1
kind: ServiceAccount
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: provider-sql
name: provider-sql
Expand All @@ -40,7 +44,8 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: crossplane-provider-provider-sql-system-custom
name: crossplane:provider:provider-sql:system:custom
Expand All @@ -61,7 +66,8 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: crossplane-provider-provider-sql-system-custom
name: crossplane:provider:provider-sql:system:custom
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '-90'
name: function-appcat
spec:
deploymentTemplate:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
argocd.argoproj.io/sync-wave: '-90'
name: function-patch-and-transform
spec:
deploymentTemplate:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: v1
kind: ServiceAccount
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: function-appcat
name: function-appcat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: v1
kind: ServiceAccount
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: function-patch-and-transform
name: function-patch-and-transform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
argocd.argoproj.io/sync-wave: '-100'
name: appcat-apiserver
rules:
- apiGroups:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
authorization.openshift.io/aggregate-to-basic-user: 'true'
name: system-openshift4-aggregate-appcat-to-basic-user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: appcat-apiserver
name: appcat-apiserver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
annotations:
argocd.argoproj.io/sync-wave: '-100'
labels:
name: appcat-api-view
rbac.authorization.k8s.io/aggregate-to-view: 'true'
Expand Down
Loading