From c87f03e02b27626ceadc32c95ea11867c927bd16 Mon Sep 17 00:00:00 2001 From: christosarvanitis Date: Wed, 20 Nov 2024 15:40:11 +0200 Subject: [PATCH] feat(deployManifest): Adding Label Selectors feature support --- .../kubernetes/src/help/kubernetes.help.ts | 4 ++ .../DeployManifestStageForm.tsx | 55 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/packages/kubernetes/src/help/kubernetes.help.ts b/packages/kubernetes/src/help/kubernetes.help.ts index 3fc6ffd3beb..c89f9e6fc44 100644 --- a/packages/kubernetes/src/help/kubernetes.help.ts +++ b/packages/kubernetes/src/help/kubernetes.help.ts @@ -213,6 +213,10 @@ const helpContents: { [key: string]: string } = { '

Skip SpEL expression evaluation of the manifest artifact in this stage. Can be paired with the "Evaluate SpEL expressions in overrides at bake time" option in the Bake Manifest stage when baking a third-party manifest artifact with expressions not meant for Spinnaker to evaluate as SpEL.

', 'kubernetes.manifest.skipSpecTemplateLabels': `

Skip applying the Reserved labels to the manifest's .spec.template.metadata.labels.

`, + 'kubernetes.manifest.deployLabelSelectors': ` +

Via Label Selectors, Spinnaker can deploy a subset of manifests satisfying the Label Selectors. See Kubernetes Label Selectors for more details. Multiple selectors combine with AND (All must be satisfied).

`, + 'kubernetes.manifest.deployLabelSelectors.allowNothingSelected': ` +

When unchecked an error is thrown if none of the provided manifests satisfy the Label Selectors

`, 'kubernetes.manifest.undoRollout.revisionsBack': `

How many revisions to rollback from the current active revision. This is not a hard-coded revision to rollout.

For example: If you specify "1", and this stage executes, the prior revision will be active upon success.

diff --git a/packages/kubernetes/src/pipelines/stages/deployManifest/DeployManifestStageForm.tsx b/packages/kubernetes/src/pipelines/stages/deployManifest/DeployManifestStageForm.tsx index 30f0be9f723..805601cc4a3 100644 --- a/packages/kubernetes/src/pipelines/stages/deployManifest/DeployManifestStageForm.tsx +++ b/packages/kubernetes/src/pipelines/stages/deployManifest/DeployManifestStageForm.tsx @@ -25,15 +25,23 @@ import { ManifestBindArtifactsSelector } from './ManifestBindArtifactsSelector'; import { ManifestDeploymentOptions } from './ManifestDeploymentOptions'; import { NamespaceSelector } from './NamespaceSelector'; import { ManifestSource } from '../../../manifest/ManifestSource'; +import type { IManifestLabelSelector } from '../../../manifest/selector/IManifestLabelSelector'; +import type { IManifestSelector } from '../../../manifest/selector/IManifestSelector'; +import { SelectorMode } from '../../../manifest/selector/IManifestSelector'; +import LabelEditor from '../../../manifest/selector/labelEditor/LabelEditor'; import { ManifestBasicSettings } from '../../../manifest/wizard/BasicSettings'; interface IDeployManifestStageConfigFormProps { accounts: IAccountDetails[]; + selector?: IManifestSelector; + modes?: SelectorMode.Label; } interface IDeployManifestStageConfigFormState { rawManifest: string; overrideNamespace: boolean; + selector: IManifestSelector; + labelSelectors: IManifestLabelSelector[]; } export class DeployManifestStageForm extends React.Component< @@ -55,6 +63,13 @@ export class DeployManifestStageForm extends React.Component< this.state = { rawManifest: !isEmpty(manifests) && isTextManifest ? yamlDocumentsToString(manifests) : '', overrideNamespace: get(stage, 'namespaceOverride', '') !== '', + selector: { + account: '', + location: '', + mode: SelectorMode.Label, + labelSelectors: { selectors: [] }, + }, + labelSelectors: [], }; } @@ -194,6 +209,41 @@ export class DeployManifestStageForm extends React.Component< onChange={(e: any) => this.props.formik.setFieldValue('skipSpecTemplateLabels', e.target.checked)} /> + + + { + if (e.target.checked) { + this.props.formik.setFieldValue('labelSelectors', { selectors: [] }); + this.props.formik.setFieldValue('allowNothingSelected', false); + } else { + this.props.formik.setFieldValue('labelSelectors', null); + this.props.formik.setFieldValue('allowNothingSelected', null); + } + }} + /> + + {stage.labelSelectors && stage.labelSelectors.selectors && ( + <> + + + + + this.props.formik.setFieldValue('allowNothingSelected', e.target.checked)} + /> + + + )} +
); } + + private handleLabelSelectorsChange = (labelSelectors: IManifestLabelSelector[]): void => { + this.setState({ labelSelectors }); + this.props.formik.setFieldValue('labelSelectors.selectors', labelSelectors); + }; }