k8s-deploy/src/actions/deploy.ts
Oliver King ecb488266d
Fixes multiple namespaces bug (#276)
* fix ns bug

* add tests

* rename some variables

* rename ns to namespace

* fix delete + correctly type

* add typing to input obj parser
2023-02-06 13:42:55 -05:00

82 lines
2.4 KiB
TypeScript

import * as core from '@actions/core'
import * as models from '../types/kubernetesTypes'
import * as KubernetesConstants from '../types/kubernetesTypes'
import {Kubectl, Resource} from '../types/kubectl'
import {
getResources,
updateManifestFiles
} from '../utilities/manifestUpdateUtils'
import {
annotateAndLabelResources,
checkManifestStability,
deployManifests
} from '../strategyHelpers/deploymentHelper'
import {DeploymentStrategy} from '../types/deploymentStrategy'
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod'
export async function deploy(
kubectl: Kubectl,
manifestFilePaths: string[],
deploymentStrategy: DeploymentStrategy
) {
// update manifests
const inputManifestFiles: string[] = updateManifestFiles(manifestFilePaths)
core.debug(`Input manifest files: ${inputManifestFiles}`)
// deploy manifests
core.startGroup('Deploying manifests')
const trafficSplitMethod = parseTrafficSplitMethod(
core.getInput('traffic-split-method', {required: true})
)
const deployedManifestFiles = await deployManifests(
inputManifestFiles,
deploymentStrategy,
kubectl,
trafficSplitMethod
)
core.debug(`Deployed manifest files: ${deployedManifestFiles}`)
core.endGroup()
// check manifest stability
core.startGroup('Checking manifest stability')
const resourceTypes: Resource[] = getResources(
deployedManifestFiles,
models.DEPLOYMENT_TYPES.concat([
KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE
])
)
await checkManifestStability(kubectl, resourceTypes)
core.endGroup()
// print ingresses
core.startGroup('Printing ingresses')
const ingressResources: Resource[] = getResources(deployedManifestFiles, [
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS
])
for (const ingressResource of ingressResources) {
await kubectl.getResource(
KubernetesConstants.DiscoveryAndLoadBalancerResource.INGRESS,
ingressResource.name,
false,
ingressResource.namespace
)
}
core.endGroup()
// annotate resources
core.startGroup('Annotating resources')
let allPods
try {
allPods = JSON.parse((await kubectl.getAllPods()).stdout)
} catch (e) {
core.debug(`Unable to parse pods: ${e}`)
}
await annotateAndLabelResources(
deployedManifestFiles,
kubectl,
resourceTypes,
allPods
)
core.endGroup()
}