Skip to content

Commit 8ef1e02

Browse files
committed
Refactor to enable shared resources to target other clusters
1 parent da4d505 commit 8ef1e02

32 files changed

+276
-29
lines changed

apps/argo/_tenant/.argocd.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.
File renamed without changes.

apps/argo/_tenant/kcl.mod renamed to apps/argo/_tenant/base/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "argo_tenant"
33
version = "0.1.0"
44

55
[dependencies]
6-
konfig = { path = "../../../konfig" }
6+
konfig = { path = "../../../../konfig" }
77

88
[profile]
99
entries = ["main.k", "${konfig:KCL_MOD}/models/render/render.k"]
File renamed without changes.

apps/argo/_tenant/base/main.k

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import konfig.models.frontend
2+
3+
tenantConfiguration: frontend.Tenant {
4+
name = "argo"
5+
}

apps/argo/_tenant/shared/kcl.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "argo"
3+
version = "0.1.0"
4+
5+
[dependencies]
6+
argo_tenant = { path = "../base" }
7+
8+
[profile]
9+
entries = ["main.k", "${konfig:KCL_MOD}/models/render/render.k"]

apps/cilium/_tenant/kcl.mod.lock renamed to apps/argo/_tenant/shared/kcl.mod.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[dependencies]
2+
[dependencies.argo_tenant]
3+
name = "argo_tenant"
4+
full_name = "argo_tenant_0.1.0"
5+
version = "0.1.0"
26
[dependencies.charts]
37
name = "charts"
48
full_name = "charts_0.1.0"

apps/argo/_tenant/main.k renamed to apps/argo/_tenant/shared/main.k

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import argo_tenant
12
import konfig.models.frontend
23

