Skip to content

Commit 5b8e166

Browse files
committed
test: verify pod spec exists in metadata payload
1 parent c643399 commit 5b8e166

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

test/fixtures/pod-spec.json

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"containers": [
3+
{
4+
"env": [
5+
{
6+
"name": "SNYK_INTEGRATION_ID",
7+
"valueFrom": {
8+
"secretKeyRef": {
9+
"key": "integrationId",
10+
"name": "snyk-monitor"
11+
}
12+
}
13+
},
14+
{
15+
"name": "SNYK_NAMESPACE"
16+
},
17+
{
18+
"name": "SNYK_INTEGRATION_API"
19+
},
20+
{
21+
"name": "SNYK_CLUSTER_NAME",
22+
"value": "Production cluster"
23+
},
24+
{
25+
"name": "SNYK_STATIC_ANALYSIS",
26+
"value": "true"
27+
}
28+
],
29+
"image": "snyk/kubernetes-monitor:1.8.5",
30+
"imagePullPolicy": "Always",
31+
"name": "snyk-monitor",
32+
"resources": {
33+
"limits": {
34+
"cpu": "1",
35+
"memory": "2Gi"
36+
},
37+
"requests": {
38+
"cpu": "250m",
39+
"memory": "400Mi"
40+
}
41+
},
42+
"terminationMessagePath": "/dev/termination-log",
43+
"terminationMessagePolicy": "File",
44+
"volumeMounts": [
45+
{
46+
"mountPath": "/root/.docker",
47+
"name": "docker-config",
48+
"readOnly": true
49+
},
50+
{
51+
"mountPath": "/snyk-monitor",
52+
"name": "temporary-storage"
53+
},
54+
{
55+
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
56+
"name": "snyk-monitor-token-ncps2",
57+
"readOnly": true
58+
}
59+
]
60+
}
61+
],
62+
"dnsPolicy": "ClusterFirst",
63+
"enableServiceLinks": true,
64+
"nodeName": "gke-test-node-123456",
65+
"priority": 0,
66+
"restartPolicy": "Always",
67+
"schedulerName": "default-scheduler",
68+
"securityContext": {},
69+
"serviceAccount": "snyk-monitor",
70+
"serviceAccountName": "snyk-monitor",
71+
"terminationGracePeriodSeconds": 30,
72+
"tolerations": [
73+
{
74+
"effect": "NoExecute",
75+
"key": "node.kubernetes.io/not-ready",
76+
"operator": "Exists",
77+
"tolerationSeconds": 300
78+
},
79+
{
80+
"effect": "NoExecute",
81+
"key": "node.kubernetes.io/unreachable",
82+
"operator": "Exists",
83+
"tolerationSeconds": 300
84+
}
85+
],
86+
"volumes": [
87+
{
88+
"name": "docker-config",
89+
"secret": {
90+
"defaultMode": 420,
91+
"items": [
92+
{
93+
"key": "dockercfg.json",
94+
"path": "config.json"
95+
}
96+
],
97+
"secretName": "snyk-monitor"
98+
}
99+
},
100+
{
101+
"emptyDir": {
102+
"sizeLimit": "50Gi"
103+
},
104+
"name": "temporary-storage"
105+
},
106+
{
107+
"name": "snyk-monitor-token-test",
108+
"secret": {
109+
"defaultMode": 420,
110+
"secretName": "snyk-monitor-token-test"
111+
}
112+
}
113+
]
114+
}

test/integration/kubernetes.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ tap.test('snyk-monitor sends data to homebase', async (t) => {
8787

8888
const metaValidator: WorkloadMetadataValidator = (workloadInfo) => {
8989
return workloadInfo !== undefined && 'revision' in workloadInfo && 'labels' in workloadInfo &&
90-
'specLabels' in workloadInfo && 'annotations' in workloadInfo && 'specAnnotations' in workloadInfo;
90+
'specLabels' in workloadInfo && 'annotations' in workloadInfo && 'specAnnotations' in workloadInfo &&
91+
'podSpec' in workloadInfo;
9192
};
9293

9394
// We don't want to spam Homebase with requests; do it infrequently

test/unit/transmitter-payload.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as tap from 'tap';
33
import imageScanner = require('../../src/kube-scanner/image-scanner');
44
import payload = require('../../src/transmitter/payload');
55
import transmitterTypes = require('../../src/transmitter/types');
6+
const podSpecFixture = require('../fixtures/pod-spec.json');
67

78
tap.test('constructHomebaseDepGraphPayloads breaks when workloadMetadata is missing items', async (t) => {
89
const scannedImages: imageScanner.IScanResult[] = [
@@ -33,6 +34,7 @@ tap.test('constructHomebaseDepGraphPayloads breaks when workloadMetadata is miss
3334
imageId: 'does this matter?',
3435
cluster: 'grapefruit',
3536
revision: undefined,
37+
podSpec: podSpecFixture,
3638
},
3739
];
3840

@@ -64,6 +66,7 @@ tap.test('constructHomebaseDepGraphPayloads happy flow', async (t) => {
6466
imageId: 'does this matter?',
6567
cluster: 'grapefruit',
6668
revision: 1,
69+
podSpec: podSpecFixture,
6770
},
6871
];
6972

@@ -92,6 +95,7 @@ tap.test('constructHomebaseWorkloadMetadataPayload happy flow', async (t) => {
9295
imageId: 'does this matter?',
9396
cluster: 'grapefruit',
9497
revision: 1,
98+
podSpec: podSpecFixture,
9599
};
96100

97101
const workloadMetadataPayload = payload.constructHomebaseWorkloadMetadataPayload(workloadWithImages);
@@ -101,6 +105,11 @@ tap.test('constructHomebaseWorkloadMetadataPayload happy flow', async (t) => {
101105
t.equals(workloadMetadataPayload.workloadLocator.name, 'workloadName', 'workload name present in payload');
102106
t.equals(workloadMetadataPayload.workloadLocator.type, 'type', 'workload type present in payload');
103107
t.equals(workloadMetadataPayload.workloadMetadata.revision, 1, 'revision present in metadata');
108+
t.ok('podSpec' in workloadMetadataPayload.workloadMetadata, 'podSpec present in metadata');
109+
t.equals(workloadMetadataPayload.workloadMetadata.podSpec.containers[0].resources!.limits!.memory!, '2Gi',
110+
'memory limit present in metadata');
111+
t.equals(workloadMetadataPayload.workloadMetadata.podSpec.serviceAccountName, 'snyk-monitor',
112+
'service account name present in metadata');
104113
t.ok('annotations' in workloadMetadataPayload.workloadMetadata, 'annotations present in metadata');
105114
t.ok('specAnnotations' in workloadMetadataPayload.workloadMetadata, 'specAnnotations present in metadata');
106115
t.ok('labels' in workloadMetadataPayload.workloadMetadata, 'labels present in metadata');

0 commit comments

Comments
 (0)