Skip to content

Commit 021ff0d

Browse files
authored
Merge pull request #65 from projectsyn/add-additional-facts-config-map
Allow component to manage additional facts config map
2 parents 3f434f1 + 25b2815 commit 021ff0d

File tree

15 files changed

+230
-3
lines changed

15 files changed

+230
-3
lines changed

.cruft.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test_cases": "defaults",
1111
"add_lib": "n",
1212
"add_pp": "n",
13-
"add_golden": "n",
13+
"add_golden": "y",
1414
"add_matrix": "n",
1515
"add_go_unit": "n",
1616
"copyright_holder": "VSHN AG <[email protected]>",

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ insert_final_newline = false
2727

2828
[Makefile]
2929
indent_style = tab
30+
31+
; Ignore golden test outputs
32+
[tests/golden/**]
33+
indent_size = unset
34+
indent_style = unset
35+
insert_final_newline = unset
36+
trim_trailing_whitespace = unset

.github/workflows/test.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ jobs:
3838
path: ${{ env.COMPONENT_NAME }}
3939
- name: Compile component
4040
run: make test
41+
golden:
42+
runs-on: ubuntu-latest
43+
defaults:
44+
run:
45+
working-directory: ${{ env.COMPONENT_NAME }}
46+
steps:
47+
- uses: actions/checkout@v4
48+
with:
49+
path: ${{ env.COMPONENT_NAME }}
50+
- name: Golden diff
51+
run: make golden-diff

Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ help: ## Show this help
2121
all: lint
2222

2323
.PHONY: lint
24-
lint: lint_jsonnet lint_yaml lint_adoc ## All-in-one linting
24+
lint: lint_jsonnet lint_yaml lint_adoc lint_kubent ## All-in-one linting
2525

2626
.PHONY: lint_jsonnet
2727
lint_jsonnet: $(JSONNET_FILES) ## Lint jsonnet files
@@ -34,6 +34,9 @@ lint_yaml: ## Lint yaml files
3434
.PHONY: lint_adoc
3535
lint_adoc: ## Lint documentation
3636
$(VALE_CMD) $(VALE_ARGS)
37+
.PHONY: lint_kubent
38+
lint_kubent: ## Check for deprecated Kubernetes API versions
39+
$(KUBENT_DOCKER) $(KUBENT_ARGS) -f $(KUBENT_FILES)
3740

3841
.PHONY: format
3942
format: format_jsonnet ## All-in-one formatting
@@ -54,6 +57,17 @@ docs-serve: ## Preview the documentation
5457
.PHONY: test
5558
test: commodore_args += -f tests/$(instance).yml
5659
test: .compile ## Compile the component
60+
.PHONY: gen-golden
61+
gen-golden: commodore_args += -f tests/$(instance).yml
62+
gen-golden: clean .compile ## Update the reference version for target `golden-diff`.
63+
@rm -rf tests/golden/$(instance)
64+
@mkdir -p tests/golden/$(instance)
65+
@cp -R compiled/. tests/golden/$(instance)/.
66+
67+
.PHONY: golden-diff
68+
golden-diff: commodore_args += -f tests/$(instance).yml
69+
golden-diff: clean .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
70+
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/
5771

5872
.PHONY: clean
5973
clean: ## Clean the project

Makefile.vars.mk

+6
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ ANTORA_PREVIEW_CMD ?= $(DOCKER_CMD) run --rm --publish 35729:35729 --publish 202
4848
COMMODORE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(git_volume) $(root_volume) docker.io/projectsyn/commodore:latest
4949
COMPILE_CMD ?= $(COMMODORE_CMD) component compile . $(commodore_args)
5050
JB_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) --entrypoint /usr/local/bin/jb docker.io/projectsyn/commodore:latest install
51+
GOLDEN_FILES ?= $(shell find tests/golden/$(instance) -type f)
52+
53+
KUBENT_FILES ?= $(shell echo "$(GOLDEN_FILES)" | sed 's/ /,/g')
54+
KUBENT_ARGS ?= -c=false --helm3=false -e
55+
KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
56+
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5157

5258
instance ?= defaults

class/defaults.yml

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ parameters:
1717
argocd:
1818
image: quay.io/argoproj/argocd
1919
tag: 'v2.3.12@sha256:57474c3c31d2e3606e9c7dad2e449e604a48ac8e9aaaa413274aed41e6550e59'
20+
21+
additional_facts: {}

component/main.jsonnet

+16
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,24 @@ local deployment = kube.Deployment('steward') {
7070
},
7171
};
7272

73+
local additionalFacts = kube.ConfigMap('additional-facts') {
74+
metadata+: {
75+
namespace: params.namespace,
76+
labels: {
77+
'app.kubernetes.io/name': 'steward',
78+
'app.kubernetes.io/managed-by': 'syn',
79+
},
80+
},
81+
data: std.mapWithKey(
82+
function(_, v)
83+
if std.isString(v) then v else std.manifestJsonMinified(v),
84+
std.prune(params.additional_facts)
85+
),
86+
};
87+
7388
{
7489
'01_rbac': [ cluster_role, service_account, cluster_role_binding ],
7590
'05_secret': secret,
7691
'10_deployment': deployment,
92+
'20_additional_facts': additionalFacts,
7793
}

docs/modules/ROOT/pages/references/parameters.adoc

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ defaults:: https://github.com/projectsyn/component-steward/blob/master/class/def
5757

5858
The Steward and ArgoCD container image versions which the component should use.
5959

60+
== `additional_facts`
61+
62+
[horizontal]
63+
type:: dict
64+
default:: `{}`
65+
example::
66+
+
67+
[source,yaml]
68+
----
69+
additional_facts:
70+
myIdFromHierarchy: mx7bMF3VIfVpGhMZDnoW65oG08Wv9ICYXetH5DNM
71+
glusterVersion:
72+
major: 11
73+
minor: 1
74+
----
75+
76+
Additional facts to be added to the dynamic facts Steward provides to Lieutenant.
77+
Objects are serialized to JSON.
78+
Dynamic facts implemented in Steward can't be overridden.
79+
6080
== Example
6181

6282
[source,yaml]

renovate.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"ignorePaths": [
88
".github/**"
99
],
10+
"postUpgradeTasks": {
11+
"commands": [
12+
"make gen-golden"
13+
],
14+
"fileFilters": [ "tests/golden/**" ],
15+
"executionMode": "update"
16+
},
17+
"suppressNotifications": [ "artifactErrors" ],
1018
"labels": [
1119
"dependency"
1220
],

tests/defaults.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
1+
parameters:
2+
steward:
3+
additional_facts:
4+
blub: blub
5+
blubobj:
6+
blub: blub
7+
deleted_blub: null

tests/golden/defaults/steward/apps/steward.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
annotations: {}
5+
labels:
6+
name: syn-admin
7+
name: syn-admin
8+
rules:
9+
- apiGroups:
10+
- '*'
11+
resources:
12+
- '*'
13+
verbs:
14+
- '*'
15+
- nonResourceURLs:
16+
- '*'
17+
verbs:
18+
- '*'
19+
---
20+
apiVersion: v1
21+
kind: ServiceAccount
22+
metadata:
23+
annotations: {}
24+
labels:
25+
name: steward
26+
name: steward
27+
namespace: syn
28+
---
29+
apiVersion: rbac.authorization.k8s.io/v1
30+
kind: ClusterRoleBinding
31+
metadata:
32+
annotations: {}
33+
labels:
34+
name: syn-steward
35+
name: syn-steward
36+
roleRef:
37+
apiGroup: rbac.authorization.k8s.io
38+
kind: ClusterRole
39+
name: syn-admin
40+
subjects:
41+
- kind: ServiceAccount
42+
name: steward
43+
namespace: syn
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
data:
3+
token: ''
4+
kind: Secret
5+
metadata:
6+
annotations: {}
7+
labels:
8+
name: steward
9+
name: steward
10+
namespace: syn
11+
stringData:
12+
token: t-silent-test-1234/c-green-test-1234/steward/token
13+
type: Opaque
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
annotations: {}
5+
labels:
6+
app.kubernetes.io/managed-by: syn
7+
app.kubernetes.io/name: steward
8+
name: steward
9+
namespace: syn
10+
spec:
11+
minReadySeconds: 30
12+
replicas: 1
13+
revisionHistoryLimit: 10
14+
selector:
15+
matchLabels:
16+
app.kubernetes.io/managed-by: syn
17+
app.kubernetes.io/name: steward
18+
strategy:
19+
rollingUpdate:
20+
maxSurge: 25%
21+
maxUnavailable: 25%
22+
type: RollingUpdate
23+
template:
24+
metadata:
25+
annotations: {}
26+
labels:
27+
app.kubernetes.io/managed-by: syn
28+
app.kubernetes.io/name: steward
29+
spec:
30+
containers:
31+
- args: []
32+
env:
33+
- name: STEWARD_API
34+
value: https://api.syn.vshn.net/
35+
- name: STEWARD_ARGO_IMAGE
36+
value: quay.io/argoproj/argocd:v2.3.12@sha256:57474c3c31d2e3606e9c7dad2e449e604a48ac8e9aaaa413274aed41e6550e59
37+
- name: STEWARD_CLUSTER_ID
38+
value: c-green-test-1234
39+
- name: STEWARD_NAMESPACE
40+
valueFrom:
41+
fieldRef:
42+
apiVersion: v1
43+
fieldPath: metadata.namespace
44+
- name: STEWARD_TOKEN
45+
valueFrom:
46+
secretKeyRef:
47+
key: token
48+
name: steward
49+
image: docker.io/projectsyn/steward:v0.10.0@sha256:97d526bf5493e9dd8923818ff70ae7c778f0b726efbafb1f42f8b6316fd4cd03
50+
imagePullPolicy: Always
51+
name: steward
52+
ports: []
53+
resources:
54+
limits:
55+
cpu: 200m
56+
memory: 64Mi
57+
requests:
58+
cpu: 100m
59+
memory: 32Mi
60+
securityContext:
61+
runAsNonRoot: true
62+
stdin: false
63+
tty: false
64+
volumeMounts: []
65+
imagePullSecrets: []
66+
initContainers: []
67+
serviceAccountName: steward
68+
terminationGracePeriodSeconds: 30
69+
volumes: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
data:
3+
blub: blub
4+
blubobj: '{"blub":"blub"}'
5+
kind: ConfigMap
6+
metadata:
7+
annotations: {}
8+
labels:
9+
app.kubernetes.io/managed-by: syn
10+
app.kubernetes.io/name: steward
11+
name: additional-facts
12+
namespace: syn

0 commit comments

Comments
 (0)