3-
tenantConfiguration: frontend.Tenant {
4-
name = "argo"
4+
tenant = argo_tenant.tenantConfiguration
55

6+
shared: frontend.SharedApp {
67
secretStores.default = {
78
name = "argo"
89
provider.doppler.auth.secretRef.dopplerToken = {

apps/argo/cd/base/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name = "argo_cd_base"
33
version = "0.1.0"
44

55
[dependencies]
6-
argo_tenant = { path = "../../_tenant" }
6+
argo = { path = "../../_tenant/shared" }

apps/argo/cd/base/kcl.mod.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[dependencies]
2+
[dependencies.argo]
3+
name = "argo"
4+
full_name = "argo_shared_0.1.0"
5+
version = "0.1.0"
26
[dependencies.argo_tenant]
37
name = "argo_tenant"
48
full_name = "argo_tenant_0.1.0"

apps/argo/cd/base/main.k

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import file
22

3-
import argo_tenant
3+
import argo
44
import charts.argo_cd
55
import konfig.models.frontend
66
import konfig.utils
@@ -9,8 +9,8 @@ _values = utils.read_yaml(file.current(), "values.yaml")
99

1010
app: frontend.App {
1111
name = "cd"
12-
tenantName = argo_tenant.tenantConfiguration.name
13-
secretStore = argo_tenant.tenantConfiguration.secretStores.default.name
12+
tenantName = argo.tenant.name
13+
secretStore = argo.shared.secretStores.default.name
1414

1515
charts.argo_cd = argo_cd.Chart {
1616
values: _values | argo_cd.Values {}

apps/argo/cd/mgmt/.app.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../konfig/models/frontend/patch.schema.json
2+
3+
syncPolicy:
4+
automated:
5+
selfHeal: true

apps/argo/cd/mgmt/kcl.mod.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[dependencies]
2+
[dependencies.argo]
3+
name = "argo"
4+
full_name = "argo_shared_0.1.0"
5+
version = "0.1.0"
26
[dependencies.argo_cd_base]
37
name = "argo_cd_base"
48
full_name = "argo_cd_base_0.1.0"

apps/cilium/_tenant/.argocd.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

apps/cilium/_tenant/base/.tenant.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../konfig/models/frontend/patch.schema.json
2+
3+
syncPolicy:
4+
automated:
5+
selfHeal: true

apps/cilium/_tenant/kcl.mod renamed to apps/cilium/_tenant/base/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cilium_tenant"
33
version = "0.1.0"
44

55
[dependencies]
6-
konfig = { path = "../../../konfig" }
6+
konfig = { path = "../../../../konfig" }
77

88
[profile]
99
entries = ["main.k", "${konfig:KCL_MOD}/models/render/render.k"]
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../konfig/models/frontend/patch.schema.json
2+
3+
syncPolicy:
4+
automated:
5+
selfHeal: true

apps/cilium/_tenant/shared/kcl.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "cilium_shared"
3+
version = "0.1.0"
4+
5+
[dependencies]
6+
cilium_tenant = { path = "../base" }
7+
8+
[profile]
9+
entries = ["main.k", "${konfig:KCL_MOD}/models/render/render.k"]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[dependencies]
2+
[dependencies.charts]
3+
name = "charts"
4+
full_name = "charts_0.1.0"
5+
version = "0.1.0"
6+
[dependencies.cilium]
7+
name = "cilium"
8+
full_name = "cilium_0.4.1"
9+
version = "0.4.1"
10+
sum = "YmVvSokDKgHSwDc7XRfVyNdniLwF+lA57/Vgi60MDGo="
11+
reg = "ghcr.io"
12+
repo = "kcl-lang/cilium"
13+
oci_tag = "0.4.1"
14+
[dependencies.cilium_tenant]
15+
name = "cilium_tenant"
16+
full_name = "cilium_tenant_0.1.0"
17+
version = "0.1.0"
18+
[dependencies.filepath]
19+
name = "filepath"
20+
full_name = "filepath_0.12.0"
21+
version = "0.12.0"
22+
sum = "zok5+7YXY/qutpo/CnjoJRbrvjWclw40zkBrB2peSa4="
23+
reg = "ghcr.io"
24+
repo = "macropower/kclipper/filepath"
25+
oci_tag = "0.12.0"
26+
[dependencies.helm]
27+
name = "helm"
28+
full_name = "helm_0.12.0"
29+
version = "0.12.0"
30+
sum = "7vrtMRNYMwG+F+lTKbmp0eC/yh0mHwWv0rYV4oP5h9I="
31+
reg = "ghcr.io"
32+
repo = "macropower/kclipper/helm"
33+
oci_tag = "0.12.0"
34+
[dependencies.json_merge_patch]
35+
name = "json_merge_patch"
36+
full_name = "json_merge_patch_0.1.1"
37+
version = "0.1.1"
38+
sum = "o1aamShk1L2MGjnN9u3IErRZ3xBNDxgmFxXsGVMt8Wk="
39+
reg = "ghcr.io"
40+
repo = "kcl-lang/json_merge_patch"
41+
oci_tag = "0.1.1"
42+
[dependencies.k8s]
43+
name = "k8s"
44+
full_name = "k8s_1.31.2"
45+
version = "1.31.2"
46+
sum = "xBZgPsnpVVyWBpahuPQHReeRx28eUHGFoaPeqbct+vs="
47+
reg = "ghcr.io"
48+
repo = "kcl-lang/k8s"
49+
oci_tag = "1.31.2"
50+
[dependencies.konfig]
51+
name = "konfig"
52+
full_name = "konfig_0.0.1"
53+
version = "0.0.1"

apps/cilium/_tenant/shared/main.k

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cilium_tenant
2+
import konfig.models.frontend
3+
4+
tenant = cilium_tenant.tenantConfiguration
5+
6+
shared: frontend.SharedApp {}

apps/cilium/system/base/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name = "cilium_system_base"
33
version = "0.1.0"
44

55
[dependencies]
6-
cilium_tenant = { path = "../../_tenant" }
6+
cilium_shared = { path = "../../_tenant/shared" }

apps/cilium/system/base/kcl.mod.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
reg = "ghcr.io"
1212
repo = "kcl-lang/cilium"
1313
oci_tag = "0.4.1"
14+
[dependencies.cilium_shared]
15+
name = "cilium_shared"
16+
full_name = "cilium_shared_0.1.0"
17+
version = "0.1.0"
1418
[dependencies.cilium_tenant]
1519
name = "cilium_tenant"
1620
full_name = "cilium_tenant_0.1.0"

apps/cilium/system/base/main.k

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import file
22

33
import charts.cilium
4-
import cilium_tenant
4+
import cilium_shared
55
import konfig.models.frontend
66
import konfig.utils
77

88
_valueFile = utils.abs_path(file.current(), "values.yaml")
99

1010
app: frontend.App {
1111
name = "system"
12-
tenantName = cilium_tenant.tenantConfiguration.name
12+
tenantName = cilium_shared.tenant.name
1313

1414
charts.cilium = cilium.Chart {
1515
valueFiles: [_valueFile]

apps/cilium/system/mgmt/.app.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../konfig/models/frontend/patch.schema.json
2+
3+
syncPolicy:
4+
automated:
5+
selfHeal: true

apps/cilium/system/mgmt/kcl.mod.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
reg = "ghcr.io"
1212
repo = "kcl-lang/cilium"
1313
oci_tag = "0.4.1"
14+
[dependencies.cilium_shared]
15+
name = "cilium_shared"
16+
full_name = "cilium_shared_0.1.0"
17+
version = "0.1.0"
1418
[dependencies.cilium_system_base]
1519
name = "cilium_system_base"
1620
full_name = "cilium_system_base_0.1.0"

appsets/tenants.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ spec:
2424
repoURL: https://github.com/MacroPower/homelab
2525
revision: main
2626
files:
27-
- path: apps/*/_tenant/.argocd.yaml
27+
- path: apps/*/_tenant/base/.tenant.yaml
2828
pathParamPrefix: app
2929
template:
3030
metadata:
31-
name: "{{index .app.path.segments 1}}-{{.values.clusterName}}"
31+
name: "{{index .app.path.segments 1}}"
3232
annotations:
3333
argocd.argoproj.io/compare-options: ServerSideDiff=true,IncludeMutationWebhook=true
3434
finalizers:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import models.frontend.shared_app
2+
import models.mixins
3+
import models.resource
4+
5+
schema SharedAppBackend[inputConfig: shared_app.SharedApp]:
6+
"""
7+
AppBackend converts the user-written front-end model `App` into a collection
8+
of k8s resources and places the resource collection into the `k8s` attribute.
9+
"""
10+
mixin [
11+
# Resource builder mixin
12+
mixins.ClusterRoleMixin,
13+
mixins.ClusterRoleBindingMixin,
14+
mixins.ClusterSecretStoreMixin,
15+
]
16+
17+
# Store the input config parameter, ensure it can be seen in protocol and mixin.
18+
config: shared_app.SharedApp = inputConfig
19+
20+
_tmp = config
21+
22+
kubernetes: resource.ResourceMapping = {}

konfig/models/backend/tenant_backend.k

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ schema TenantBackend[inputConfig: frontend.Tenant]:
1212
collection of k8s resources and places the resource collection into
1313
the `k8s` attribute.
1414
"""
15-
mixin [
16-
# Resource builder mixin
17-
mixins.ClusterSecretStoreMixin
18-
]
15+
# mixin [
16+
# # Resource builder mixin
17+
# mixins.ClusterSecretStoreMixin
18+
# ]
1919
# Store the input config parameter, ensure it can be seen in protocol and mixin.
2020
config: frontend.Tenant = inputConfig
2121

@@ -44,6 +44,70 @@ schema TenantBackend[inputConfig: frontend.Tenant]:
4444
server = _c?.server or "*"
4545
} for _k, _c in config.destinations]
4646

47+
_argoSharedApplicationSet: argov1alpha1.ApplicationSet {
48+
metadata = utils.AppMetadataBuilder(config | {
49+
name = "${config.name}-shared"
50+
}, utils.ArgoCDOptions {
51+
sync.Prune = "false"
52+
finalize = False
53+
})
54+
spec: {
55+
goTemplate = True
56+
goTemplateOptions = ["missingkey=error"]
57+
generators = [{
58+
clusters: {
59+
selector.matchLabels = {
60+
"argocd.argoproj.io/secret-type" = "cluster"
61+
}
62+
values = {
63+
clusterName = "{{.name}}"
64+
}
65+
}
66+
git: {
67+
repoURL = kmd.__META_REPO_URL
68+
revision = kmd.__META_REVISION
69+
files = [{
70+
path = "apps/${config.name}/_tenant/shared/.tenant.yaml"
71+
}]
72+
pathParamPrefix = "app"
73+
}
74+
}]
75+
template.metadata: utils.AppMetadataBuilder(config | {
76+
name = "${config.name}-{{.values.clusterName}}"
77+
}, utils.ArgoCDOptions {
78+
compare.ServerSideDiff = True
79+
compare.IncludeMutationWebhook = True
80+
sync.Prune = "confirm"
81+
})
82+
template.spec: {
83+
project = config.name
84+
source: {
85+
repoURL = kmd.__META_REPO_URL
86+
targetRevision = kmd.__META_REVISION
87+
path = "{{.app.path.path}}"
88+
}
89+
destination: {
90+
name = "{{.values.clusterName}}"
91+
namespace = "default" # This appset should only deploy cluster resources.
92+
}
93+
syncPolicy: {
94+
syncOptions = [
95+
"ServerSideApply=true"
96+
"FailOnSharedResource=true"
97+
]
98+
retry: {
99+
limit = 5
100+
backoff: {
101+
duration = "15s"
102+
factor = 2
103+
maxDuration = "5m"
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}
110+
47111
_argoApplicationSet: argov1alpha1.ApplicationSet {
48112
metadata = utils.AppMetadataBuilder(config | {
49113
name = "${config.name}-apps"
@@ -59,7 +123,7 @@ schema TenantBackend[inputConfig: frontend.Tenant]:
59123
repoURL = kmd.__META_REPO_URL
60124
revision = kmd.__META_REVISION
61125
files = [{
62-
path = "apps/${config.name}/*/*/.argocd.yaml"
126+
path = "apps/${config.name}/*/*/.app.yaml"
63127
}]
64128
pathParamPrefix = "app"
65129
}
@@ -126,5 +190,8 @@ schema TenantBackend[inputConfig: frontend.Tenant]:
126190
if _argoAppProject:
127191
"${typeof(_argoAppProject)}" = [_argoAppProject]
128192
if _argoApplicationSet:
129-
"${typeof(_argoApplicationSet)}" = [_argoApplicationSet]
193+
"${typeof(_argoApplicationSet)}" = [
194+
_argoSharedApplicationSet
195+
_argoApplicationSet
196+
]
130197
}

0 commit comments

Comments
 (0)