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

Allow component to manage additional facts config map #65

Merged
merged 4 commits into from
Nov 14, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test_cases": "defaults",
"add_lib": "n",
"add_pp": "n",
"add_golden": "n",
"add_golden": "y",
"add_matrix": "n",
"add_go_unit": "n",
"copyright_holder": "VSHN AG <[email protected]>",
Expand Down
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ insert_final_newline = false

[Makefile]
indent_style = tab

; Ignore golden test outputs
[tests/golden/**]
indent_size = unset
indent_style = unset
insert_final_newline = unset
trim_trailing_whitespace = unset
11 changes: 11 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ jobs:
path: ${{ env.COMPONENT_NAME }}
- name: Compile component
run: make test
golden:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
steps:
- uses: actions/checkout@v4
with:
path: ${{ env.COMPONENT_NAME }}
- name: Golden diff
run: make golden-diff
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ help: ## Show this help
all: lint

.PHONY: lint
lint: lint_jsonnet lint_yaml lint_adoc ## All-in-one linting
lint: lint_jsonnet lint_yaml lint_adoc lint_kubent ## All-in-one linting

.PHONY: lint_jsonnet
lint_jsonnet: $(JSONNET_FILES) ## Lint jsonnet files
Expand All @@ -34,6 +34,9 @@ lint_yaml: ## Lint yaml files
.PHONY: lint_adoc
lint_adoc: ## Lint documentation
$(VALE_CMD) $(VALE_ARGS)
.PHONY: lint_kubent
lint_kubent: ## Check for deprecated Kubernetes API versions
$(KUBENT_DOCKER) $(KUBENT_ARGS) -f $(KUBENT_FILES)

.PHONY: format
format: format_jsonnet ## All-in-one formatting
Expand All @@ -54,6 +57,17 @@ docs-serve: ## Preview the documentation
.PHONY: test
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: clean .compile ## Update the reference version for target `golden-diff`.
@rm -rf tests/golden/$(instance)
@mkdir -p tests/golden/$(instance)
@cp -R compiled/. tests/golden/$(instance)/.

.PHONY: golden-diff
golden-diff: commodore_args += -f tests/$(instance).yml
golden-diff: clean .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/

.PHONY: clean
clean: ## Clean the project
Expand Down
6 changes: 6 additions & 0 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ ANTORA_PREVIEW_CMD ?= $(DOCKER_CMD) run --rm --publish 35729:35729 --publish 202
COMMODORE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(git_volume) $(root_volume) docker.io/projectsyn/commodore:latest
COMPILE_CMD ?= $(COMMODORE_CMD) component compile . $(commodore_args)
JB_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) --entrypoint /usr/local/bin/jb docker.io/projectsyn/commodore:latest install
GOLDEN_FILES ?= $(shell find tests/golden/$(instance) -type f)

KUBENT_FILES ?= $(shell echo "$(GOLDEN_FILES)" | sed 's/ /,/g')
KUBENT_ARGS ?= -c=false --helm3=false -e
KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)

instance ?= defaults
2 changes: 2 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ parameters:
argocd:
image: quay.io/argoproj/argocd
tag: 'v2.3.12@sha256:57474c3c31d2e3606e9c7dad2e449e604a48ac8e9aaaa413274aed41e6550e59'

additional_facts: {}
16 changes: 16 additions & 0 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,24 @@ local deployment = kube.Deployment('steward') {
},
};

local additionalFacts = kube.ConfigMap('additional-facts') {
metadata+: {
namespace: params.namespace,
labels: {
'app.kubernetes.io/name': 'steward',
'app.kubernetes.io/managed-by': 'syn',
},
},
data: std.mapWithKey(
function(_, v)
if std.isString(v) then v else std.manifestJsonMinified(v),
std.prune(params.additional_facts)
),
};

{
'01_rbac': [ cluster_role, service_account, cluster_role_binding ],
'05_secret': secret,
'10_deployment': deployment,
'20_additional_facts': additionalFacts,
}
20 changes: 20 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ defaults:: https://github.com/projectsyn/component-steward/blob/master/class/def

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

== `additional_facts`

[horizontal]
type:: dict
default:: `{}`
example::
+
[source,yaml]
----
additional_facts:
myIdFromHierarchy: mx7bMF3VIfVpGhMZDnoW65oG08Wv9ICYXetH5DNM
glusterVersion:
major: 11
minor: 1
----

Additional facts to be added to the dynamic facts Steward provides to Lieutenant.
Objects are serialized to JSON.
bastjan marked this conversation as resolved.
Show resolved Hide resolved
Dynamic facts implemented in Steward can't be overridden.

== Example

[source,yaml]
Expand Down
8 changes: 8 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"ignorePaths": [
".github/**"
],
"postUpgradeTasks": {
"commands": [
"make gen-golden"
],
"fileFilters": [ "tests/golden/**" ],
"executionMode": "update"
},
"suppressNotifications": [ "artifactErrors" ],
"labels": [
"dependency"
],
Expand Down
8 changes: 7 additions & 1 deletion tests/defaults.yml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@

parameters:
steward:
additional_facts:
blub: blub
blubobj:
blub: blub
deleted_blub: null
Empty file.
43 changes: 43 additions & 0 deletions tests/golden/defaults/steward/steward/01_rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations: {}
labels:
name: syn-admin
name: syn-admin
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- nonResourceURLs:
- '*'
verbs:
- '*'
---
apiVersion: v1
kind: ServiceAccount
metadata:
annotations: {}
labels:
name: steward
name: steward
namespace: syn
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations: {}
labels:
name: syn-steward
name: syn-steward
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: syn-admin
subjects:
- kind: ServiceAccount
name: steward
namespace: syn
13 changes: 13 additions & 0 deletions tests/golden/defaults/steward/steward/05_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
data:
token: ''
kind: Secret
metadata:
annotations: {}
labels:
name: steward
name: steward
namespace: syn
stringData:
token: t-silent-test-1234/c-green-test-1234/steward/token
type: Opaque
69 changes: 69 additions & 0 deletions tests/golden/defaults/steward/steward/10_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app.kubernetes.io/managed-by: syn
app.kubernetes.io/name: steward
name: steward
namespace: syn
spec:
minReadySeconds: 30
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/managed-by: syn
app.kubernetes.io/name: steward
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations: {}
labels:
app.kubernetes.io/managed-by: syn
app.kubernetes.io/name: steward
spec:
containers:
- args: []
env:
- name: STEWARD_API
value: https://api.syn.vshn.net/
- name: STEWARD_ARGO_IMAGE
value: quay.io/argoproj/argocd:v2.3.12@sha256:57474c3c31d2e3606e9c7dad2e449e604a48ac8e9aaaa413274aed41e6550e59
- name: STEWARD_CLUSTER_ID
value: c-green-test-1234
- name: STEWARD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: STEWARD_TOKEN
valueFrom:
secretKeyRef:
key: token
name: steward
image: docker.io/projectsyn/steward:v0.10.0@sha256:97d526bf5493e9dd8923818ff70ae7c778f0b726efbafb1f42f8b6316fd4cd03
imagePullPolicy: Always
name: steward
ports: []
resources:
limits:
cpu: 200m
memory: 64Mi
requests:
cpu: 100m
memory: 32Mi
securityContext:
runAsNonRoot: true
stdin: false
tty: false
volumeMounts: []
imagePullSecrets: []
initContainers: []
serviceAccountName: steward
terminationGracePeriodSeconds: 30
volumes: []
12 changes: 12 additions & 0 deletions tests/golden/defaults/steward/steward/20_additional_facts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
data:
blub: blub
blubobj: '{"blub":"blub"}'
kind: ConfigMap
metadata:
annotations: {}
labels:
app.kubernetes.io/managed-by: syn
app.kubernetes.io/name: steward
name: additional-facts
namespace: syn
Loading