k8s-deploy/src/actions/deploy.ts
benjamin ac0b58c9a5
Add timeout to the rollout status (#425)
* Added timeout to the rollout status and tests for it

* Fixed integration test errors

* Fix for blue green integration test

* Probable fix for integration errors

* No jobs run error fixed

* Changed timeout to file level constant

* Added parsing logic for timeout

* Made tests more concise

* implemented timeout validation check in an extracted utils mod

* Changed function name to parseDuration

* Removed timeout parameter from getResource

---------

Co-authored-by: David Gamero <david340804@gmail.com>
Co-authored-by: Suneha Bose <123775811+bosesuneha@users.noreply.github.com>
2025-07-09 10:22:21 -07:00

82 lines
2.5 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'
import {ClusterType} from '../inputUtils'
export const ResourceTypeManagedCluster =
'Microsoft.ContainerService/managedClusters'
export const ResourceTypeFleet = 'Microsoft.ContainerService/fleets'
export async function deploy(
kubectl: Kubectl,
manifestFilePaths: string[],
deploymentStrategy: DeploymentStrategy,
resourceType: ClusterType,
timeout?: string
) {
// 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,
timeout
)
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, resourceType, timeout)
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')
await annotateAndLabelResources(
deployedManifestFiles,
kubectl,
resourceTypes
)
core.endGroup()
}