Skip to content

Commit

Permalink
Update ArgoApp to set spec.project based on syn.teams in compon…
Browse files Browse the repository at this point in the history
…ent library
  • Loading branch information
simu committed Dec 19, 2024
1 parent 75ed6d2 commit bd3abf6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
3 changes: 2 additions & 1 deletion component/app.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ local root_app(team) =
else
'root-%s' % team;

argocd.App(name, params.namespace, project=project, secrets=false) {
argocd.App(name, params.namespace, secrets=false) {
metadata: {
name: name,
namespace: params.namespace,
},
spec+: {
project: project,
source+: {
path: if team == 'root' then
'manifests/apps/'
Expand Down
84 changes: 51 additions & 33 deletions lib/argocd.libjsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


local kap = import 'lib/kapitan.libjsonnet';
local syn_teams = import 'syn/syn-teams.libsonnet';

local inv = kap.inventory();
local params = inv.parameters.argocd;

Expand All @@ -20,43 +22,59 @@ local params = inv.parameters.argocd;
*
* See the documentation https://argoproj.github.io/argo-cd/operator-manual/declarative-setup/#applications
*/
local ArgoApp(component, namespace, project='syn', secrets=true) = {
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Application',
metadata: {
name: component,
namespace: params.namespace,
finalizers: [
'resources-finalizer.argocd.argoproj.io',
],
},
spec: {
project: project,
source: {
repoURL: inv.parameters.cluster.catalog_url,
targetRevision: 'HEAD',
path: 'manifests/' + component,
} + if secrets then {
plugin: {
name: 'kapitan',
local ArgoApp(component, namespace, project=null, secrets=true) =
local team = syn_teams.teamForApplication(component);
local proj =
if project != null then (
std.trace('Parameter `project` for `ArgoApp` is deprecated and will be removed in a future version. Set to `%s`' % project, project)
) else if team != syn_teams.owner then (
local app = syn_teams.appKey(component)[0];
if syn_teams.isMultiTenantAware(component) then
team
else
error
"Component instance %s isn't team-aware. " % component +
'Please check https://syn.tools/... for details on how to refactor your component to make it team-aware.'
) else
'syn';

{
apiVersion: 'argoproj.io/v1alpha1',
kind: 'Application',
metadata: {
name: component,
namespace: params.namespace,
finalizers: [
'resources-finalizer.argocd.argoproj.io',
],
},
spec: {
project: proj,
source: {
repoURL: inv.parameters.cluster.catalog_url,
targetRevision: 'HEAD',
path: 'manifests/' + component,
} + if secrets then {
plugin: {
name: 'kapitan',
},
} else {
directory: {
recurse: true,
},
},
} else {
directory: {
recurse: true,
syncPolicy: {
automated: {
prune: true,
selfHeal: true,
},
},
},
syncPolicy: {
automated: {
prune: true,
selfHeal: true,
destination: {
server: 'https://kubernetes.default.svc',
namespace: namespace,
},
},
destination: {
server: 'https://kubernetes.default.svc',
namespace: namespace,
},
},
};
};

/**
* \brief `ArgoProject` creates an Argo CD AppProject
Expand Down

0 comments on commit bd3abf6

Please sign in to comment.