Skip to content

Commit bed2492

Browse files
authored
feat: add extraManifests, extraEnv, and configurable secret keys (#137)
1 parent 5c0e640 commit bed2492

File tree

8 files changed

+130
-11
lines changed

8 files changed

+130
-11
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919

2020
- [ ] Bump the chart version (`Chart.yaml` -> `version`)
2121
- [ ] JSON Schema updated (`values.schema.json`)
22-
- [ ] Update `README.md` via helm-docs
22+
- [ ] Update `README.md` via [helm-docs](https://github.com/norwoodj/helm-docs) (or `make prep`)
23+
- [ ] Run `pre-commit run --all-files` via [pre-commit](https://pre-commit.com/) (or `make prep`)
2324
- [ ] Update Artifacthub annotation (`Chart.yaml` -> `artifacthub.io/changes`, `artifacthub.io/images`)

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
.PHONY: pre-commit
3+
pre-commit:
4+
pre-commit run --all-files
5+
6+
7+
.PHONY: helm-docs
8+
helm-docs:
9+
helm-docs
10+
11+
12+
.PHONY: tools-macos
13+
tools-macos:
14+
brew install pre-commit norwoodj/tap/helm-docs
15+
16+
.PHONY: prep
17+
prep: helm-docs pre-commit

charts/k8s-image-swapper/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: k8s-image-swapper
33
description: Mirror images into your own registry and swap image references automatically.
44
type: application
5-
version: 1.7.0
5+
version: 1.8.0
66
appVersion: 1.4.1
77
home: https://github.com/estahn/charts/tree/main/charts/k8s-image-swapper
88
keywords:
@@ -15,7 +15,7 @@ maintainers:
1515
name: estahn
1616
annotations:
1717
artifacthub.io/changes: |
18-
- "Allow to set annotations for deployment"
18+
- "Allow configure AWS secret and deploy extraManifests"
1919
artifacthub.io/images: |
2020
- name: k8s-image-webhook
2121
image: ghcr.io/estahn/k8s-image-swapper:1.4.1

charts/k8s-image-swapper/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# k8s-image-swapper
22

3-
![Version: 1.7.0](https://img.shields.io/badge/Version-1.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.4.1](https://img.shields.io/badge/AppVersion-1.4.1-informational?style=flat-square)
3+
![Version: 1.8.0](https://img.shields.io/badge/Version-1.8.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.4.1](https://img.shields.io/badge/AppVersion-1.4.1-informational?style=flat-square)
44

55
Mirror images into your own registry and swap image references automatically.
66

@@ -21,7 +21,10 @@ Mirror images into your own registry and swap image references automatically.
2121
| autoscaling.maxReplicas | int | `100` | |
2222
| autoscaling.minReplicas | int | `1` | |
2323
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
24-
| awsSecretName | string | `""` | |
24+
| awsSecretKeys | object | `{"accessKeyID":"aws_access_key_id","secretAccessKey":"aws_secret_access_key"}` | Specify which keys to pull from the .awsSecretName secret for the associated environment variables. |
25+
| awsSecretKeys.accessKeyID | string | `"aws_access_key_id"` | If using Hashicorp Vault Operator w/ AWS engine, use `access_key` |
26+
| awsSecretKeys.secretAccessKey | string | `"aws_secret_access_key"` | If using Hashicorp Vault Operator w/ AWS engine, use `secret_key` |
27+
| awsSecretName | string | `""` | If set, the secret will be used as environment variables, see awsSecretKeys. |
2528
| certmanager.enabled | bool | `false` | |
2629
| commonLabels | object | `{}` | Labels that will be added on all the resources (not in selectors) |
2730
| config.dryRun | bool | `true` | |
@@ -34,6 +37,9 @@ Mirror images into your own registry and swap image references automatically.
3437
| deployment.annotations | object | `{}` | |
3538
| dev.enabled | bool | `false` | |
3639
| dev.webhookURL | string | `"https://xxx.ngrok.io"` | |
40+
| extraEnv | list | `[]` | Additional environment variables to be defined on the container Follows the same syntax as containers.env in a Pod v1 API |
41+
| extraManifests | list | `[]` | Additional manifests to be deployed Can be either a full object OR a string containing valid YAML |
42+
| extraManifestsTemplated | list | `[]` | Additional manifests to be deployed. These will be passed through the templating engine Useful if you need to use values from this chart in your manifests |
3743
| fullnameOverride | string | `""` | |
3844
| hostNetwork | bool | `false` | |
3945
| image.pullPolicy | string | `"IfNotPresent"` | |

charts/k8s-image-swapper/templates/deployment.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,23 @@ spec:
4141
{{- toYaml .Values.securityContext | nindent 12 }}
4242
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
4343
imagePullPolicy: {{ .Values.image.pullPolicy }}
44-
{{- if .Values.awsSecretName }}
44+
{{- if or .Values.awsSecretName .Values.extraEnv }}
4545
env:
46+
{{- if .Values.awsSecretName }}
4647
- name: AWS_ACCESS_KEY_ID
4748
valueFrom:
4849
secretKeyRef:
4950
name: {{ .Values.awsSecretName }}
50-
key: aws_access_key_id
51+
key: {{ .Values.awsSecretKeys.accessKeyID }}
5152
- name: AWS_SECRET_ACCESS_KEY
5253
valueFrom:
5354
secretKeyRef:
5455
name: {{ .Values.awsSecretName }}
55-
key: aws_secret_access_key
56+
key: {{ .Values.awsSecretKeys.secretAccessKey }}
57+
{{- end }}
58+
{{- with .Values.extraEnv }}
59+
{{- toYaml . | nindent 12 }}
60+
{{- end }}
5661
{{- end }}
5762
args:
5863
- --config=/.k8s-image-swapper.yaml
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{{ range .Values.extraManifests }}
2+
{{- if eq "string" ( kindOf . ) }}
3+
{{/* If manifest is a string, convert it back and forth from yaml to ensure good syntax */}}
4+
{{- . | fromYaml | toYaml }}
5+
{{- else }}
6+
{{- . | toYaml }}
7+
{{- end }}
8+
---
9+
{{ end }}
10+
11+
{{ range .Values.extraManifestsTemplated }}
12+
{{- if eq "string" ( kindOf . ) }}
13+
{{- tpl . $ }}
14+
{{- else }}
15+
{{- tpl ( . | toYaml ) $ }}
16+
{{- end }}
17+
---
18+
{{ end }}

charts/k8s-image-swapper/values.schema.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
}
2323
}
2424
},
25+
"awsSecretKeys": {
26+
"type": "object",
27+
"additionalProperties": false,
28+
"description": "Specify which keys to pull from the .awsSecretName secret for the associated environment variables.",
29+
"properties": {
30+
"accessKeyID": {
31+
"type": "string",
32+
"default": "aws_access_key_id"
33+
},
34+
"secretAccessKey": {
35+
"type": "string",
36+
"default": "aws_secret_access_key"
37+
}
38+
}
39+
},
2540
"awsSecretName": {
2641
"type": "string"
2742
},
@@ -104,6 +119,36 @@
104119
}
105120
}
106121
},
122+
"extraEnv": {
123+
"type": "array",
124+
"items": {}
125+
},
126+
"extraManifests": {
127+
"type": "array",
128+
"items": {
129+
"anyOf": [
130+
{
131+
"type": "object"
132+
},
133+
{
134+
"type": "string"
135+
}
136+
]
137+
}
138+
},
139+
"extraManifestsTemplated": {
140+
"type": "array",
141+
"items": {
142+
"anyOf": [
143+
{
144+
"type": "object"
145+
},
146+
{
147+
"type": "string"
148+
}
149+
]
150+
}
151+
},
107152
"fullnameOverride": {
108153
"type": "string"
109154
},

