mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-27 07:09:26 +08:00
Added Integration Tests, Resolved Bugs With Annotations (#255)
* First commit - made manifests for test deployments, made manifests for i tests for other deployment strategies * broke down blue/green * added latest tags to test manifests for new tags * remade tester * ready to test bgi * using all but first index of argv * careless error with dicts * added test to namespace * realized i was silencing error * indexing containers * keyerror * logging bc python errors are weird * expected still string * parsed args behaving weirdly * test seems to be working now, applying changes to other YAMLs now * blue/green ready to test * oops * oops * Added additional labels to check * hyphen * Added our annotations * lol * added our labels to services too * nonetype issue' * nonetype issue' * narrowing down parameter * fixed annotations issue with promote * adding debhug statement to figure out why services aren't getting annotations * this should fix annotations issue for service * not sure why this wasn't caught by intellisense * should be fixed with removing comma but adding logs in case * added linkerd install * verification * upgraded kubernetes version * removing crds * proxy option * Added smi extension * logging service * smi svcs also getting labeled now * matching ts type * not sure where stable service is going * remaining svc and deployment should match * keeping stable service and ts object * updated tests to reflect keeping ts object * no green svc after promote * duh * lol * canary work * canary test ready * logging for ing, filename for canary * changed ingress svc key and returning svc files from smi canary deployment * ts name * forgot about baseline in first deploy * * * * * smi canary should annotate, fixed cleanup * typescript issue plus percentage * forgot to type extra method * removed cleaned up objects from annotate list * logging because services aren't getting removed * moving to try/catch strategy of annotation since deletion can fail silently/with warnings * moved label to individual * removing canary service check after promote * pod ready for testing * set weights to 1000 * selectors * * * percentage * * * typing * mixed up pod and smi * fixed tests * prettier * forgot to remove canary * cleanup * Added oliver's feedback + more cleanup * ncc as dev dependency * npx * going back to global ncc install bc npm is being weird * prettier * removed unnecessary post step
This commit is contained in:
@@ -29,12 +29,17 @@ export async function deleteCanaryDeployment(
|
||||
kubectl: Kubectl,
|
||||
manifestFilePaths: string[],
|
||||
includeServices: boolean
|
||||
) {
|
||||
): Promise<string[]> {
|
||||
if (manifestFilePaths == null || manifestFilePaths.length == 0) {
|
||||
throw new Error('Manifest files for deleting canary deployment not found')
|
||||
}
|
||||
|
||||
await cleanUpCanary(kubectl, manifestFilePaths, includeServices)
|
||||
const deletedFiles = await cleanUpCanary(
|
||||
kubectl,
|
||||
manifestFilePaths,
|
||||
includeServices
|
||||
)
|
||||
return deletedFiles
|
||||
}
|
||||
|
||||
export function markResourceAsStable(inputObject: any): object {
|
||||
@@ -189,7 +194,7 @@ async function cleanUpCanary(
|
||||
kubectl: Kubectl,
|
||||
files: string[],
|
||||
includeServices: boolean
|
||||
) {
|
||||
): Promise<string[]> {
|
||||
const deleteObject = async function (kind, name) {
|
||||
try {
|
||||
const result = await kubectl.delete([kind, name])
|
||||
@@ -199,6 +204,8 @@ async function cleanUpCanary(
|
||||
}
|
||||
}
|
||||
|
||||
const deletedFiles: string[] = []
|
||||
|
||||
for (const filePath of files) {
|
||||
const fileContents = fs.readFileSync(filePath).toString()
|
||||
|
||||
@@ -211,6 +218,7 @@ async function cleanUpCanary(
|
||||
isDeploymentEntity(kind) ||
|
||||
(includeServices && isServiceEntity(kind))
|
||||
) {
|
||||
deletedFiles.push(filePath)
|
||||
const canaryObjectName = getCanaryResourceName(name)
|
||||
const baselineObjectName = getBaselineResourceName(name)
|
||||
|
||||
@@ -219,4 +227,6 @@ async function cleanUpCanary(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deletedFiles
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ import * as fileHelper from '../../utilities/fileUtils'
|
||||
import * as canaryDeploymentHelper from './canaryHelper'
|
||||
import {isDeploymentEntity} from '../../types/kubernetesTypes'
|
||||
import {getReplicaCount} from '../../utilities/manifestUpdateUtils'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
|
||||
export async function deployPodCanary(
|
||||
filePaths: string[],
|
||||
kubectl: Kubectl,
|
||||
onlyDeployStable: boolean = false
|
||||
) {
|
||||
): Promise<DeployResult> {
|
||||
const newObjectsList = []
|
||||
const percentage = parseInt(core.getInput('percentage', {required: true}))
|
||||
|
||||
@@ -71,8 +72,8 @@ export async function deployPodCanary(
|
||||
const manifestFiles = fileHelper.writeObjectsToFile(newObjectsList)
|
||||
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
|
||||
|
||||
const result = await kubectl.apply(manifestFiles, forceDeployment)
|
||||
return {result, newFilePaths: manifestFiles}
|
||||
const execResult = await kubectl.apply(manifestFiles, forceDeployment)
|
||||
return {execResult, manifestFiles}
|
||||
}
|
||||
|
||||
export function calculateReplicaCountForCanary(
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as podCanaryHelper from './podCanaryHelper'
|
||||
import {isDeploymentEntity, isServiceEntity} from '../../types/kubernetesTypes'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils'
|
||||
import {inputAnnotations} from '../../inputUtils'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
|
||||
const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout'
|
||||
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit'
|
||||
@@ -18,7 +19,7 @@ export async function deploySMICanary(
|
||||
filePaths: string[],
|
||||
kubectl: Kubectl,
|
||||
onlyDeployStable: boolean = false
|
||||
) {
|
||||
): Promise<DeployResult> {
|
||||
const canaryReplicasInput = core.getInput('baseline-and-canary-replicas')
|
||||
let canaryReplicaCount
|
||||
let calculateReplicas = true
|
||||
@@ -97,11 +98,15 @@ export async function deploySMICanary(
|
||||
const newFilePaths = fileHelper.writeObjectsToFile(newObjectsList)
|
||||
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
|
||||
const result = await kubectl.apply(newFilePaths, forceDeployment)
|
||||
await createCanaryService(kubectl, filePaths)
|
||||
return {result, newFilePaths}
|
||||
const svcDeploymentFiles = await createCanaryService(kubectl, filePaths)
|
||||
newFilePaths.push(...svcDeploymentFiles)
|
||||
return {execResult: result, manifestFiles: newFilePaths}
|
||||
}
|
||||
|
||||
async function createCanaryService(kubectl: Kubectl, filePaths: string[]) {
|
||||
async function createCanaryService(
|
||||
kubectl: Kubectl,
|
||||
filePaths: string[]
|
||||
): Promise<string[]> {
|
||||
const newObjectsList = []
|
||||
const trafficObjectsList: string[] = []
|
||||
|
||||
@@ -190,6 +195,7 @@ async function createCanaryService(kubectl: Kubectl, filePaths: string[]) {
|
||||
|
||||
const result = await kubectl.apply(manifestFiles, forceDeployment)
|
||||
checkForErrors([result])
|
||||
return manifestFiles
|
||||
}
|
||||
|
||||
export async function redirectTrafficToCanaryDeployment(
|
||||
@@ -202,8 +208,8 @@ export async function redirectTrafficToCanaryDeployment(
|
||||
export async function redirectTrafficToStableDeployment(
|
||||
kubectl: Kubectl,
|
||||
manifestFilePaths: string[]
|
||||
) {
|
||||
await adjustTraffic(kubectl, manifestFilePaths, 1000, 0)
|
||||
): Promise<string[]> {
|
||||
return await adjustTraffic(kubectl, manifestFilePaths, 1000, 0)
|
||||
}
|
||||
|
||||
async function adjustTraffic(
|
||||
@@ -245,6 +251,7 @@ async function adjustTraffic(
|
||||
const forceDeployment = core.getInput('force').toLowerCase() === 'true'
|
||||
const result = await kubectl.apply(trafficSplitManifests, forceDeployment)
|
||||
checkForErrors([result])
|
||||
return trafficSplitManifests
|
||||
}
|
||||
|
||||
async function updateTrafficSplitObject(
|
||||
|
||||
Reference in New Issue
Block a user