Skip to content

Commit

Permalink
Fix “Service” route-method of the Blue-Green strategy with some manif…
Browse files Browse the repository at this point in the history
…est files (#283)
  • Loading branch information
otetard authored Apr 17, 2023
1 parent dd4bbd1 commit e52890d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 219 deletions.
224 changes: 16 additions & 208 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@types/jest": "^26.0.0",
"@types/js-yaml": "^3.12.7",
"@types/node": "^12.20.41",
"@vercel/ncc": "^0.36.1",
"jest": "^26.0.0",
"ncc": "^0.3.6",
"prettier": "^2.7.1",
"ts-jest": "^26.0.0",
"typescript": "3.9.5"
Expand Down
24 changes: 14 additions & 10 deletions src/strategyHelpers/blueGreen/blueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,25 @@ export async function deleteObjects(
// other common functions
export function getManifestObjects(filePaths: string[]): BlueGreenManifests {
const deploymentEntityList: K8sObject[] = []
const serviceEntityList: K8sObject[] = []
const routedServiceEntityList: K8sObject[] = []
const unroutedServiceEntityList: K8sObject[] = []
const ingressEntityList: K8sObject[] = []
const otherEntitiesList: K8sObject[] = []
const serviceNameMap = new Map<string, string>()

// Manifest objects per type. All resources should be parsed and
// organized before we can check if services are “routed” or not.
filePaths.forEach((filePath: string) => {
const fileContents = fs.readFileSync(filePath).toString()
yaml.safeLoadAll(fileContents, (inputObject) => {
if (!!inputObject) {
const kind = inputObject.kind
const name = inputObject.metadata.name

if (isDeploymentEntity(kind)) {
deploymentEntityList.push(inputObject)
} else if (isServiceEntity(kind)) {
if (isServiceRouted(inputObject, deploymentEntityList)) {
routedServiceEntityList.push(inputObject)
serviceNameMap.set(
name,
getBlueGreenResourceName(name, GREEN_SUFFIX)
)
} else {
unroutedServiceEntityList.push(inputObject)
}
serviceEntityList.push(inputObject)
} else if (isIngressEntity(kind)) {
ingressEntityList.push(inputObject)
} else {
Expand All @@ -101,6 +95,16 @@ export function getManifestObjects(filePaths: string[]): BlueGreenManifests {
})
})

serviceEntityList.forEach((inputObject: any) => {
if (isServiceRouted(inputObject, deploymentEntityList)) {
const name = inputObject.metadata.name
routedServiceEntityList.push(inputObject)
serviceNameMap.set(name, getBlueGreenResourceName(name, GREEN_SUFFIX))
} else {
unroutedServiceEntityList.push(inputObject)
}
})

return {
serviceEntityList: routedServiceEntityList,
serviceNameMap: serviceNameMap,
Expand Down

0 comments on commit e52890d

Please sign in to comment.