charts/k8s-image-swapper/values.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ podSecurityPolicy:
4444

4545
podAnnotations: {}
4646

47-
podSecurityContext: {}
47+
podSecurityContext:
48+
{}
4849
# fsGroup: 2000
4950

50-
securityContext: {}
51+
securityContext:
52+
{}
5153
# capabilities:
5254
# drop:
5355
# - ALL
@@ -59,7 +61,8 @@ service:
5961
type: ClusterIP
6062
port: 443
6163

62-
resources: {}
64+
resources:
65+
{}
6366
# We usually recommend not to specify default resources and to leave this as a conscious
6467
# choice for the user. This also increases chances charts run on environments with little
6568
# resources, such as Minikube. If you do want to specify resources, uncomment the following
@@ -112,7 +115,14 @@ webhook:
112115
namespaceSelector: {}
113116
objectSelector: {}
114117

118+
# -- If set, the secret will be used as environment variables, see awsSecretKeys.
115119
awsSecretName: ""
120+
# -- Specify which keys to pull from the .awsSecretName secret for the associated environment variables.
121+
awsSecretKeys:
122+
# -- If using Hashicorp Vault Operator w/ AWS engine, use `access_key`
123+
accessKeyID: "aws_access_key_id"
124+
# -- If using Hashicorp Vault Operator w/ AWS engine, use `secret_key`
125+
secretAccessKey: "aws_secret_access_key"
116126

117127
# Private registries are supported via imagePullSecrets on Pods and ServiceAccounts.
118128
# k8s-image-swapper requires to read the secret containing the docker authentication details
@@ -144,3 +154,20 @@ config:
144154
dev:
145155
enabled: false
146156
webhookURL: https://xxx.ngrok.io
157+
158+
# -- Additional environment variables to be defined on the container
159+
# Follows the same syntax as containers.env in a Pod v1 API
160+
extraEnv: []
161+
162+
# -- Additional manifests to be deployed
163+
# Can be either a full object OR a string containing valid YAML
164+
extraManifests: []
165+
166+
# -- Additional manifests to be deployed. These will be passed through the templating engine
167+
# Useful if you need to use values from this chart in your manifests
168+
extraManifestsTemplated: []
169+
# - kind: ConfigMap
170+
# metadata:
171+
# name: "{{ .Release.Name }}-extra-config"
172+
# data:
173+
# key: value

0 commit comments

Comments
 (0)