Skip to content

Commit 8dfe460

Browse files
authored
Merge pull request #997 from snyk/fix/cronjob
[RUN-1518] Test cronjobs only if supported
2 parents fcdeb61 + fdb0cb0 commit 8dfe460

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

test/helpers/kubernetes-upstream.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export async function validateUpstreamStoredScanResults(
3131
remainingChecks: number = UPSTREAM_POLLING_CONFIGURATION.MAXIMUM_REQUESTS,
3232
): Promise<boolean> {
3333
while (remainingChecks > 0) {
34-
console.log(
35-
`Pinging upstream for existing data (${remainingChecks} checks remaining)...`,
36-
);
34+
if (remainingChecks % 10 === 0) {
35+
console.log(
36+
`Pinging upstream for existing data (${remainingChecks} checks remaining)...`,
37+
);
38+
}
3739
const responseBody = await getUpstreamResponseBody(relativeUrl);
3840
const depGraphs = responseBody?.workloadScanResults;
3941
const result = validatorFn(depGraphs);
@@ -52,9 +54,11 @@ export async function validateUpstreamStoredData(
5254
remainingChecks: number = UPSTREAM_POLLING_CONFIGURATION.MAXIMUM_REQUESTS,
5355
): Promise<boolean> {
5456
while (remainingChecks > 0) {
55-
console.log(
56-
`Pinging upstream for existing data (${remainingChecks} checks remaining)...`,
57-
);
57+
if (remainingChecks % 10 === 0) {
58+
console.log(
59+
`Pinging upstream for existing data (${remainingChecks} checks remaining)...`,
60+
);
61+
}
5862
const responseBody = await getUpstreamResponseBody(relativeUrl);
5963
const workloads: IWorkloadLocator[] | undefined = responseBody.workloads;
6064
const result = validatorFn(workloads);

test/integration/kubernetes.spec.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const cronJobV1Beta1Validator = (workloads: IWorkloadLocator[]) =>
5151
workload.type === WorkloadKind.CronJob,
5252
) !== undefined;
5353

54+
let cronJobV1Supported = true;
55+
let cronJobV1Beta1Supported = true;
5456
// Next we apply some sample workloads
5557
test('deploy sample workloads', async () => {
5658
const servicesNamespace = 'services';
@@ -66,11 +68,13 @@ test('deploy sample workloads', async () => {
6668
kubectl.applyK8sYaml('./test/fixtures/consul-deployment.yaml'),
6769
kubectl.applyK8sYaml('./test/fixtures/cronjob.yaml').catch((error) => {
6870
console.log('CronJob is possibly unsupported', error);
71+
cronJobV1Supported = false;
6972
}),
7073
kubectl
7174
.applyK8sYaml('./test/fixtures/cronjob-v1beta1.yaml')
7275
.catch((error) => {
7376
console.log('CronJobV1Beta1 is possibly unsupported', error);
77+
cronJobV1Beta1Supported = false;
7478
}),
7579
kubectl.createPodFromImage(
7680
'alpine-from-sha',
@@ -250,32 +254,35 @@ test('snyk-monitor sends data to kubernetes-upstream', async () => {
250254
},
251255
]);
252256

253-
const scanResultsCronJob = await getUpstreamResponseBody(
254-
`api/v1/scan-results/${integrationId}/Default%20cluster/services/CronJob/cron-job`,
255-
);
256-
expect(scanResultsCronJob.workloadScanResults['busybox']).toEqual<
257-
ScanResult[]
258-
>([
259-
{
260-
identity: { type: 'linux', args: { platform: 'linux/amd64' } },
261-
facts: expect.any(Array),
262-
target: { image: 'docker-image|busybox' },
263-
},
264-
]);
257+
if (cronJobV1Beta1Supported) {
258+
const scanResultsCronJobBeta = await getUpstreamResponseBody(
259+
`api/v1/scan-results/${integrationId}/Default%20cluster/services/CronJob/cron-job-v1beta1`,
260+
);
261+
expect(scanResultsCronJobBeta.workloadScanResults['busybox']).toEqual<
262+
ScanResult[]
263+
>([
264+
{
265+
identity: { type: 'linux', args: { platform: 'linux/amd64' } },
266+
facts: expect.any(Array),
267+
target: { image: 'docker-image|busybox' },
268+
},
269+
]);
270+
}
265271

266-
// the v1 reader works for both v1 and v1beta1
267-
const scanResultsCronJobBeta = await getUpstreamResponseBody(
268-
`api/v1/scan-results/${integrationId}/Default%20cluster/services/CronJob/cron-job-v1beta1`,
269-
);
270-
expect(scanResultsCronJobBeta.workloadScanResults['busybox']).toEqual<
271-
ScanResult[]
272-
>([
273-
{
274-
identity: { type: 'linux', args: { platform: 'linux/amd64' } },
275-
facts: expect.any(Array),
276-
target: { image: 'docker-image|busybox' },
277-
},
278-
]);
272+
if (cronJobV1Supported) {
273+
const scanResultsCronJob = await getUpstreamResponseBody(
274+
`api/v1/scan-results/${integrationId}/Default%20cluster/services/CronJob/cron-job`,
275+
);
276+
expect(scanResultsCronJob.workloadScanResults['busybox']).toEqual<
277+
ScanResult[]
278+
>([
279+
{
280+
identity: { type: 'linux', args: { platform: 'linux/amd64' } },
281+
facts: expect.any(Array),
282+
target: { image: 'docker-image|busybox' },
283+
},
284+
]);
285+
}
279286
});
280287

281288
test('snyk-monitor sends binary hashes to kubernetes-upstream after adding another deployment', async () => {

0 commit comments

Comments
 (0)