mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-30 00:51:14 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 634c143449 |
@@ -2,5 +2,6 @@ node_modules
|
|||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
|
lib/
|
||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [5.0.3] - 2025-04-16
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- #398 case-insensitive resource type
|
|
||||||
|
|
||||||
## [5.0.2] - 2025-04-15
|
## [5.0.2] - 2025-04-15
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
-17991
File diff suppressed because it is too large
Load Diff
+17
-4
@@ -13,15 +13,17 @@ import {
|
|||||||
} from '../strategyHelpers/deploymentHelper'
|
} from '../strategyHelpers/deploymentHelper'
|
||||||
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
||||||
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod'
|
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod'
|
||||||
import {ClusterType} from '../inputUtils'
|
|
||||||
export const ResourceTypeManagedCluster =
|
export const ResourceTypeManagedCluster =
|
||||||
'Microsoft.ContainerService/managedClusters'
|
'Microsoft.ContainerService/managedClusters'
|
||||||
export const ResourceTypeFleet = 'Microsoft.ContainerService/fleets'
|
export const ResourceTypeFleet = 'Microsoft.ContainerService/fleets'
|
||||||
|
export type ClusterType =
|
||||||
|
| typeof ResourceTypeManagedCluster
|
||||||
|
| typeof ResourceTypeFleet
|
||||||
|
|
||||||
export async function deploy(
|
export async function deploy(
|
||||||
kubectl: Kubectl,
|
kubectl: Kubectl,
|
||||||
manifestFilePaths: string[],
|
manifestFilePaths: string[],
|
||||||
deploymentStrategy: DeploymentStrategy,
|
deploymentStrategy: DeploymentStrategy
|
||||||
resourceType: ClusterType
|
|
||||||
) {
|
) {
|
||||||
// update manifests
|
// update manifests
|
||||||
const inputManifestFiles: string[] = updateManifestFiles(manifestFilePaths)
|
const inputManifestFiles: string[] = updateManifestFiles(manifestFilePaths)
|
||||||
@@ -43,6 +45,8 @@ export async function deploy(
|
|||||||
|
|
||||||
// check manifest stability
|
// check manifest stability
|
||||||
core.startGroup('Checking manifest stability')
|
core.startGroup('Checking manifest stability')
|
||||||
|
const resourceTypeInput =
|
||||||
|
core.getInput('resource-type') || ResourceTypeManagedCluster
|
||||||
const resourceTypes: Resource[] = getResources(
|
const resourceTypes: Resource[] = getResources(
|
||||||
deployedManifestFiles,
|
deployedManifestFiles,
|
||||||
models.DEPLOYMENT_TYPES.concat([
|
models.DEPLOYMENT_TYPES.concat([
|
||||||
@@ -50,7 +54,16 @@ export async function deploy(
|
|||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
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()
|
core.endGroup()
|
||||||
|
|
||||||
// print ingresses
|
// print ingresses
|
||||||
|
|||||||
+14
-9
@@ -38,20 +38,19 @@ import {
|
|||||||
TrafficSplitMethod
|
TrafficSplitMethod
|
||||||
} from '../types/trafficSplitMethod'
|
} from '../types/trafficSplitMethod'
|
||||||
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy'
|
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy'
|
||||||
import {ClusterType} from '../inputUtils'
|
import {ResourceTypeFleet, ResourceTypeManagedCluster} from './deploy'
|
||||||
|
|
||||||
export async function promote(
|
export async function promote(
|
||||||
kubectl: Kubectl,
|
kubectl: Kubectl,
|
||||||
manifests: string[],
|
manifests: string[],
|
||||||
deploymentStrategy: DeploymentStrategy,
|
deploymentStrategy: DeploymentStrategy
|
||||||
resourceType: ClusterType
|
|
||||||
) {
|
) {
|
||||||
switch (deploymentStrategy) {
|
switch (deploymentStrategy) {
|
||||||
case DeploymentStrategy.CANARY:
|
case DeploymentStrategy.CANARY:
|
||||||
await promoteCanary(kubectl, manifests)
|
await promoteCanary(kubectl, manifests)
|
||||||
break
|
break
|
||||||
case DeploymentStrategy.BLUE_GREEN:
|
case DeploymentStrategy.BLUE_GREEN:
|
||||||
await promoteBlueGreen(kubectl, manifests, resourceType)
|
await promoteBlueGreen(kubectl, manifests)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw Error('Invalid promote deployment strategy')
|
throw Error('Invalid promote deployment strategy')
|
||||||
@@ -141,11 +140,7 @@ async function promoteCanary(kubectl: Kubectl, manifests: string[]) {
|
|||||||
core.endGroup()
|
core.endGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function promoteBlueGreen(
|
async function promoteBlueGreen(kubectl: Kubectl, manifests: string[]) {
|
||||||
kubectl: Kubectl,
|
|
||||||
manifests: string[],
|
|
||||||
resourceType: ClusterType
|
|
||||||
) {
|
|
||||||
// update container images and pull secrets
|
// update container images and pull secrets
|
||||||
const inputManifestFiles: string[] = updateManifestFiles(manifests)
|
const inputManifestFiles: string[] = updateManifestFiles(manifests)
|
||||||
const manifestObjects: BlueGreenManifests =
|
const manifestObjects: BlueGreenManifests =
|
||||||
@@ -172,6 +167,8 @@ async function promoteBlueGreen(
|
|||||||
|
|
||||||
// checking stability of newly created deployments
|
// checking stability of newly created deployments
|
||||||
core.startGroup('Checking manifest stability')
|
core.startGroup('Checking manifest stability')
|
||||||
|
const resourceType =
|
||||||
|
core.getInput('resource-type') || ResourceTypeManagedCluster
|
||||||
const deployedManifestFiles = deployResult.manifestFiles
|
const deployedManifestFiles = deployResult.manifestFiles
|
||||||
const resources: Resource[] = getResources(
|
const resources: Resource[] = getResources(
|
||||||
deployedManifestFiles,
|
deployedManifestFiles,
|
||||||
@@ -179,6 +176,14 @@ async function promoteBlueGreen(
|
|||||||
models.DiscoveryAndLoadBalancerResource.SERVICE
|
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(
|
await KubernetesManifestUtility.checkManifestStability(
|
||||||
kubectl,
|
kubectl,
|
||||||
resources,
|
resources,
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
import {parseResourceTypeInput} from './inputUtils'
|
|
||||||
import {
|
|
||||||
ClusterType,
|
|
||||||
ResourceTypeFleet,
|
|
||||||
ResourceTypeManagedCluster
|
|
||||||
} from './actions/deploy'
|
|
||||||
|
|
||||||
describe('InputUtils', () => {
|
|
||||||
describe('parseResourceTypeInput', () => {
|
|
||||||
it('should extract fleet exact match resource type', () => {
|
|
||||||
expect(
|
|
||||||
parseResourceTypeInput('Microsoft.ContainerService/fleets')
|
|
||||||
).toEqual(ResourceTypeFleet)
|
|
||||||
})
|
|
||||||
it('should match fleet case-insensitively', () => {
|
|
||||||
expect(
|
|
||||||
parseResourceTypeInput('Microsoft.containerservice/fleets')
|
|
||||||
).toEqual(ResourceTypeFleet)
|
|
||||||
})
|
|
||||||
it('should match managed cluster case-insensitively', () => {
|
|
||||||
expect(
|
|
||||||
parseResourceTypeInput('Microsoft.containerservice/MAnaGedClusterS')
|
|
||||||
).toEqual(ResourceTypeManagedCluster)
|
|
||||||
})
|
|
||||||
it('should error on unexpected values', () => {
|
|
||||||
expect(() => {
|
|
||||||
parseResourceTypeInput('icrosoft.ContainerService/ManagedCluster')
|
|
||||||
}).toThrow()
|
|
||||||
expect(() => {
|
|
||||||
parseResourceTypeInput('wrong-value')
|
|
||||||
}).toThrow()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {parseAnnotations} from './types/annotations'
|
import {parseAnnotations} from './types/annotations'
|
||||||
import {ResourceTypeFleet, ResourceTypeManagedCluster} from './actions/deploy'
|
|
||||||
|
|
||||||
export const inputAnnotations = parseAnnotations(
|
export const inputAnnotations = parseAnnotations(
|
||||||
core.getInput('annotations', {required: false})
|
core.getInput('annotations', {required: false})
|
||||||
@@ -15,18 +14,3 @@ export function getBufferTime(): number {
|
|||||||
|
|
||||||
return inputBufferTime
|
return inputBufferTime
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseResourceTypeInput(rawInput: string): ClusterType {
|
|
||||||
switch (rawInput.toLowerCase()) {
|
|
||||||
case ResourceTypeFleet.toLowerCase():
|
|
||||||
return ResourceTypeFleet
|
|
||||||
case ResourceTypeManagedCluster.toLowerCase():
|
|
||||||
return ResourceTypeManagedCluster
|
|
||||||
}
|
|
||||||
throw new Error(
|
|
||||||
`Invalid resource type: ${rawInput}. Supported resource types are: ${ResourceTypeManagedCluster} (default), ${ResourceTypeFleet}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
export type ClusterType =
|
|
||||||
| typeof ResourceTypeManagedCluster
|
|
||||||
| typeof ResourceTypeFleet
|
|
||||||
|
|||||||
+3
-19
@@ -1,18 +1,12 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {getKubectlPath, Kubectl} from './types/kubectl'
|
import {getKubectlPath, Kubectl} from './types/kubectl'
|
||||||
import {
|
import {deploy} from './actions/deploy'
|
||||||
deploy,
|
|
||||||
ResourceTypeFleet,
|
|
||||||
ResourceTypeManagedCluster
|
|
||||||
} from './actions/deploy'
|
|
||||||
import {ClusterType} from './inputUtils'
|
|
||||||
import {promote} from './actions/promote'
|
import {promote} from './actions/promote'
|
||||||
import {reject} from './actions/reject'
|
import {reject} from './actions/reject'
|
||||||
import {Action, parseAction} from './types/action'
|
import {Action, parseAction} from './types/action'
|
||||||
import {parseDeploymentStrategy} from './types/deploymentStrategy'
|
import {parseDeploymentStrategy} from './types/deploymentStrategy'
|
||||||
import {getFilesFromDirectoriesAndURLs} from './utilities/fileUtils'
|
import {getFilesFromDirectoriesAndURLs} from './utilities/fileUtils'
|
||||||
import {PrivateKubectl} from './types/privatekubectl'
|
import {PrivateKubectl} from './types/privatekubectl'
|
||||||
import {parseResourceTypeInput} from './inputUtils'
|
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
// verify kubeconfig is set
|
// verify kubeconfig is set
|
||||||
@@ -42,16 +36,6 @@ export async function run() {
|
|||||||
const resourceName = core.getInput('name') || ''
|
const resourceName = core.getInput('name') || ''
|
||||||
const skipTlsVerify = core.getBooleanInput('skip-tls-verify')
|
const skipTlsVerify = core.getBooleanInput('skip-tls-verify')
|
||||||
|
|
||||||
let resourceType: ClusterType
|
|
||||||
try {
|
|
||||||
// included in the trycatch to allow raw input to go out of scope after parsing
|
|
||||||
const resourceTypeInput = core.getInput('resource-type')
|
|
||||||
resourceType = parseResourceTypeInput(resourceTypeInput)
|
|
||||||
} catch (e) {
|
|
||||||
core.setFailed(e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const kubectl = isPrivateCluster
|
const kubectl = isPrivateCluster
|
||||||
? new PrivateKubectl(
|
? new PrivateKubectl(
|
||||||
kubectlPath,
|
kubectlPath,
|
||||||
@@ -65,11 +49,11 @@ export async function run() {
|
|||||||
// run action
|
// run action
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case Action.DEPLOY: {
|
case Action.DEPLOY: {
|
||||||
await deploy(kubectl, fullManifestFilePaths, strategy, resourceType)
|
await deploy(kubectl, fullManifestFilePaths, strategy)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case Action.PROMOTE: {
|
case Action.PROMOTE: {
|
||||||
await promote(kubectl, fullManifestFilePaths, strategy, resourceType)
|
await promote(kubectl, fullManifestFilePaths, strategy)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case Action.REJECT: {
|
case Action.REJECT: {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
} from '../utilities/githubUtils'
|
} from '../utilities/githubUtils'
|
||||||
import {getDeploymentConfig} from '../utilities/dockerUtils'
|
import {getDeploymentConfig} from '../utilities/dockerUtils'
|
||||||
import {DeployResult} from '../types/deployResult'
|
import {DeployResult} from '../types/deployResult'
|
||||||
import {ClusterType} from '../inputUtils'
|
import {ClusterType} from '../actions/deploy'
|
||||||
|
|
||||||
export async function deployManifests(
|
export async function deployManifests(
|
||||||
files: string[],
|
files: string[],
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import * as KubernetesConstants from '../types/kubernetesTypes'
|
|||||||
import {Kubectl, Resource} from '../types/kubectl'
|
import {Kubectl, Resource} from '../types/kubectl'
|
||||||
import {checkForErrors} from './kubectlUtils'
|
import {checkForErrors} from './kubectlUtils'
|
||||||
import {sleep} from './timeUtils'
|
import {sleep} from './timeUtils'
|
||||||
import {ResourceTypeFleet} from '../actions/deploy'
|
import {ClusterType, ResourceTypeFleet} from '../actions/deploy'
|
||||||
import {ClusterType} from '../inputUtils'
|
|
||||||
|
|
||||||
const IS_SILENT = false
|
const IS_SILENT = false
|
||||||
const POD = 'pod'
|
const POD = 'pod'
|
||||||
@@ -12,10 +11,10 @@ const POD = 'pod'
|
|||||||
export async function checkManifestStability(
|
export async function checkManifestStability(
|
||||||
kubectl: Kubectl,
|
kubectl: Kubectl,
|
||||||
resources: Resource[],
|
resources: Resource[],
|
||||||
resourceType: ClusterType
|
clusterTyper: ClusterType
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Skip if resource type is microsoft.containerservice/fleets
|
// Skip if resource type is microsoft.containerservice/fleets
|
||||||
if (resourceType === ResourceTypeFleet) {
|
if (clusterTyper === ResourceTypeFleet) {
|
||||||
core.info(`Skipping checkManifestStability for ${ResourceTypeFleet}`)
|
core.info(`Skipping checkManifestStability for ${ResourceTypeFleet}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user