Skip to content

Commit ae735a2

Browse files
committed
chore: YAML installation is more robust by using find()
Instead of using array indices, use find to locate the element we want to override in the YAML. This ensures that if array entries change position, the code still works.
1 parent ae84f0f commit ae735a2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

test/setup/deployers/yaml.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ function createTestYamlDeployment(
3434
);
3535
const deployment = parse(originalDeploymentYaml);
3636

37-
deployment.spec.template.spec.containers[0].image = imageNameAndTag;
38-
deployment.spec.template.spec.containers[0].imagePullPolicy = imagePullPolicy;
37+
const container = deployment.spec.template.spec.containers.find(
38+
(container) => container.name === 'snyk-monitor',
39+
);
40+
container.image = imageNameAndTag;
41+
container.imagePullPolicy = imagePullPolicy;
3942

4043
// Inject the baseUrl of kubernetes-upstream that snyk-monitor container use to send metadata
41-
deployment.spec.template.spec.containers[0].env[2] = {
42-
name: 'SNYK_INTEGRATION_API',
43-
value: 'https://kubernetes-upstream.dev.snyk.io',
44-
};
44+
const envVar = container.env.find(
45+
(env) => env.name === 'SNYK_INTEGRATION_API',
46+
);
47+
envVar.value = 'https://kubernetes-upstream.dev.snyk.io';
48+
delete envVar.valueFrom;
4549

4650
writeFileSync(newYamlPath, stringify(deployment));
4751
console.log('Created YAML snyk-monitor deployment');

0 commit comments

Comments
 (0)