diff --git a/.github/workflows/ms.kubernetesconfiguration.fluxconfigurations.yml b/.github/workflows/ms.kubernetesconfiguration.fluxconfigurations.yml index a4f242ea2b..663fa61d5a 100644 --- a/.github/workflows/ms.kubernetesconfiguration.fluxconfigurations.yml +++ b/.github/workflows/ms.kubernetesconfiguration.fluxconfigurations.yml @@ -106,8 +106,7 @@ jobs: - name: 'Using test file [${{ matrix.moduleTestFilePaths }}]' uses: ./.github/actions/templates/validateModuleDeployment with: - templateFilePath: '${{ env.modulePath }}/deploy.bicep' - parameterFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' + templateFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' location: '${{ env.location }}' resourceGroupName: '${{ env.resourceGroupName }}' subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}' diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/dependencies.bicep b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/dependencies.bicep new file mode 100644 index 0000000000..d35586edf5 --- /dev/null +++ b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/dependencies.bicep @@ -0,0 +1,49 @@ +@description('Optional. The location to deploy resources to.') +param location string = resourceGroup().location + +@description('Required. The name of the AKS cluster to create.') +param clusterName string + +@description('Required. The name of the AKS cluster extension to create.') +param clusterExtensionName string + +@description('Required. The name of the AKS cluster nodes resource group to create.') +param clusterNodeResourceGroupName string + +resource cluster 'Microsoft.ContainerService/managedClusters@2022-06-01' = { + name: clusterName + location: location + identity: { + type: 'SystemAssigned' + } + properties: { + dnsPrefix: clusterName + nodeResourceGroup: clusterNodeResourceGroupName + agentPoolProfiles: [ + { + name: 'agentpool' + count: 1 + vmSize: 'Standard_DS2_v2' + osType: 'Linux' + mode: 'System' + } + ] + } +} + +resource extension 'Microsoft.KubernetesConfiguration/extensions@2022-03-01' = { + scope: cluster + name: clusterExtensionName + properties: { + extensionType: 'microsoft.flux' + releaseTrain: 'Stable' + scope: { + cluster: { + releaseNamespace: 'flux-system' + } + } + } +} + +@description('The name of the created AKS cluster.') +output clusterName string = cluster.name diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/deploy.test.bicep b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..4355a51707 --- /dev/null +++ b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/common/deploy.test.bicep @@ -0,0 +1,70 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.kubernetesconfiguration.fluxconfigurations-${serviceShort}-rg' + +@description('Optional. The location to deploy resources to.') +param location string = deployment().location + +@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.') +param serviceShort string = 'kcfccom' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +module resourceGroupResources 'dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-paramNested' + params: { + clusterName: 'dep-carml-aks-${serviceShort}' + clusterExtensionName: '<>${serviceShort}001' + clusterNodeResourceGroupName: 'nodes-${resourceGroupName}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + clusterName: resourceGroupResources.outputs.clusterName + namespace: 'flux-system' + scope: 'cluster' + sourceKind: 'GitRepository' + gitRepository: { + repositoryRef: { + branch: 'main' + } + sshKnownHosts: '' + syncIntervalInSeconds: 300 + timeoutInSeconds: 180 + url: 'https://github.com/mspnp/aks-baseline' + } + kustomizations: { + unified: { + dependsOn: [] + force: false + path: './cluster-manifests' + prune: true + syncIntervalInSeconds: 300 + timeoutInSeconds: 300 + } + } + } +} diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min.parameters.json b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min.parameters.json deleted file mode 100644 index 201ac22b6b..0000000000 --- a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min.parameters.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "flux2" - }, - "scope": { - "value": "cluster" - }, - "clusterName": { - "value": "<>-az-aks-kubenet-001" - }, - "namespace": { - "value": "flux-system" - }, - "sourceKind": { - "value": "GitRepository" - }, - "gitRepository": { - "value": { - "url": "https://github.com/mspnp/aks-baseline", - "timeoutInSeconds": 180, - "syncIntervalInSeconds": 300, - "repositoryRef": { - "branch": "main" - }, - "sshKnownHosts": "" - } - } - } -} diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/dependencies.bicep b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/dependencies.bicep new file mode 100644 index 0000000000..d35586edf5 --- /dev/null +++ b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/dependencies.bicep @@ -0,0 +1,49 @@ +@description('Optional. The location to deploy resources to.') +param location string = resourceGroup().location + +@description('Required. The name of the AKS cluster to create.') +param clusterName string + +@description('Required. The name of the AKS cluster extension to create.') +param clusterExtensionName string + +@description('Required. The name of the AKS cluster nodes resource group to create.') +param clusterNodeResourceGroupName string + +resource cluster 'Microsoft.ContainerService/managedClusters@2022-06-01' = { + name: clusterName + location: location + identity: { + type: 'SystemAssigned' + } + properties: { + dnsPrefix: clusterName + nodeResourceGroup: clusterNodeResourceGroupName + agentPoolProfiles: [ + { + name: 'agentpool' + count: 1 + vmSize: 'Standard_DS2_v2' + osType: 'Linux' + mode: 'System' + } + ] + } +} + +resource extension 'Microsoft.KubernetesConfiguration/extensions@2022-03-01' = { + scope: cluster + name: clusterExtensionName + properties: { + extensionType: 'microsoft.flux' + releaseTrain: 'Stable' + scope: { + cluster: { + releaseNamespace: 'flux-system' + } + } + } +} + +@description('The name of the created AKS cluster.') +output clusterName string = cluster.name diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/deploy.test.bicep b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..aedf8e447c --- /dev/null +++ b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/min/deploy.test.bicep @@ -0,0 +1,60 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.kubernetesconfiguration.fluxconfigurations-${serviceShort}-rg' + +@description('Optional. The location to deploy resources to.') +param location string = deployment().location + +@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.') +param serviceShort string = 'kcfcmin' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +module resourceGroupResources 'dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-paramNested' + params: { + clusterName: 'dep-carml-aks-${serviceShort}' + clusterExtensionName: '<>${serviceShort}001' + clusterNodeResourceGroupName: 'nodes-${resourceGroupName}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + clusterName: resourceGroupResources.outputs.clusterName + namespace: 'flux-system' + scope: 'cluster' + sourceKind: 'GitRepository' + gitRepository: { + repositoryRef: { + branch: 'main' + } + sshKnownHosts: '' + syncIntervalInSeconds: 300 + timeoutInSeconds: 180 + url: 'https://github.com/mspnp/aks-baseline' + } + } +} diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/parameters.json b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/parameters.json deleted file mode 100644 index e6f563f7f8..0000000000 --- a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/.test/parameters.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "flux2" - }, - "scope": { - "value": "cluster" - }, - "clusterName": { - "value": "<>-az-aks-kubenet-001" - }, - "namespace": { - "value": "flux-system" - }, - "sourceKind": { - "value": "GitRepository" - }, - "gitRepository": { - "value": { - "url": "https://github.com/mspnp/aks-baseline", - "timeoutInSeconds": 180, - "syncIntervalInSeconds": 300, - "repositoryRef": { - "branch": "main" - }, - "sshKnownHosts": "" - } - }, - "kustomizations": { - "value": { - "unified": { - "path": "./cluster-manifests", - "dependsOn": [], - "timeoutInSeconds": 300, - "syncIntervalInSeconds": 300, - "prune": true, - "force": false - } - } - } - } -} diff --git a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/readme.md b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/readme.md index ad3b68f34f..105bdf0a16 100644 --- a/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/readme.md +++ b/modules/Microsoft.KubernetesConfiguration/fluxConfigurations/readme.md @@ -77,7 +77,7 @@ The following module usage examples are retrieved from the content of the files >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Min

+

Example 1: Common

@@ -85,13 +85,12 @@ The following module usage examples are retrieved from the content of the files ```bicep module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfigurations/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-FluxConfigurations' + name: '${uniqueString(deployment().name)}-test-kcfccom' params: { // Required parameters - clusterName: '<>-az-aks-kubenet-001' - name: 'flux2' + clusterName: '' + name: '<>kcfccom001' namespace: 'flux-system' - scope: 'cluster' sourceKind: 'GitRepository' // Non-required parameters gitRepository: { @@ -103,6 +102,16 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration timeoutInSeconds: 180 url: 'https://github.com/mspnp/aks-baseline' } + kustomizations: { + unified: { + dependsOn: [] + force: false + path: './cluster-manifests' + prune: true + syncIntervalInSeconds: 300 + timeoutInSeconds: 300 + } + } } } ``` @@ -121,17 +130,14 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration "parameters": { // Required parameters "clusterName": { - "value": "<>-az-aks-kubenet-001" + "value": "" }, "name": { - "value": "flux2" + "value": "<>kcfccom001" }, "namespace": { "value": "flux-system" }, - "scope": { - "value": "cluster" - }, "sourceKind": { "value": "GitRepository" }, @@ -146,6 +152,18 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration "timeoutInSeconds": 180, "url": "https://github.com/mspnp/aks-baseline" } + }, + "kustomizations": { + "value": { + "unified": { + "dependsOn": [], + "force": false, + "path": "./cluster-manifests", + "prune": true, + "syncIntervalInSeconds": 300, + "timeoutInSeconds": 300 + } + } } } } @@ -154,7 +172,7 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration

-

Example 2: Parameters

+

Example 2: Min

@@ -162,15 +180,13 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration ```bicep module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfigurations/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-FluxConfigurations' + name: '${uniqueString(deployment().name)}-test-kcfcmin' params: { // Required parameters - clusterName: '<>-az-aks-kubenet-001' - name: 'flux2' + clusterName: '' + name: '<>kcfcmin001' namespace: 'flux-system' - scope: 'cluster' sourceKind: 'GitRepository' - // Non-required parameters gitRepository: { repositoryRef: { branch: 'main' @@ -180,16 +196,6 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration timeoutInSeconds: 180 url: 'https://github.com/mspnp/aks-baseline' } - kustomizations: { - unified: { - dependsOn: [] - force: false - path: './cluster-manifests' - prune: true - syncIntervalInSeconds: 300 - timeoutInSeconds: 300 - } - } } } ``` @@ -208,21 +214,17 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration "parameters": { // Required parameters "clusterName": { - "value": "<>-az-aks-kubenet-001" + "value": "" }, "name": { - "value": "flux2" + "value": "<>kcfcmin001" }, "namespace": { "value": "flux-system" }, - "scope": { - "value": "cluster" - }, "sourceKind": { "value": "GitRepository" }, - // Non-required parameters "gitRepository": { "value": { "repositoryRef": { @@ -233,18 +235,6 @@ module fluxConfigurations './Microsoft.KubernetesConfiguration/fluxConfiguration "timeoutInSeconds": 180, "url": "https://github.com/mspnp/aks-baseline" } - }, - "kustomizations": { - "value": { - "unified": { - "dependsOn": [], - "force": false, - "path": "./cluster-manifests", - "prune": true, - "syncIntervalInSeconds": 300, - "timeoutInSeconds": 300 - } - } } } }