mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-24 05:29:26 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5782616d03 |
+28
-9
@@ -22017,12 +22017,20 @@ function checkManifestStability(kubectl, resources) {
|
|||||||
exports.checkManifestStability = checkManifestStability;
|
exports.checkManifestStability = checkManifestStability;
|
||||||
function annotateAndLabelResources(files, kubectl, resourceTypes, allPods) {
|
function annotateAndLabelResources(files, kubectl, resourceTypes, allPods) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation';
|
||||||
const githubToken = core.getInput('token');
|
const githubToken = core.getInput('token');
|
||||||
const workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
|
let workflowFilePath;
|
||||||
|
try {
|
||||||
|
workflowFilePath = yield githubUtils_1.getWorkflowFilePath(githubToken);
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
core.warning(`Failed to extract workflow file name: ${ex}`);
|
||||||
|
workflowFilePath = defaultWorkflowFileName;
|
||||||
|
}
|
||||||
const deploymentConfig = yield dockerUtils_1.getDeploymentConfig();
|
const deploymentConfig = yield dockerUtils_1.getDeploymentConfig();
|
||||||
const annotationKeyLabel = workflowAnnotationUtils_1.getWorkflowAnnotationKeyLabel();
|
const annotationKeyLabel = workflowAnnotationUtils_1.getWorkflowAnnotationKeyLabel();
|
||||||
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig);
|
yield annotateResources(files, kubectl, resourceTypes, allPods, annotationKeyLabel, workflowFilePath, deploymentConfig).catch((err) => core.warning(`Failed to annotate resources: ${err} `));
|
||||||
yield labelResources(files, kubectl, annotationKeyLabel);
|
yield labelResources(files, kubectl, annotationKeyLabel).catch((err) => core.warning(`Failed to label resources: ${err}`));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.annotateAndLabelResources = annotateAndLabelResources;
|
exports.annotateAndLabelResources = annotateAndLabelResources;
|
||||||
@@ -22360,13 +22368,17 @@ class Kubectl {
|
|||||||
let newReplicaSet = '';
|
let newReplicaSet = '';
|
||||||
if (result === null || result === void 0 ? void 0 : result.stdout) {
|
if (result === null || result === void 0 ? void 0 : result.stdout) {
|
||||||
const stdout = result.stdout.split('\n');
|
const stdout = result.stdout.split('\n');
|
||||||
|
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout));
|
||||||
stdout.forEach((line) => {
|
stdout.forEach((line) => {
|
||||||
const newreplicaset = 'newreplicaset';
|
const newreplicaset = 'newreplicaset';
|
||||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
|
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
|
||||||
|
core.debug(`found string of interest for replicaset, line is ${line}`);
|
||||||
|
core.debug(`substring is ${line.substring(newreplicaset.length).trim()}`);
|
||||||
newReplicaSet = line
|
newReplicaSet = line
|
||||||
.substring(newreplicaset.length)
|
.substring(newreplicaset.length)
|
||||||
.trim()
|
.trim()
|
||||||
.split(' ')[0];
|
.split(' ')[0];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return newReplicaSet;
|
return newReplicaSet;
|
||||||
@@ -23803,8 +23815,9 @@ exports.getTrafficSplitAPIVersion = getTrafficSplitAPIVersion;
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = void 0;
|
exports.removeInvalidLabelCharacters = exports.cleanLabel = exports.getWorkflowAnnotationKeyLabel = exports.getWorkflowAnnotations = exports.VALID_LABEL_REGEX = void 0;
|
||||||
const ANNOTATION_PREFIX = 'actions.github.com';
|
const ANNOTATION_PREFIX = 'actions.github.com';
|
||||||
|
exports.VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
|
||||||
function getWorkflowAnnotations(lastSuccessRunSha, workflowFilePath, deploymentConfig) {
|
function getWorkflowAnnotations(lastSuccessRunSha, workflowFilePath, deploymentConfig) {
|
||||||
const annotationObject = {
|
const annotationObject = {
|
||||||
run: process.env.GITHUB_RUN_ID,
|
run: process.env.GITHUB_RUN_ID,
|
||||||
@@ -23836,14 +23849,20 @@ exports.getWorkflowAnnotationKeyLabel = getWorkflowAnnotationKeyLabel;
|
|||||||
* @returns cleaned label
|
* @returns cleaned label
|
||||||
*/
|
*/
|
||||||
function cleanLabel(label) {
|
function cleanLabel(label) {
|
||||||
let removedInvalidChars = label
|
let removedInvalidChars = removeInvalidLabelCharacters(label);
|
||||||
|
const regexResult = exports.VALID_LABEL_REGEX.exec(removedInvalidChars) || [
|
||||||
|
'github-workflow-file'
|
||||||
|
];
|
||||||
|
return regexResult[0];
|
||||||
|
}
|
||||||
|
exports.cleanLabel = cleanLabel;
|
||||||
|
function removeInvalidLabelCharacters(label) {
|
||||||
|
return label
|
||||||
.replace(/\s/gi, '_')
|
.replace(/\s/gi, '_')
|
||||||
.replace(/[\/\\\|]/gi, '-')
|
.replace(/[\/\\\|]/gi, '-')
|
||||||
.replace(/[^-A-Za-z0-9_.]/gi, '');
|
.replace(/[^-A-Za-z0-9_.]/gi, '');
|
||||||
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/;
|
|
||||||
return regex.exec(removedInvalidChars)[0] || '';
|
|
||||||
}
|
}
|
||||||
exports.cleanLabel = cleanLabel;
|
exports.removeInvalidLabelCharacters = removeInvalidLabelCharacters;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|||||||
@@ -150,8 +150,15 @@ export async function annotateAndLabelResources(
|
|||||||
resourceTypes: Resource[],
|
resourceTypes: Resource[],
|
||||||
allPods: any
|
allPods: any
|
||||||
) {
|
) {
|
||||||
|
const defaultWorkflowFileName = 'k8s-deploy-failed-workflow-annotation'
|
||||||
const githubToken = core.getInput('token')
|
const githubToken = core.getInput('token')
|
||||||
const workflowFilePath = await getWorkflowFilePath(githubToken)
|
let workflowFilePath
|
||||||
|
try {
|
||||||
|
workflowFilePath = await getWorkflowFilePath(githubToken)
|
||||||
|
} catch (ex) {
|
||||||
|
core.warning(`Failed to extract workflow file name: ${ex}`)
|
||||||
|
workflowFilePath = defaultWorkflowFileName
|
||||||
|
}
|
||||||
|
|
||||||
const deploymentConfig = await getDeploymentConfig()
|
const deploymentConfig = await getDeploymentConfig()
|
||||||
const annotationKeyLabel = getWorkflowAnnotationKeyLabel()
|
const annotationKeyLabel = getWorkflowAnnotationKeyLabel()
|
||||||
@@ -164,8 +171,11 @@ export async function annotateAndLabelResources(
|
|||||||
annotationKeyLabel,
|
annotationKeyLabel,
|
||||||
workflowFilePath,
|
workflowFilePath,
|
||||||
deploymentConfig
|
deploymentConfig
|
||||||
|
).catch((err) => core.warning(`Failed to annotate resources: ${err} `))
|
||||||
|
|
||||||
|
await labelResources(files, kubectl, annotationKeyLabel).catch((err) =>
|
||||||
|
core.warning(`Failed to label resources: ${err}`)
|
||||||
)
|
)
|
||||||
await labelResources(files, kubectl, annotationKeyLabel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function annotateResources(
|
async function annotateResources(
|
||||||
|
|||||||
@@ -70,13 +70,21 @@ export class Kubectl {
|
|||||||
let newReplicaSet = ''
|
let newReplicaSet = ''
|
||||||
if (result?.stdout) {
|
if (result?.stdout) {
|
||||||
const stdout = result.stdout.split('\n')
|
const stdout = result.stdout.split('\n')
|
||||||
|
core.debug('stdout from getNewReplicaSet is ' + JSON.stringify(stdout))
|
||||||
stdout.forEach((line: string) => {
|
stdout.forEach((line: string) => {
|
||||||
const newreplicaset = 'newreplicaset'
|
const newreplicaset = 'newreplicaset'
|
||||||
if (line && line.toLowerCase().indexOf(newreplicaset) > -1)
|
if (line && line.toLowerCase().indexOf(newreplicaset) > -1) {
|
||||||
|
core.debug(
|
||||||
|
`found string of interest for replicaset, line is ${line}`
|
||||||
|
)
|
||||||
|
core.debug(
|
||||||
|
`substring is ${line.substring(newreplicaset.length).trim()}`
|
||||||
|
)
|
||||||
newReplicaSet = line
|
newReplicaSet = line
|
||||||
.substring(newreplicaset.length)
|
.substring(newreplicaset.length)
|
||||||
.trim()
|
.trim()
|
||||||
.split(' ')[0]
|
.split(' ')[0]
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import {cleanLabel} from '../utilities/workflowAnnotationUtils'
|
import {
|
||||||
|
cleanLabel,
|
||||||
|
removeInvalidLabelCharacters,
|
||||||
|
VALID_LABEL_REGEX
|
||||||
|
} from '../utilities/workflowAnnotationUtils'
|
||||||
|
|
||||||
describe('WorkflowAnnotationUtils', () => {
|
describe('WorkflowAnnotationUtils', () => {
|
||||||
describe('cleanLabel', () => {
|
describe('cleanLabel', () => {
|
||||||
@@ -16,5 +20,14 @@ describe('WorkflowAnnotationUtils', () => {
|
|||||||
cleanLabel('Workflow Name / With Slashes / And Spaces')
|
cleanLabel('Workflow Name / With Slashes / And Spaces')
|
||||||
).toEqual('Workflow_Name_-_With_Slashes_-_And_Spaces')
|
).toEqual('Workflow_Name_-_With_Slashes_-_And_Spaces')
|
||||||
})
|
})
|
||||||
|
it('should return a blank string when regex fails (https://github.com/Azure/k8s-deploy/issues/266)', () => {
|
||||||
|
const label = '持续部署'
|
||||||
|
expect(cleanLabel(label)).toEqual('github-workflow-file')
|
||||||
|
|
||||||
|
let removedInvalidChars = removeInvalidLabelCharacters(label)
|
||||||
|
|
||||||
|
const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars)
|
||||||
|
expect(regexResult).toBe(null)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import {DeploymentConfig} from '../types/deploymentConfig'
|
|||||||
|
|
||||||
const ANNOTATION_PREFIX = 'actions.github.com'
|
const ANNOTATION_PREFIX = 'actions.github.com'
|
||||||
|
|
||||||
|
export const VALID_LABEL_REGEX = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
|
||||||
|
|
||||||
export function getWorkflowAnnotations(
|
export function getWorkflowAnnotations(
|
||||||
lastSuccessRunSha: string,
|
lastSuccessRunSha: string,
|
||||||
workflowFilePath: string,
|
workflowFilePath: string,
|
||||||
@@ -37,11 +39,17 @@ export function getWorkflowAnnotationKeyLabel(): string {
|
|||||||
* @returns cleaned label
|
* @returns cleaned label
|
||||||
*/
|
*/
|
||||||
export function cleanLabel(label: string): string {
|
export function cleanLabel(label: string): string {
|
||||||
let removedInvalidChars = label
|
let removedInvalidChars = removeInvalidLabelCharacters(label)
|
||||||
|
|
||||||
|
const regexResult = VALID_LABEL_REGEX.exec(removedInvalidChars) || [
|
||||||
|
'github-workflow-file'
|
||||||
|
]
|
||||||
|
return regexResult[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeInvalidLabelCharacters(label: string): string {
|
||||||
|
return label
|
||||||
.replace(/\s/gi, '_')
|
.replace(/\s/gi, '_')
|
||||||
.replace(/[\/\\\|]/gi, '-')
|
.replace(/[\/\\\|]/gi, '-')
|
||||||
.replace(/[^-A-Za-z0-9_.]/gi, '')
|
.replace(/[^-A-Za-z0-9_.]/gi, '')
|
||||||
|
|
||||||
const regex = /([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]/
|
|
||||||
return regex.exec(removedInvalidChars)[0] || ''
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user