Skip to content

Commit cc28069

Browse files
authored
Merge pull request #735 from snyk/feat/helm-annotations
feat: Allow passing arbitrary annotations to ServiceAccount with Helm
2 parents 691dc78 + 0cd07fb commit cc28069

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

snyk-monitor/templates/serviceaccount.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ metadata:
77
helm.sh/chart: {{ include "snyk-monitor.chart" . }}
88
app.kubernetes.io/instance: {{ .Release.Name }}
99
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
{{- with .Values.rbac.serviceAccount.annotations }}
11+
annotations:
12+
{{ toYaml . | nindent 4 }}
13+
{{- end }}

snyk-monitor/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ pvc:
5252
##
5353
# storageClassName: "-"
5454

55+
# Additional annotations for the Kubernetes ServiceAccount
56+
rbac:
57+
serviceAccount:
58+
annotations: {}
59+
5560
# Node.js in-container process memory enhancements
5661
envs:
5762
- name: V8_MAX_OLD_SPACE_SIZE

test/helpers/kubectl.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { execWrapper as exec } from './exec';
21
import { chmodSync, writeFileSync, existsSync, unlinkSync } from 'fs';
32
import { platform } from 'os';
43
import { resolve } from 'path';
54
import * as needle from 'needle';
65
import * as sleep from 'sleep-promise';
6+
import type { V1ServiceAccount } from '@kubernetes/client-node';
7+
8+
import { execWrapper as exec } from './exec';
79

810
/**
911
* @param version For example: "v1.18.0"
@@ -191,6 +193,16 @@ export async function getDeploymentJson(
191193
return JSON.parse(getDeploymentResult.stdout);
192194
}
193195

196+
export async function getServiceAccountJson(
197+
name: string,
198+
namespace: string,
199+
): Promise<V1ServiceAccount> {
200+
const getDeploymentResult = await exec(
201+
`./kubectl get serviceaccount ${name} -n ${namespace} -o json`,
202+
);
203+
return JSON.parse(getDeploymentResult.stdout);
204+
}
205+
194206
export async function getPodNames(namespace: string): Promise<string[]> {
195207
const commandPrefix = `./kubectl -n ${namespace} get pods`;
196208
const onlyNames =

test/integration/kubernetes.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,25 @@ test('snyk-monitor has log level', async () => {
576576
expect(logLevel.value).toBeTruthy();
577577
});
578578

579+
test('service account has annotations that were set on deployment', async () => {
580+
if (process.env.DEPLOYMENT_TYPE !== 'Helm') {
581+
console.log(
582+
"Not testing annotations existence because we're not installing with Helm",
583+
);
584+
return;
585+
}
586+
587+
const snykMonitorServiceAccount = await kubectl.getServiceAccountJson(
588+
'snyk-monitor',
589+
namespace,
590+
);
591+
expect(snykMonitorServiceAccount.metadata?.annotations).toEqual(
592+
expect.objectContaining({
593+
foo: 'bar',
594+
}),
595+
);
596+
});
597+
579598
test('snyk-monitor has nodeSelector', async () => {
580599
if (process.env['DEPLOYMENT_TYPE'] !== 'Helm') {
581600
console.log(

test/setup/deployers/helm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ async function deployKubernetesMonitor(
3434
'--set psp.enabled=true ' +
3535
'--set pvc.enabled=true ' +
3636
'--set pvc.create=true ' +
37-
'--set log_level="INFO"',
37+
'--set log_level="INFO" ' +
38+
'--set rbac.serviceAccount.annotations."foo"="bar"',
3839
);
3940
console.log(
4041
`Deployed ${imageOptions.nameAndTag} with pull policy ${imageOptions.pullPolicy}`,

0 commit comments

Comments
 (0)