Skip to content

Commit 6ea5f9e

Browse files
Merge pull request #72 from projectsyn/feat/support-secrets
Support custom secrets
2 parents d5f42de + 4dee73f commit 6ea5f9e

File tree

19 files changed

+299
-8
lines changed

19 files changed

+299
-8
lines changed

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"name": "fluentbit",
88
"slug": "fluentbit",
99
"parameter_key": "fluentbit",
10-
"test_cases": "defaults",
10+
"test_cases": "defaults config",
1111
"add_lib": "n",
1212
"add_pp": "y",
1313
"add_golden": "y",
14-
"add_matrix": "n",
14+
"add_matrix": "y",
1515
"add_go_unit": "n",
1616
"automerge_patch": "y",
1717
"automerge_patch_v0": "n",

.github/workflows/test.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
args: 'check'
3030
test:
3131
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
instance:
35+
- defaults
36+
- config
3237
defaults:
3338
run:
3439
working-directory: ${{ env.COMPONENT_NAME }}
@@ -37,9 +42,14 @@ jobs:
3742
with:
3843
path: ${{ env.COMPONENT_NAME }}
3944
- name: Compile component
40-
run: make test
45+
run: make test -e instance=${{ matrix.instance }}
4146
golden:
4247
runs-on: ubuntu-latest
48+
strategy:
49+
matrix:
50+
instance:
51+
- defaults
52+
- config
4353
defaults:
4454
run:
4555
working-directory: ${{ env.COMPONENT_NAME }}
@@ -48,4 +58,4 @@ jobs:
4858
with:
4959
path: ${{ env.COMPONENT_NAME }}
5060
- name: Golden diff
51-
run: make golden-diff
61+
run: make golden-diff -e instance=${{ matrix.instance }}

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ golden-diff: commodore_args += -f tests/$(instance).yml
7171
golden-diff: clean .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
7272
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/
7373

74+
.PHONY: golden-diff-all
75+
golden-diff-all: recursive_target=golden-diff
76+
golden-diff-all: $(test_instances) ## Run golden-diff for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
77+
78+
.PHONY: gen-golden-all
79+
gen-golden-all: recursive_target=gen-golden
80+
gen-golden-all: $(test_instances) ## Run gen-golden for all instances. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
81+
82+
.PHONY: lint_kubent_all
83+
lint_kubent_all: recursive_target=lint_kubent
84+
lint_kubent_all: $(test_instances) ## Lint deprecated Kubernetes API versions for all golden test instances. Will exit on first error. Note: this doesn't work when running make with multiple parallel jobs (-j != 1).
85+
86+
.PHONY: $(test_instances)
87+
$(test_instances):
88+
$(MAKE) $(recursive_target) -e instance=$(basename $(@F))
89+
7490
.PHONY: clean
7591
clean: ## Clean the project
7692
rm -rf .cache compiled dependencies vendor helmcharts jsonnetfile*.json || true

Makefile.vars.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
5757
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5858

5959
instance ?= defaults
60+
test_instances = tests/defaults.yml tests/config.yml

class/defaults.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ parameters:
6666
K8S-Logging.Parser: "On"
6767
K8S-Logging.Exclude: "On"
6868

69+
# Configure a custom secret to deploy
70+
secretName: ${_instance}
71+
secret: {}
72+
6973
# Add volumes to the pod spec
7074
extraVolumes: []
7175
extraVolumeMounts: []

component/main.jsonnet

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,25 @@ local configmap = kube.ConfigMap(params.configMapName) {
162162
},
163163
};
164164

165+
local secret = kube.Secret(params.secretName) {
166+
metadata+: {
167+
labels+: {
168+
'app.kubernetes.io/name': params.secretName,
169+
'app.kubernetes.io/instance': instanceName,
170+
'app.kubernetes.io/component': 'fluent-bit',
171+
'app.kubernetes.io/managed-by': 'commodore',
172+
},
173+
},
174+
stringData: {
175+
[s]: params.secret[s]
176+
for s in std.objectFields(params.secret)
177+
},
178+
data:: {},
179+
};
180+
165181
{
166182
[if params.createNamespace then '00_namespace']: kube.Namespace(params.namespace),
183+
[if std.length(params.secret) > 0 then '10_custom_secret']: secret,
167184
'10_custom_config': configmap,
168185
[if params.monitoring.enabled then '20_service_monitor']:
169186
kube._Object('monitoring.coreos.com/v1', 'ServiceMonitor', 'fluent-bit') {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ capitalization of keys and values).
180180
If the dict for a section doesn't have a key `Name`, the key for the section will be used as the plugin name for the section.
181181
This allows avoiding repetition, when it's unnecessary, while still supporting having multiple outputs using the same plugin.
182182

183+
== `secretName`
184+
185+
[horizontal]
186+
type:: string
187+
default:: `${_instance}`
188+
189+
The name of the generated secret.
190+
191+
== `secret`
192+
193+
[horizontal]
194+
type:: dict
195+
default:: {}
196+
197+
Create a custom secret which containes the key-value pairs defined in this dict.
198+
183199
== `annotations`
184200

185201
[horizontal]

renovate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"separateMinorPatch": true,
1414
"postUpgradeTasks": {
1515
"commands": [
16-
"make gen-golden"
16+
"make gen-golden-all"
1717
],
1818
"fileFilters": [
1919
"tests/golden/**"

tests/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
fluentbit:
3+
secret:
4+
AWS_ACCESS_KEY_ID: <SUPER_SECRET>
5+
AWS_SECRET_ACCESS_KEY: <EVEN_MORE_SUPERER>
6+
7+
helm_values:
8+
envFrom:
9+
- secretRef:
10+
name: ${fluentbit:secretName}

tests/defaults.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
---
2-
parameters:
3-
fluentbit: {}
1+
# Overwrite parameters here
2+
3+
# parameters: {...}

0 commit comments

Comments
 (0)