Skip to content

Commit

Permalink
feat: Kube-Flux - Added features of carml contribution (#625)
Browse files Browse the repository at this point in the history
# Description

> This is a follow up to:
Azure/ResourceModules#4142

<details>
<summary>The current version of flux configuration 2022-03-01 doesn't
add Postbuild substitution variables</summary>
Updated Microsoft.KubernetesConfiguration/fluxConfigurations to version
2023-05-01
</details>

> Please include a summary of the change and which issue is fixed.

Updated Microsoft.KubernetesConfiguration/fluxConfigurations to version
2023-05-01 and added postBuild section in common main.test.bicep.

> Please also include the context.

The current version 2022-03-01 doesn't add Postbuild substitution
variables which are included in the Bicep configuration. We have tested
these by running the common/main.test.bicep with 2 postBuild substitute
variables with values foo and bar and they don't appear in the
Kustomization in AKS. Please see snippet below which is a result of
running 'kubectl describe kustomization fluxaakcfccom001-unified -n
flux-system'


![image](https://github.com/Azure/ResourceModules/assets/39670555/edfefa45-69a9-419f-8c8e-54be71acc945)

We have updated the API version to 2023-05-01 which renders the expected
results. Please see snippet below which is a result of running 'kubectl
describe kustomization fluxaakcfccom001-unified -n flux-system'


![image](https://github.com/Azure/ResourceModules/assets/39670555/e5d6a060-6729-4054-ae8a-34d7bb02a64f)

This is a feature we require to correctly configure our Flux
configuration.

| Pipeline |
| - |
|
[![avm.res.kubernetes-configuration.flux-configuration](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.flux-configuration.yml/badge.svg?branch=users%2Falsehr%2FkubeContr)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.flux-configuration.yml)
|
|
[![avm.res.kubernetes-configuration.extension](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.extension.yml/badge.svg?branch=users%2Falsehr%2FkubeContr)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.extension.yml)
|

There are no dependencies


- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Update to documentation

## Checklist

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [ ] My corresponding pipelines / checks run clean and green without
any errors or warnings
- [x] My code follows the style guidelines of this project
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation (readme)
- [x] I did format my code

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored Nov 16, 2023
1 parent 218cf9f commit 68f7e41
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
28 changes: 24 additions & 4 deletions avm/res/kubernetes-configuration/flux-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This module deploys a Kubernetes Configuration Flux Configuration.

| Resource Type | API Version |
| :-- | :-- |
| `Microsoft.KubernetesConfiguration/fluxConfigurations` | [2022-03-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.KubernetesConfiguration/2022-03-01/fluxConfigurations) |
| `Microsoft.KubernetesConfiguration/fluxConfigurations` | [2023-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.KubernetesConfiguration/fluxConfigurations) |

## Usage examples

Expand Down Expand Up @@ -61,7 +61,11 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
timeoutInSeconds: 180
url: 'https://github.com/mspnp/aks-baseline'
}
kustomizations: '<kustomizations>'
kustomizations: {
unified: {
path: './cluster-manifests'
}
}
location: '<location>'
}
}
Expand Down Expand Up @@ -111,7 +115,11 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
}
},
"kustomizations": {
"value": "<kustomizations>"
"value": {
"unified": {
"path": "./cluster-manifests"
}
}
},
"location": {
"value": "<location>"
Expand Down Expand Up @@ -158,6 +166,12 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
dependsOn: []
force: false
path: './cluster-manifests'
postBuild: {
substitute: {
TEST_VAR1: 'foo'
TEST_VAR2: 'bar'
}
}
prune: true
syncIntervalInSeconds: 300
timeoutInSeconds: 300
Expand Down Expand Up @@ -217,6 +231,12 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
"dependsOn": [],
"force": false,
"path": "./cluster-manifests",
"postBuild": {
"substitute": {
"TEST_VAR1": "foo",
"TEST_VAR2": "bar"
}
},
"prune": true,
"syncIntervalInSeconds": 300,
"timeoutInSeconds": 300
Expand Down Expand Up @@ -351,6 +371,7 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`clusterName`](#parameter-clustername) | string | The name of the AKS cluster that should be configured. |
| [`kustomizations`](#parameter-kustomizations) | object | Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster. |
| [`name`](#parameter-name) | string | The name of the Flux Configuration. |
| [`namespace`](#parameter-namespace) | string | The namespace to which this configuration is installed to. Maximum of 253 lower case alphanumeric characters, hyphen and period only. |
| [`scope`](#parameter-scope) | string | Scope at which the configuration will be installed. |
Expand All @@ -369,7 +390,6 @@ module fluxConfiguration 'br/public:avm/res/kubernetes-configuration/flux-config
| :-- | :-- | :-- |
| [`configurationProtectedSettings`](#parameter-configurationprotectedsettings) | secureObject | Key-value pairs of protected configuration settings for the configuration. |
| [`enableTelemetry`](#parameter-enabletelemetry) | bool | Enable/Disable usage telemetry for module. |
| [`kustomizations`](#parameter-kustomizations) | object | Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster. |
| [`location`](#parameter-location) | string | Location for all resources. |
| [`suspend`](#parameter-suspend) | bool | Whether this configuration should suspend its reconciliation of its kustomizations and sources. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ param configurationProtectedSettings object?
@description('Conditional. Parameters to reconcile to the GitRepository source kind type. Required if `sourceKind` is `GitRepository`.')
param gitRepository object?

@description('Optional. Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster.')
@description('Required. Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster.')
param kustomizations object?

@description('Required. The namespace to which this configuration is installed to. Maximum of 253 lower case alphanumeric characters, hyphen and period only.')
Expand All @@ -48,7 +48,7 @@ param sourceKind string
param suspend bool = false

resource avmTelemetry 'Microsoft.Resources/deployments@2023-07-01' = if (enableTelemetry) {
name: '46d3xbcp.res.kubernetesconfiguration-extension.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
name: '46d3xbcp.res.kubernetesconfiguration-fluxconfig.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
Expand All @@ -69,7 +69,7 @@ resource managedCluster 'Microsoft.ContainerService/managedClusters@2022-07-01'
name: clusterName
}

resource fluxConfiguration 'Microsoft.KubernetesConfiguration/fluxConfigurations@2022-03-01' = {
resource fluxConfiguration 'Microsoft.KubernetesConfiguration/fluxConfigurations@2023-05-01' = {
name: name
scope: managedCluster
properties: {
Expand Down
8 changes: 4 additions & 4 deletions avm/res/kubernetes-configuration/flux-configuration/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.23.1.45101",
"templateHash": "13420454476526931427"
"templateHash": "12231512467754753013"
},
"name": "Kubernetes Configuration Flux Configurations",
"description": "This module deploys a Kubernetes Configuration Flux Configuration.",
Expand Down Expand Up @@ -64,7 +64,7 @@
"type": "object",
"nullable": true,
"metadata": {
"description": "Optional. Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster."
"description": "Required. Array of kustomizations used to reconcile the artifact pulled by the source type on the cluster."
}
},
"namespace": {
Expand Down Expand Up @@ -106,7 +106,7 @@
"condition": "[parameters('enableTelemetry')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2023-07-01",
"name": "[format('46d3xbcp.res.kubernetesconfiguration-extension.{0}.{1}', replace('-..--..-', '.', '-'), substring(uniqueString(deployment().name, parameters('location')), 0, 4))]",
"name": "[format('46d3xbcp.res.kubernetesconfiguration-fluxconfig.{0}.{1}', replace('-..--..-', '.', '-'), substring(uniqueString(deployment().name, parameters('location')), 0, 4))]",
"properties": {
"mode": "Incremental",
"template": {
Expand All @@ -130,7 +130,7 @@
},
"fluxConfiguration": {
"type": "Microsoft.KubernetesConfiguration/fluxConfigurations",
"apiVersion": "2022-03-01",
"apiVersion": "2023-05-01",
"scope": "[format('Microsoft.ContainerService/managedClusters/{0}', parameters('clusterName'))]",
"name": "[parameters('name')]",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
timeoutInSeconds: 180
url: 'https://github.com/mspnp/aks-baseline'
}
kustomizations: {
unified: {
path: './cluster-manifests'
}
}
// Workaround for PSRule
bucket: null
kustomizations: null
configurationProtectedSettings: null
}
}]
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ module testDeployment '../../../main.bicep' = [for iteration in [ 'init', 'idem'
prune: true
syncIntervalInSeconds: 300
timeoutInSeconds: 300
postBuild: {
substitute: {
TEST_VAR1: 'foo'
TEST_VAR2: 'bar'
}
}
}
}
// Workaround for PSRule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/bicep-registry-module-version-file-schema#",
"version": "0.2",
"version": "0.3",
"pathFilters": [
"./main.json"
]
Expand Down

0 comments on commit 68f7e41

Please sign in to comment.