Skip to content

Commit

Permalink
chore(chaoscenter): Added node selector in chaos engine spec (#4365)
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Kumar Das <[email protected]>
  • Loading branch information
amityt authored Jan 3, 2024
1 parent 94680e8 commit 7a57192
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions chaoscenter/web/src/services/experiment/KubernetesYamlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,60 @@ export class KubernetesYamlService extends ExperimentYamlService {
delete spec?.nodeSelector;
}

const [templates] = this.getTemplatesAndSteps(experiment?.manifest as KubernetesExperimentManifest);

templates?.map(template => {
if (template.inputs?.artifacts?.[0]?.raw?.data) {
const chaosEngineCR = parse(template.inputs.artifacts[0].raw.data ?? '') as ChaosEngine;
if (chaosEngineCR.kind === 'ChaosEngine') {
const updatedEngineCR = this.updateNodeSelectorInChaosEngine(chaosEngineCR, nodeSelector, remove);
template.inputs.artifacts[0].raw.data = yamlStringify(updatedEngineCR);
}
}
});

await store.put({ ...experiment }, key);
await tx.done;
} catch (_) {
this.handleIDBFailure();
}
}

private updateNodeSelectorInChaosEngine(
manifest: ChaosEngine | undefined,
nodeSelector: {
key: string;
value: string;
},
remove: boolean
): ChaosEngine | undefined {
if (!manifest?.spec) return;

if (remove) {
if (manifest.spec?.components?.runner?.nodeSelector) {
delete manifest.spec?.components?.runner?.nodeSelector;
}
if (manifest.spec?.experiments[0].spec.components?.nodeSelector) {
delete manifest.spec.experiments[0].spec.components?.nodeSelector;
}
return manifest;
}

manifest.spec.components = {
...manifest.spec.components,
runner: {
...manifest.spec.components?.runner,
nodeSelector: { [nodeSelector.key]: nodeSelector.value }
}
};
manifest.spec.experiments[0].spec.components = {
...manifest.spec.experiments[0].spec.components,
nodeSelector: { [nodeSelector.key]: nodeSelector.value }
};

return manifest;
}

async updateToleration(
key: ChaosObjectStoresPrimaryKeys['experiments'],
toleration: WorkflowToleration,
Expand Down

0 comments on commit 7a57192

Please sign in to comment.