mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-14 18:42:20 +08:00
WokflowFileName added in annotations for View All Runs in UX
This commit is contained in:
parent
65e1224846
commit
f9acc4f772
@ -293,7 +293,7 @@ test("deployment - deploy() - deploy force flag on", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("deployment - deploy() - Annotate & label resources", async () => {
|
test("deployment - deploy() - Annotate & label resources", async () => {
|
||||||
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('currentCommit');
|
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('currentCommit', '.github/workflows/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);
|
||||||
@ -320,8 +320,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 = 'NewWorkflow';
|
process.env.GITHUB_WORKFLOW = '.github/workflows/NewWorkflow.yml';
|
||||||
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('NA');
|
let annotationKeyValStr = getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW) + '=' + getWorkflowAnnotationsJson('NA', '.github/workflows/NewWorkflow.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);
|
||||||
@ -344,7 +344,7 @@ test("deployment - deploy() - Annotate & label resources for a new workflow", as
|
|||||||
expect(kubeCtl.annotateFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"], annotationKeyValStr);
|
expect(kubeCtl.annotateFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"], annotationKeyValStr);
|
||||||
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
expect(kubeCtl.annotate).toBeCalledTimes(2);
|
||||||
expect(kubeCtl.labelFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"],
|
expect(kubeCtl.labelFiles).toBeCalledWith(["~/Deployment_testapp_currentTimestamp"],
|
||||||
[`workflowFriendlyName=${process.env.GITHUB_WORKFLOW}`, `workflow=${getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW)}`]);
|
[`workflowFriendlyName=NewWorkflow.yml`, `workflow=${getWorkflowAnnotationKeyLabel(process.env.GITHUB_WORKFLOW)}`]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("deployment - deploy() - Annotate resources failed", async () => {
|
test("deployment - deploy() - Annotate resources failed", async () => {
|
||||||
|
|||||||
@ -25,11 +25,12 @@ ServiceTypes.clusterIP = 'ClusterIP';
|
|||||||
exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset'];
|
exports.deploymentTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset'];
|
||||||
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
exports.workloadTypes = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
||||||
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
|
exports.workloadTypesWithRolloutStatus = ['deployment', 'daemonset', 'statefulset'];
|
||||||
function getWorkflowAnnotationsJson(lastSuccessRunSha) {
|
function getWorkflowAnnotationsJson(lastSuccessRunSha, workflowFilePath) {
|
||||||
return `{`
|
return `{`
|
||||||
+ `'run': '${process.env.GITHUB_RUN_ID}',`
|
+ `'run': '${process.env.GITHUB_RUN_ID}',`
|
||||||
+ `'repository': '${process.env.GITHUB_REPOSITORY}',`
|
+ `'repository': '${process.env.GITHUB_REPOSITORY}',`
|
||||||
+ `'workflow': '${process.env.GITHUB_WORKFLOW}',`
|
+ `'workflow': '${process.env.GITHUB_WORKFLOW}',`
|
||||||
|
+ `'workflowFileName': '${workflowFilePath.replace(".github/workflows/", "")}',`
|
||||||
+ `'jobName': '${process.env.GITHUB_JOB}',`
|
+ `'jobName': '${process.env.GITHUB_JOB}',`
|
||||||
+ `'createdBy': '${process.env.GITHUB_ACTOR}',`
|
+ `'createdBy': '${process.env.GITHUB_ACTOR}',`
|
||||||
+ `'runUri': 'https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}',`
|
+ `'runUri': 'https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}',`
|
||||||
|
|||||||
@ -114,14 +114,14 @@ function annotateAndLabelResources(files, kubectl, resourceTypes, allPods) {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const workflowFilePath = yield utility_1.getWorkflowFilePath(TaskInputParameters.githubToken);
|
const workflowFilePath = yield utility_1.getWorkflowFilePath(TaskInputParameters.githubToken);
|
||||||
const annotationKeyLabel = models.getWorkflowAnnotationKeyLabel(workflowFilePath);
|
const annotationKeyLabel = models.getWorkflowAnnotationKeyLabel(workflowFilePath);
|
||||||
annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel);
|
annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath);
|
||||||
labelResources(files, kubectl, annotationKeyLabel);
|
labelResources(files, kubectl, annotationKeyLabel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function annotateResources(files, kubectl, resourceTypes, allPods, annotationKey) {
|
function annotateResources(files, kubectl, resourceTypes, allPods, annotationKey, workflowFilePath) {
|
||||||
const annotateResults = [];
|
const annotateResults = [];
|
||||||
const lastSuccessSha = utility_1.getLastSuccessfulRunSha(kubectl, TaskInputParameters.namespace, annotationKey);
|
const lastSuccessSha = utility_1.getLastSuccessfulRunSha(kubectl, TaskInputParameters.namespace, annotationKey);
|
||||||
let annotationKeyValStr = annotationKey + '=' + models.getWorkflowAnnotationsJson(lastSuccessSha);
|
let annotationKeyValStr = annotationKey + '=' + models.getWorkflowAnnotationsJson(lastSuccessSha, workflowFilePath);
|
||||||
annotateResults.push(kubectl.annotate('namespace', TaskInputParameters.namespace, annotationKeyValStr));
|
annotateResults.push(kubectl.annotate('namespace', TaskInputParameters.namespace, annotationKeyValStr));
|
||||||
annotateResults.push(kubectl.annotateFiles(files, annotationKeyValStr));
|
annotateResults.push(kubectl.annotateFiles(files, annotationKeyValStr));
|
||||||
resourceTypes.forEach(resource => {
|
resourceTypes.forEach(resource => {
|
||||||
|
|||||||
@ -25,11 +25,12 @@ export const deploymentTypes: string[] = ['deployment', 'replicaset', 'daemonset
|
|||||||
export const workloadTypes: string[] = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
export const workloadTypes: string[] = ['deployment', 'replicaset', 'daemonset', 'pod', 'statefulset', 'job', 'cronjob'];
|
||||||
export const workloadTypesWithRolloutStatus: string[] = ['deployment', 'daemonset', 'statefulset'];
|
export const workloadTypesWithRolloutStatus: string[] = ['deployment', 'daemonset', 'statefulset'];
|
||||||
|
|
||||||
export function getWorkflowAnnotationsJson(lastSuccessRunSha: string): string {
|
export function getWorkflowAnnotationsJson(lastSuccessRunSha: string, workflowFilePath: string): string {
|
||||||
return `{`
|
return `{`
|
||||||
+ `'run': '${process.env.GITHUB_RUN_ID}',`
|
+ `'run': '${process.env.GITHUB_RUN_ID}',`
|
||||||
+ `'repository': '${process.env.GITHUB_REPOSITORY}',`
|
+ `'repository': '${process.env.GITHUB_REPOSITORY}',`
|
||||||
+ `'workflow': '${process.env.GITHUB_WORKFLOW}',`
|
+ `'workflow': '${process.env.GITHUB_WORKFLOW}',`
|
||||||
|
+ `'workflowFileName': '${workflowFilePath.replace(".github/workflows/", "")}',`
|
||||||
+ `'jobName': '${process.env.GITHUB_JOB}',`
|
+ `'jobName': '${process.env.GITHUB_JOB}',`
|
||||||
+ `'createdBy': '${process.env.GITHUB_ACTOR}',`
|
+ `'createdBy': '${process.env.GITHUB_ACTOR}',`
|
||||||
+ `'runUri': 'https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}',`
|
+ `'runUri': 'https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}',`
|
||||||
|
|||||||
@ -115,14 +115,14 @@ async function checkManifestStability(kubectl: Kubectl, resources: Resource[]):
|
|||||||
async function annotateAndLabelResources(files: string[], kubectl: Kubectl, resourceTypes: Resource[], allPods: any) {
|
async function annotateAndLabelResources(files: string[], kubectl: Kubectl, resourceTypes: Resource[], allPods: any) {
|
||||||
const workflowFilePath = await getWorkflowFilePath(TaskInputParameters.githubToken);
|
const workflowFilePath = await getWorkflowFilePath(TaskInputParameters.githubToken);
|
||||||
const annotationKeyLabel = models.getWorkflowAnnotationKeyLabel(workflowFilePath);
|
const annotationKeyLabel = models.getWorkflowAnnotationKeyLabel(workflowFilePath);
|
||||||
annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel);
|
annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath);
|
||||||
labelResources(files, kubectl, annotationKeyLabel);
|
labelResources(files, kubectl, annotationKeyLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
function annotateResources(files: string[], kubectl: Kubectl, resourceTypes: Resource[], allPods: any, annotationKey: string) {
|
function annotateResources(files: string[], kubectl: Kubectl, resourceTypes: Resource[], allPods: any, annotationKey: string, workflowFilePath: string) {
|
||||||
const annotateResults: IExecSyncResult[] = [];
|
const annotateResults: IExecSyncResult[] = [];
|
||||||
const lastSuccessSha = getLastSuccessfulRunSha(kubectl, TaskInputParameters.namespace, annotationKey);
|
const lastSuccessSha = getLastSuccessfulRunSha(kubectl, TaskInputParameters.namespace, annotationKey);
|
||||||
let annotationKeyValStr = annotationKey + '=' + models.getWorkflowAnnotationsJson(lastSuccessSha);
|
let annotationKeyValStr = annotationKey + '=' + models.getWorkflowAnnotationsJson(lastSuccessSha, workflowFilePath);
|
||||||
annotateResults.push(kubectl.annotate('namespace', TaskInputParameters.namespace, annotationKeyValStr));
|
annotateResults.push(kubectl.annotate('namespace', TaskInputParameters.namespace, annotationKeyValStr));
|
||||||
annotateResults.push(kubectl.annotateFiles(files, annotationKeyValStr));
|
annotateResults.push(kubectl.annotateFiles(files, annotationKeyValStr));
|
||||||
resourceTypes.forEach(resource => {
|
resourceTypes.forEach(resource => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user