diff --git a/CHANGELOG.md b/CHANGELOG.md index 655b4d0f5..9a7340a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [5.0.1] - 2024-03-12 + +### Added + +- #356 Add fleet support + ## [5.0.0] - 2024-03-12 ### Changed diff --git a/README.md b/README.md index c99d521e5..f0012844f 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ Following are the key capabilities of this action: skip-tls-verify

(Optional) Acceptable values: true/false
Default value: false
True if the insecure-skip-tls-verify option should be used + + resource-type (Optional) + Acceptable values: `Microsoft.ContainerService/managedClusters` (default), 'Microsoft.ContainerService/fleets' + ## Usage Examples diff --git a/src/actions/deploy.ts b/src/actions/deploy.ts index 34c18b9d1..eba643ff1 100644 --- a/src/actions/deploy.ts +++ b/src/actions/deploy.ts @@ -13,6 +13,12 @@ import { } from '../strategyHelpers/deploymentHelper' import {DeploymentStrategy} from '../types/deploymentStrategy' import {parseTrafficSplitMethod} from '../types/trafficSplitMethod' +export const ResourceTypeManagedCluster = + 'Microsoft.ContainerService/managedClusters' +export const ResourceTypeFleet = 'Microsoft.ContainerService/fleets' +export type ClusterType = + | typeof ResourceTypeManagedCluster + | typeof ResourceTypeFleet export async function deploy( kubectl: Kubectl, @@ -39,17 +45,25 @@ export async function deploy( // check manifest stability core.startGroup('Checking manifest stability') - const resourceType = ( - core.getInput('resource-type') || - 'Microsoft.ContainerService/managedClusters' - ).toLowerCase() + const resourceTypeInput = + core.getInput('resource-type') || ResourceTypeManagedCluster const resourceTypes: Resource[] = getResources( deployedManifestFiles, models.DEPLOYMENT_TYPES.concat([ KubernetesConstants.DiscoveryAndLoadBalancerResource.SERVICE ]) ) - await checkManifestStability(kubectl, resourceTypes, resourceType) + + if ( + resourceTypeInput !== ResourceTypeManagedCluster && + resourceTypeInput !== ResourceTypeFleet + ) { + let errMsg = `Invalid resource type: ${resourceTypeInput}. Supported resource types are: ${ResourceTypeManagedCluster} (default), ${ResourceTypeFleet}` + core.setFailed(errMsg) + throw new Error(errMsg) + } + + await checkManifestStability(kubectl, resourceTypes, resourceTypeInput) core.endGroup() // print ingresses diff --git a/src/actions/promote.ts b/src/actions/promote.ts index 7a6c3075b..b4a99a52d 100644 --- a/src/actions/promote.ts +++ b/src/actions/promote.ts @@ -38,6 +38,7 @@ import { TrafficSplitMethod } from '../types/trafficSplitMethod' import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy' +import {ResourceTypeFleet, ResourceTypeManagedCluster} from './deploy' export async function promote( kubectl: Kubectl, @@ -166,10 +167,8 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) { // checking stability of newly created deployments core.startGroup('Checking manifest stability') - const resourceType = ( - core.getInput('resource-type') || - 'Microsoft.ContainerService/managedClusters' - ).toLowerCase() + const resourceType = + core.getInput('resource-type') || ResourceTypeManagedCluster const deployedManifestFiles = deployResult.manifestFiles const resources: Resource[] = getResources( deployedManifestFiles, @@ -177,6 +176,14 @@ async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) { models.DiscoveryAndLoadBalancerResource.SERVICE ]) ) + if ( + resourceType !== ResourceTypeManagedCluster && + resourceType !== ResourceTypeFleet + ) { + const errMsg = `Invalid resource type: ${resourceType}. Supported resource types are: ${ResourceTypeManagedCluster} (default), fleet` + core.setFailed(errMsg) + throw new Error(errMsg) + } await KubernetesManifestUtility.checkManifestStability( kubectl, resources, diff --git a/src/strategyHelpers/deploymentHelper.ts b/src/strategyHelpers/deploymentHelper.ts index 024f60f53..891050261 100644 --- a/src/strategyHelpers/deploymentHelper.ts +++ b/src/strategyHelpers/deploymentHelper.ts @@ -35,6 +35,7 @@ import { } from '../utilities/githubUtils' import {getDeploymentConfig} from '../utilities/dockerUtils' import {DeployResult} from '../types/deployResult' +import {ClusterType} from '../actions/deploy' export async function deployManifests( files: string[], @@ -139,7 +140,7 @@ function appendStableVersionLabelToResource(files: string[]): string[] { export async function checkManifestStability( kubectl: Kubectl, resources: Resource[], - resourceType: string + resourceType: ClusterType ): Promise { await KubernetesManifestUtility.checkManifestStability( kubectl, diff --git a/src/utilities/manifestStabilityUtils.test.ts b/src/utilities/manifestStabilityUtils.test.ts index e39bcc384..d1eb7dbad 100644 --- a/src/utilities/manifestStabilityUtils.test.ts +++ b/src/utilities/manifestStabilityUtils.test.ts @@ -1,5 +1,8 @@ import * as manifestStabilityUtils from './manifestStabilityUtils' import {Kubectl} from '../types/kubectl' +import {ResourceTypeFleet, ResourceTypeManagedCluster} from '../actions/deploy' +import {ExecOutput} from '@actions/exec' +import {exitCode, stdout} from 'process' describe('manifestStabilityUtils', () => { const kc = new Kubectl('') @@ -10,18 +13,40 @@ describe('manifestStabilityUtils', () => { namespace: 'default' } ] - const resourceType = 'microsoft.containerservice/fleets' - it('should return immediately if the resource type is microsoft.containerservice/fleets', async () => { + it('should return immediately if the resource type is fleet', async () => { const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability') const checkRolloutStatusSpy = jest.spyOn(kc, 'checkRolloutStatus') await manifestStabilityUtils.checkManifestStability( kc, resources, - resourceType + ResourceTypeFleet ) expect(checkRolloutStatusSpy).not.toHaveBeenCalled() expect(spy).toHaveReturned() }) + + it('should run fully if the resource type is managedCluster', async () => { + const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability') + const checkRolloutStatusSpy = jest + .spyOn(kc, 'checkRolloutStatus') + .mockImplementation(() => { + return new Promise((resolve, reject) => { + resolve({ + exitCode: 0, + stderr: '', + stdout: '' + }) + }) + }) + await manifestStabilityUtils.checkManifestStability( + kc, + resources, + ResourceTypeManagedCluster + ) + + expect(checkRolloutStatusSpy).toHaveBeenCalled() + expect(spy).toHaveReturned() + }) }) diff --git a/src/utilities/manifestStabilityUtils.ts b/src/utilities/manifestStabilityUtils.ts index 51efd49f5..640cd36db 100644 --- a/src/utilities/manifestStabilityUtils.ts +++ b/src/utilities/manifestStabilityUtils.ts @@ -3,6 +3,7 @@ import * as KubernetesConstants from '../types/kubernetesTypes' import {Kubectl, Resource} from '../types/kubectl' import {checkForErrors} from './kubectlUtils' import {sleep} from './timeUtils' +import {ClusterType, ResourceTypeFleet} from '../actions/deploy' const IS_SILENT = false const POD = 'pod' @@ -10,13 +11,11 @@ const POD = 'pod' export async function checkManifestStability( kubectl: Kubectl, resources: Resource[], - resourceType: string + clusterTyper: ClusterType ): Promise { // Skip if resource type is microsoft.containerservice/fleets - if (resourceType === 'microsoft.containerservice/fleets') { - core.info( - 'Skipping checkManifestStability for microsoft.containerservice/fleets' - ) + if (clusterTyper === ResourceTypeFleet) { + core.info(`Skipping checkManifestStability for ${ResourceTypeFleet}`) return } let rolloutStatusHasErrors = false