Skip to content

Commit

Permalink
Merge pull request #132 from metacoma/publish-pkg-argo-cd-order-0.1.2
Browse files Browse the repository at this point in the history
Add ability to aggregate resources
  • Loading branch information
Peefy authored May 1, 2024
2 parents cfed586 + 7781a94 commit 7d44337
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 61 deletions.
102 changes: 52 additions & 50 deletions argo-cd-order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,28 @@ import k8s.api.core.v1 as k8core
import file
import argoproj.v1alpha1 as argoproj
testApp = ArgoCdOrder.make({
PreSync = [
k8core.Namespace {
metadata.name = "test-namespace"
}
k8core.ConfigMap {
metadata = {
name = "test-configmap"
namespace = "test-namespace"
annotations = {
hello = "world"
}
}
}
] + yaml.decode_all(file.read("./knative-operator.yaml"))
testApp = argoCdOrder.make({
# PreSync, PostSync and other phases works in the same way
Sync = [
argoproj.Application {
metadata = {
name = "testApp"
namespace = "argocd"
}
spec = {
destination = {
namespace = "test-namespace"
server = "https://kubernetes.default.svc"
}
project = "default"
source = {
chart = "hello"
repoURL = "https://cloudecho.github.io/charts/"
targetRevision = "0.1.2"
helm = {
values = yaml.encode({})
releaseName = "my-hello"
}
}
syncPolicy = {
automated = {}
syncOptions = [
"CreateNamespace=true"
]
}
}
}
# wave 0
[
k8core.Namespace {
metadata.name = "test"
}
k8core.Namespace {
metadata.name = "test2"
}
]
# wave 1
[
k8core.Namespace {
metadata.name = "test3"
}
k8core.Namespace {
metadata.name = "test4"
}
]
]
PostSync = []
})
manifests.yaml_stream([
Expand All @@ -81,3 +51,35 @@ manifests.yaml_stream([
```

Result yaml

```
apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: '0'
name: test
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: '0'
name: test2
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: '1'
name: test3
---
apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: '1'
name: test4
```

4 changes: 2 additions & 2 deletions argo-cd-order/kcl.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "argo-cd-order"
edition = "v0.1.1"
version = "0.1.1"
edition = "v0.1.2"
version = "0.1.2"

[dependencies]
json_merge_patch = { oci = "oci://ghcr.io/kcl-lang/json_merge_patch", tag = "0.1.0" }
24 changes: 15 additions & 9 deletions argo-cd-order/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ schema ArgoCdManifestMetadataAnnotations:
"argocd.argoproj.io/sync-wave": str
"argocd.argoproj.io/hook": str

preparePhase = lambda phase: str, phaseResources: [any] -> [ArgoCdManifest] {
[
patchResource = lambda resource: any, sync_wave: str, phase: str -> ArgoCdManifest {
p.merge(resource, { metadata.annotations = validatedAnnotations({
"argocd.argoproj.io/sync-wave" = str(sync_wave)
"argocd.argoproj.io/hook" = phase
})})
for sync_wave, resource in phaseResources if resource != None
}

preparePhase = lambda phase: str, phaseResources: [any] -> [[ArgoCdManifest]] {
[
[
patchResource(resource, str(sync_wave), phase)
for resource in resources
] for sync_wave, resources in phaseResources if resources != None

]
}
Expand All @@ -52,13 +58,13 @@ schema ArgoCdOrder:
For more details: https://argo-cd.readthedocs.io/en/stable/user-guide/sync-waves/

"""
PreSync: [any] = []
Sync: [any] = []
Skip: [any] = []
PostSync: [any] = []
SyncFail: [any] = []
PreSync: [any] = [[]]
Sync: [any] = [[]]
Skip: [any] = [[]]
PostSync: [any] = [[]]
SyncFail: [any] = [[]]

make = lambda argoCdApp: ArgoCdOrder -> [[ArgoCdManifest]] {
make = lambda argoCdApp: ArgoCdOrder {
[
preparePhase(phase, argoCdApp[phase])
for phase in argoCdApp
Expand Down

0 comments on commit 7d44337

Please sign in to comment.