Skip to content

Commit

Permalink
v5.0.1 Release with Fleet Types (#358)
Browse files Browse the repository at this point in the history
* extract resource type

* fleet details

* new release with fleet

* format

* type params

* format

* promote input

* format

* fleet type

* format pls
  • Loading branch information
davidgamero authored Dec 9, 2024
1 parent d1acc1a commit 3d107b0
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [5.0.1] - 2024-03-12

### Added

- #356 Add fleet support

## [5.0.0] - 2024-03-12

### Changed
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Following are the key capabilities of this action:
<td>skip-tls-verify</br></br>(Optional)</td>
<td>Acceptable values: true/false</br>Default value: false</br>True if the insecure-skip-tls-verify option should be used</td>
</tr>
<tr>
<td>resource-type (Optional)</td>
<td>Acceptable values: `Microsoft.ContainerService/managedClusters` (default), 'Microsoft.ContainerService/fleets'</td>
</tr>
</table>

## Usage Examples
Expand Down
24 changes: 19 additions & 5 deletions src/actions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/actions/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -166,17 +167,23 @@ 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,
models.DEPLOYMENT_TYPES.concat([
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,
Expand Down
3 changes: 2 additions & 1 deletion src/strategyHelpers/deploymentHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -139,7 +140,7 @@ function appendStableVersionLabelToResource(files: string[]): string[] {
export async function checkManifestStability(
kubectl: Kubectl,
resources: Resource[],
resourceType: string
resourceType: ClusterType
): Promise<void> {
await KubernetesManifestUtility.checkManifestStability(
kubectl,
Expand Down
31 changes: 28 additions & 3 deletions src/utilities/manifestStabilityUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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('')
Expand All @@ -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<ExecOutput>((resolve, reject) => {
resolve({
exitCode: 0,
stderr: '',
stdout: ''
})
})
})
await manifestStabilityUtils.checkManifestStability(
kc,
resources,
ResourceTypeManagedCluster
)

expect(checkRolloutStatusSpy).toHaveBeenCalled()
expect(spy).toHaveReturned()
})
})
9 changes: 4 additions & 5 deletions src/utilities/manifestStabilityUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ 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'

export async function checkManifestStability(
kubectl: Kubectl,
resources: Resource[],
resourceType: string
clusterTyper: ClusterType
): Promise<void> {
// 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
Expand Down

0 comments on commit 3d107b0

Please sign in to comment.