mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-14 10:32:22 +08:00
Fixing label values of workflow names with spaces (#125)
This commit is contained in:
parent
0bdc00d5b0
commit
e159999d64
@ -327,8 +327,8 @@ test("deployment - deploy() - Annotate & label resources", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("deployment - deploy() - Annotate & label resources for a new workflow", async () => {
|
test("deployment - deploy() - Annotate & label resources for a new workflow", async () => {
|
||||||
process.env.GITHUB_WORKFLOW = '.github/workflows/NewWorkflow.yml';
|
process.env.GITHUB_WORKFLOW = '.github/workflows/New Workflow.yml';
|
||||||
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('NA', '.github/workflows/NewWorkflow.yml');
|
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('NA', '.github/workflows/New Workflow.yml');
|
||||||
const KubernetesManifestUtilityMock = mocked(KubernetesManifestUtility, true);
|
const KubernetesManifestUtilityMock = mocked(KubernetesManifestUtility, true);
|
||||||
KubernetesManifestUtilityMock.checkManifestStability = jest.fn().mockReturnValue("");
|
KubernetesManifestUtilityMock.checkManifestStability = jest.fn().mockReturnValue("");
|
||||||
const KubernetesObjectUtilityMock = mocked(KubernetesObjectUtility, true);
|
const KubernetesObjectUtilityMock = mocked(KubernetesObjectUtility, true);
|
||||||
@ -352,7 +352,7 @@ test("deployment - deploy() - Annotate & label resources for a new workflow", as
|
|||||||
expect(kubeCtl.annotateFiles).toBeCalledWith(["manifests/deployment.yaml"], annotationKeyValStr);
|
expect(kubeCtl.annotateFiles).toBeCalledWith(["manifests/deployment.yaml"], annotationKeyValStr);
|
||||||
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
||||||
expect(kubeCtl.labelFiles).toBeCalledWith(["manifests/deployment.yaml"],
|
expect(kubeCtl.labelFiles).toBeCalledWith(["manifests/deployment.yaml"],
|
||||||
[`workflowFriendlyName=NewWorkflow.yml`, `workflow=${getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW)}`]);
|
[`workflowFriendlyName=New_Workflow.yml`, `workflow=${getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW)}`]);
|
||||||
readFileSpy.mockRestore();
|
readFileSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -154,10 +154,7 @@ function annotateResources(files, kubectl, resourceTypes, allPods, annotationKey
|
|||||||
utility_1.checkForErrors(annotateResults, true);
|
utility_1.checkForErrors(annotateResults, true);
|
||||||
}
|
}
|
||||||
function labelResources(files, kubectl, label) {
|
function labelResources(files, kubectl, label) {
|
||||||
let workflowName = process.env.GITHUB_WORKFLOW;
|
const labels = [`workflowFriendlyName=${utility_1.normaliseWorkflowStrLabel(process.env.GITHUB_WORKFLOW)}`, `workflow=${label}`];
|
||||||
workflowName = workflowName.startsWith('.github/workflows/') ?
|
|
||||||
workflowName.replace(".github/workflows/", "") : workflowName;
|
|
||||||
const labels = [`workflowFriendlyName=${workflowName}`, `workflow=${label}`];
|
|
||||||
utility_1.checkForErrors([kubectl.labelFiles(files, labels)], true);
|
utility_1.checkForErrors([kubectl.labelFiles(files, labels)], true);
|
||||||
}
|
}
|
||||||
function isCanaryDeploymentStrategy(deploymentStrategy) {
|
function isCanaryDeploymentStrategy(deploymentStrategy) {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.resolveGlobPatterns = exports.getCurrentTime = exports.getRandomInt = exports.sleep = exports.annotateChildPods = exports.getWorkflowFilePath = exports.getLastSuccessfulRunSha = exports.checkForErrors = exports.isEqual = exports.getExecutableExtension = void 0;
|
exports.resolveGlobPatterns = exports.getCurrentTime = exports.getRandomInt = exports.sleep = exports.normaliseWorkflowStrLabel = exports.annotateChildPods = exports.getWorkflowFilePath = exports.getLastSuccessfulRunSha = exports.checkForErrors = exports.isEqual = exports.getExecutableExtension = void 0;
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const glob = require("glob");
|
const glob = require("glob");
|
||||||
@ -139,6 +139,12 @@ function annotateChildPods(kubectl, resourceType, resourceName, annotationKeyVal
|
|||||||
return commandExecutionResults;
|
return commandExecutionResults;
|
||||||
}
|
}
|
||||||
exports.annotateChildPods = annotateChildPods;
|
exports.annotateChildPods = annotateChildPods;
|
||||||
|
function normaliseWorkflowStrLabel(workflowName) {
|
||||||
|
workflowName = workflowName.startsWith('.github/workflows/') ?
|
||||||
|
workflowName.replace(".github/workflows/", "") : workflowName;
|
||||||
|
return workflowName.replace(/ /g, "_");
|
||||||
|
}
|
||||||
|
exports.normaliseWorkflowStrLabel = normaliseWorkflowStrLabel;
|
||||||
function sleep(timeout) {
|
function sleep(timeout) {
|
||||||
return new Promise(resolve => setTimeout(resolve, timeout));
|
return new Promise(resolve => setTimeout(resolve, timeout));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { IExecSyncResult } from '../../utilities/tool-runner';
|
|||||||
|
|
||||||
import { deployPodCanary } from './pod-canary-deployment-helper';
|
import { deployPodCanary } from './pod-canary-deployment-helper';
|
||||||
import { deploySMICanary } from './smi-canary-deployment-helper';
|
import { deploySMICanary } from './smi-canary-deployment-helper';
|
||||||
import { checkForErrors, annotateChildPods, getWorkflowFilePath, getLastSuccessfulRunSha } from "../utility";
|
import { checkForErrors, annotateChildPods, getWorkflowFilePath, getLastSuccessfulRunSha, normaliseWorkflowStrLabel } from "../utility";
|
||||||
import { isBlueGreenDeploymentStrategy, isIngressRoute, isSMIRoute, routeBlueGreen } from './blue-green-helper';
|
import { isBlueGreenDeploymentStrategy, isIngressRoute, isSMIRoute, routeBlueGreen } from './blue-green-helper';
|
||||||
import { deployBlueGreenService } from './service-blue-green-helper';
|
import { deployBlueGreenService } from './service-blue-green-helper';
|
||||||
import { deployBlueGreenIngress } from './ingress-blue-green-helper';
|
import { deployBlueGreenIngress } from './ingress-blue-green-helper';
|
||||||
@ -151,10 +151,7 @@ function annotateResources(files: string[], kubectl: Kubectl, resourceTypes: Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
function labelResources(files: string[], kubectl: Kubectl, label: string) {
|
function labelResources(files: string[], kubectl: Kubectl, label: string) {
|
||||||
let workflowName = process.env.GITHUB_WORKFLOW;
|
const labels = [`workflowFriendlyName=${normaliseWorkflowStrLabel(process.env.GITHUB_WORKFLOW)}`, `workflow=${label}`];
|
||||||
workflowName = workflowName.startsWith('.github/workflows/') ?
|
|
||||||
workflowName.replace(".github/workflows/", "") : workflowName;
|
|
||||||
const labels = [`workflowFriendlyName=${workflowName}`, `workflow=${label}`];
|
|
||||||
checkForErrors([kubectl.labelFiles(files, labels)], true);
|
checkForErrors([kubectl.labelFiles(files, labels)], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -130,6 +130,12 @@ export function annotateChildPods(kubectl: Kubectl, resourceType: string, resour
|
|||||||
return commandExecutionResults;
|
return commandExecutionResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normaliseWorkflowStrLabel(workflowName: string): string {
|
||||||
|
workflowName = workflowName.startsWith('.github/workflows/') ?
|
||||||
|
workflowName.replace(".github/workflows/", "") : workflowName;
|
||||||
|
return workflowName.replace(/ /g, "_");
|
||||||
|
}
|
||||||
|
|
||||||
export function sleep(timeout: number) {
|
export function sleep(timeout: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, timeout));
|
return new Promise(resolve => setTimeout(resolve, timeout));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user