Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes multiple namespaces bug #276

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/actions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export async function deploy(
for (const ingressResource of ingressResources) {
await kubectl.getResource(
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
ingressResource.name
ingressResource.name,
OliverMKing marked this conversation as resolved.
Show resolved Hide resolved
false,
ingressResource.namespace
)
}
core.endGroup()
Expand Down
8 changes: 5 additions & 3 deletions src/strategyHelpers/blueGreen/blueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export async function deleteGreenObjects(
const resourcesToDelete: K8sDeleteObject[] = toDelete.map((obj) => {
return {
name: getBlueGreenResourceName(obj.metadata.name, GREEN_SUFFIX),
kind: obj.kind
kind: obj.kind,
namespace: obj.metadata.namespace
}
})

Expand Down Expand Up @@ -234,9 +235,10 @@ export function isServiceSelectorSubsetOfMatchLabel(
export async function fetchResource(
kubectl: Kubectl,
kind: string,
name: string
name: string,
namespace?: string
): Promise<K8sObject> {
const result = await kubectl.getResource(kind, name)
const result = await kubectl.getResource(kind, name, false, namespace)
if (result == null || !!result.stderr) {
return null
}
Expand Down
3 changes: 2 additions & 1 deletion src/strategyHelpers/blueGreen/ingressBlueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export async function validateIngresses(
const existingIngress = await fetchResource(
kubectl,
inputObject.kind,
inputObject.metadata.name
inputObject.metadata.name,
inputObject?.metadata?.namespace
)

const isValid =
Expand Down
3 changes: 2 additions & 1 deletion src/strategyHelpers/blueGreen/serviceBlueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export async function validateServicesState(
const existingService = await fetchResource(
kubectl,
serviceObject.kind,
serviceObject.metadata.name
serviceObject.metadata.name,
serviceObject?.metadata?.namespace
)

let isServiceGreen =
Expand Down
6 changes: 4 additions & 2 deletions src/strategyHelpers/blueGreen/smiBlueGreenHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export async function validateTrafficSplitsState(
let trafficSplitObject = await fetchResource(
kubectl,
TRAFFIC_SPLIT_OBJECT,
getBlueGreenResourceName(name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX)
getBlueGreenResourceName(name, TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX),
serviceObject?.metadata?.namespace
)
core.debug(
`ts object extracted was ${JSON.stringify(trafficSplitObject)}`
Expand Down Expand Up @@ -183,7 +184,8 @@ export async function cleanupSMI(
serviceObject.metadata.name,
GREEN_SUFFIX
),
kind: serviceObject.kind
kind: serviceObject.kind,
namespace: serviceObject?.metadata?.namespace
})
})

Expand Down
11 changes: 8 additions & 3 deletions src/strategyHelpers/canary/canaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ async function cleanUpCanary(
files: string[],
includeServices: boolean
): Promise<string[]> {
const deleteObject = async function (kind, name) {
const deleteObject = async function (
kind: string,
name: string,
ns: string
) {
try {
const result = await kubectl.delete([kind, name])
checkForErrors([result])
Expand All @@ -213,6 +217,7 @@ async function cleanUpCanary(
for (const inputObject of parsedYaml) {
const name = inputObject.metadata.name
const kind = inputObject.kind
const ns = inputObject?.metadata?.namespace
OliverMKing marked this conversation as resolved.
Show resolved Hide resolved

if (
isDeploymentEntity(kind) ||
Expand All @@ -222,8 +227,8 @@ async function cleanUpCanary(
const canaryObjectName = getCanaryResourceName(name)
const baselineObjectName = getBaselineResourceName(name)

await deleteObject(kind, canaryObjectName)
await deleteObject(kind, baselineObjectName)
await deleteObject(kind, canaryObjectName, ns)
OliverMKing marked this conversation as resolved.
Show resolved Hide resolved
await deleteObject(kind, baselineObjectName, ns)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ async function annotateResources(
)
if (annotateNamespace) {
annotateResults.push(
await kubectl.annotate('namespace', namespace, annotationKeyValStr)
await kubectl.annotate(
'namespace',
OliverMKing marked this conversation as resolved.
Show resolved Hide resolved
namespace,
annotationKeyValStr,
namespace
)
)
}
for (const file of files) {
Expand All @@ -243,6 +248,7 @@ async function annotateResources(
kubectl,
resource.type,
resource.name,
resource.namespace,
annotationKeyValStr,
allPods
)
Expand Down
2 changes: 2 additions & 0 deletions src/types/k8sObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface K8sObject {
metadata: {
name: string
labels: Map<string, string>
namespace?: string
}
kind: string
spec: any
Expand All @@ -16,6 +17,7 @@ export interface K8sServiceObject extends K8sObject {
export interface K8sDeleteObject {
name: string
kind: string
namespace?: string
}

export interface K8sIngress extends K8sObject {
Expand Down
Loading