mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-21 18:59:27 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ebc294c887 | |||
| 72a09f4051 | |||
| a17f35ba63 |
+16
-8
@@ -65,26 +65,30 @@ async function promoteCanary(kubectl: Kubectl, manifests: string[]) {
|
||||
|
||||
// In case of SMI traffic split strategy when deployment is promoted, first we will redirect traffic to
|
||||
// canary deployment, then update stable deployment and then redirect traffic to stable deployment
|
||||
core.info('Redirecting traffic to canary deployment')
|
||||
core.startGroup('Redirecting traffic to canary deployment')
|
||||
await SMICanaryDeploymentHelper.redirectTrafficToCanaryDeployment(
|
||||
kubectl,
|
||||
manifests
|
||||
)
|
||||
core.endGroup()
|
||||
|
||||
core.info('Deploying input manifests with SMI canary strategy')
|
||||
core.startGroup('Deploying input manifests with SMI canary strategy')
|
||||
await deploy.deploy(kubectl, manifests, DeploymentStrategy.CANARY)
|
||||
core.endGroup()
|
||||
|
||||
core.info('Redirecting traffic to stable deployment')
|
||||
core.startGroup('Redirecting traffic to stable deployment')
|
||||
await SMICanaryDeploymentHelper.redirectTrafficToStableDeployment(
|
||||
kubectl,
|
||||
manifests
|
||||
)
|
||||
core.endGroup()
|
||||
} else {
|
||||
core.info('Deploying input manifests')
|
||||
core.startGroup('Deploying input manifests')
|
||||
await deploy.deploy(kubectl, manifests, DeploymentStrategy.CANARY)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
core.info('Deleting canary and baseline workloads')
|
||||
core.startGroup('Deleting canary and baseline workloads')
|
||||
try {
|
||||
await canaryDeploymentHelper.deleteCanaryDeployment(
|
||||
kubectl,
|
||||
@@ -97,6 +101,7 @@ async function promoteCanary(kubectl: Kubectl, manifests: string[]) {
|
||||
ex
|
||||
)
|
||||
}
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
@@ -109,7 +114,7 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
core.getInput('route-method', {required: true})
|
||||
)
|
||||
|
||||
core.info('Deleting old deployment and making new one')
|
||||
core.startGroup('Deleting old deployment and making new one')
|
||||
let result
|
||||
if (routeStrategy == RouteStrategy.INGRESS) {
|
||||
result = await promoteBlueGreenIngress(kubectl, manifestObjects)
|
||||
@@ -118,9 +123,10 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
} else {
|
||||
result = await promoteBlueGreenService(kubectl, manifestObjects)
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
// checking stability of newly created deployments
|
||||
core.info('Checking manifest stability')
|
||||
core.startGroup('Checking manifest stability')
|
||||
const deployedManifestFiles = result.newFilePaths
|
||||
const resources: Resource[] = getResources(
|
||||
deployedManifestFiles,
|
||||
@@ -129,8 +135,9 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
])
|
||||
)
|
||||
await KubernetesManifestUtility.checkManifestStability(kubectl, resources)
|
||||
core.endGroup()
|
||||
|
||||
core.info(
|
||||
core.startGroup(
|
||||
'Routing to new deployments and deleting old workloads and services'
|
||||
)
|
||||
if (routeStrategy == RouteStrategy.INGRESS) {
|
||||
@@ -170,4 +177,5 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
manifestObjects.deploymentEntityList
|
||||
)
|
||||
}
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
@@ -36,24 +36,26 @@ async function rejectCanary(kubectl: Kubectl, manifests: string[]) {
|
||||
core.getInput('traffic-split-method', {required: true})
|
||||
)
|
||||
if (trafficSplitMethod == TrafficSplitMethod.SMI) {
|
||||
core.info('Rejecting deployment with SMI canary strategy')
|
||||
core.startGroup('Rejecting deployment with SMI canary strategy')
|
||||
includeServices = true
|
||||
await SMICanaryDeploymentHelper.redirectTrafficToStableDeployment(
|
||||
kubectl,
|
||||
manifests
|
||||
)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
core.info('Deleting baseline and canary workloads')
|
||||
core.startGroup('Deleting baseline and canary workloads')
|
||||
await canaryDeploymentHelper.deleteCanaryDeployment(
|
||||
kubectl,
|
||||
manifests,
|
||||
includeServices
|
||||
)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
async function rejectBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
core.info('Rejecting deployment with blue green strategy')
|
||||
core.startGroup('Rejecting deployment with blue green strategy')
|
||||
|
||||
const routeStrategy = parseRouteStrategy(
|
||||
core.getInput('route-method', {required: true})
|
||||
@@ -65,4 +67,5 @@ async function rejectBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||
} else {
|
||||
await rejectBlueGreenService(kubectl, manifests)
|
||||
}
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {
|
||||
getWorkflowAnnotationKeyLabel,
|
||||
getWorkflowAnnotations
|
||||
getWorkflowAnnotations,
|
||||
cleanLabel
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
import {
|
||||
annotateChildPods,
|
||||
@@ -214,10 +215,10 @@ async function labelResources(
|
||||
label: string
|
||||
) {
|
||||
const labels = [
|
||||
`workflowFriendlyName=${normalizeWorkflowStrLabel(
|
||||
process.env.GITHUB_WORKFLOW
|
||||
`workflowFriendlyName=${cleanLabel(
|
||||
normalizeWorkflowStrLabel(process.env.GITHUB_WORKFLOW)
|
||||
)}`,
|
||||
`workflow=${label}`
|
||||
`workflow=${cleanLabel(label)}`
|
||||
]
|
||||
|
||||
checkForErrors([await kubectl.labelFiles(files, labels)], true)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import {prefixObjectKeys} from '../utilities/workflowAnnotationUtils'
|
||||
import {
|
||||
cleanLabel,
|
||||
prefixObjectKeys
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
|
||||
describe('WorkflowAnnotationUtils', () => {
|
||||
describe('prefixObjectKeys', () => {
|
||||
@@ -15,4 +18,16 @@ describe('WorkflowAnnotationUtils', () => {
|
||||
expect(prefixObjectKeys(obj, prefix)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('cleanLabel', () => {
|
||||
it('should clean label', () => {
|
||||
const alreadyClean = 'alreadyClean'
|
||||
expect(cleanLabel(alreadyClean)).toEqual(alreadyClean)
|
||||
expect(cleanLabel('.startInvalid')).toEqual('startInvalid')
|
||||
expect(cleanLabel('with%S0ME&invalid#chars')).toEqual(
|
||||
'withS0MEinvalidchars'
|
||||
)
|
||||
expect(cleanLabel('with⚒️emoji')).toEqual('withemoji')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -47,3 +47,14 @@ export function getWorkflowAnnotationKeyLabel(
|
||||
.digest('hex')
|
||||
return `githubWorkflow_${hashKey}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans label to match valid kubernetes label specification by removing invalid characters
|
||||
* @param label
|
||||
* @returns cleaned label
|
||||
*/
|
||||
export function cleanLabel(label: string): string {
|
||||
const removedInvalidChars = label.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