Gallery › Kubernetes › Azure built-in policies
Configure installation of Flux extension on Kubernetes cluster
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Install Flux extension on Kubernetes cluster to enable deployment of 'fluxconfigurations' in the cluster
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDeploy-GitOps-Flux2-Extension-to-Kubernetes-cluster_DINE.json · 261 lines
{
"properties": {
"displayName": "Configure installation of Flux extension on Kubernetes cluster",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Install Flux extension on Kubernetes cluster to enable deployment of 'fluxconfigurations' in the cluster",
"metadata": {
"version": "1.0.0",
"category": "Kubernetes"
},
"version": "1.0.0",
"parameters": {
"helmControllerEnabled": {
"type": "Boolean",
"metadata": {
"displayName": "Enable Flux Helm Controller",
"description": "Flag to enable or disable the Helm controller. Set to false if you don't need Helm support. Learn more: https://aka.ms/flux-extension-management"
},
"defaultValue": true
},
"notificationControllerEnabled": {
"type": "Boolean",
"metadata": {
"displayName": "Enable Flux Notification Controller",
"description": "Flag to enable or disable the Notification controller. Set to false if you don't need to use the Notification controller. Learn more: https://aka.ms/flux-extension-management"
},
"defaultValue": true
},
"imageAutomationController": {
"type": "Boolean",
"metadata": {
"displayName": "Enable Flux Image Automation Controller",
"description": "Flag to enable or disable the Image Automation controller. Set to true if you need Image Automation controller. Learn more: https://aka.ms/flux-extension-management"
},
"defaultValue": false
},
"imageReflectorController": {
"type": "Boolean",
"metadata": {
"displayName": "Enable Flux Image Reflector Controller",
"description": "Flag to enable or disable the Image Reflector controller. Set to true if you need to use the Image Reflector controller. Learn more: https://aka.ms/flux-extension-management"
},
"defaultValue": false
},
"releaseTrain": {
"type": "String",
"metadata": {
"displayName": "Release Train",
"description": "The release train this extension participates in for auto-upgrade if autoUpgradeMinorVersion is 'true'."
},
"allowedValues": [
"Stable"
],
"defaultValue": "Stable"
},
"autoUpgradeMinorVersion": {
"type": "Boolean",
"metadata": {
"displayName": "Auto Upgrade Minor Version",
"description": "Flag to control if this extension participates in auto upgrade of minor version or not."
},
"defaultValue": true
},
"version": {
"type": "String",
"metadata": {
"displayName": "Version",
"description": "Indicate a specific version you want to install, otherwise leave blank. autoUpgradeMinorVersion must be 'false'."
},
"defaultValue": ""
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"in": [
"Microsoft.Kubernetes/connectedClusters",
"Microsoft.ContainerService/managedClusters"
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.KubernetesConfiguration/extensions",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.KubernetesConfiguration/extensions/extensionType",
"equals": "microsoft.flux"
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/provisioningState",
"equals": "Succeeded"
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/releaseTrain",
"equals": "[parameters('releaseTrain')]"
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/autoUpgradeMinorVersion",
"equals": "[parameters('autoUpgradeMinorVersion')]"
},
{
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.KubernetesConfiguration/extensions/autoUpgradeMinorVersion",
"equals": "false"
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/version",
"equals": "[parameters('version')]"
}
]
},
{
"field": "Microsoft.KubernetesConfiguration/extensions/autoUpgradeMinorVersion",
"equals": "true"
}
]
}
]
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"type": "string"
},
"clusterResourceType": {
"type": "string"
},
"helmControllerEnabled": {
"type": "bool"
},
"notificationControllerEnabled": {
"type": "bool"
},
"imageAutomationController": {
"type": "bool"
},
"imageReflectorController": {
"type": "bool"
},
"releaseTrain": {
"type": "string"
},
"autoUpgradeMinorVersion": {
"type": "bool"
},
"version": {
"type": "string"
}
},
"resources": [
{
"condition": "[contains(toLower(parameters('clusterResourceType')), toLower('connectedclusters'))]",
"comments": "Install the Flux extension in the connected (ARC) cluster.",
"type": "Microsoft.KubernetesConfiguration/extensions",
"name": "flux",
"apiVersion": "2022-03-01",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"extensionType": "microsoft.flux",
"releaseTrain": "[parameters('releaseTrain')]",
"autoUpgradeMinorVersion": "[parameters('autoUpgradeMinorVersion')]",
"version": "[if(and(not(empty(parameters('version'))), not(parameters('autoUpgradeMinorVersion'))), parameters('version'), json('null'))]",
"configurationSettings": {
"helm-controller.enabled": "[parameters('helmControllerEnabled')]",
"notification-controller.enabled": "[parameters('notificationControllerEnabled')]",
"image-automation-controller.enabled": "[parameters('imageAutomationController')]",
"image-reflector-controller.enabled": "[parameters('imageReflectorController')]"
}
},
"scope": "[concat('Microsoft.Kubernetes/connectedClusters/',parameters('clusterName'))]"
},
{
"condition": "[contains(toLower(parameters('clusterResourceType')), toLower('managedclusters'))]",
"comments": "Install the Flux extension in the managed (AKS) cluster.",
"type": "Microsoft.KubernetesConfiguration/extensions",
"name": "flux",
"apiVersion": "2022-03-01",
"properties": {
"extensionType": "microsoft.flux",
"releaseTrain": "[parameters('releaseTrain')]",
"autoUpgradeMinorVersion": "[parameters('autoUpgradeMinorVersion')]",
"version": "[if(and(not(empty( parameters('version'))), not(parameters('autoUpgradeMinorVersion'))), parameters('version'), json('null'))]",
"configurationSettings": {
"helm-controller.enabled": "[parameters('helmControllerEnabled')]",
"notification-controller.enabled": "[parameters('notificationControllerEnabled')]",
"image-automation-controller.enabled": "[parameters('imageAutomationController')]",
"image-reflector-controller.enabled": "[parameters('imageReflectorController')]"
}
},
"scope": "[concat('Microsoft.ContainerService/managedClusters/',parameters('clusterName'))]"
}
]
},
"parameters": {
"clusterName": {
"value": "[field('name')]"
},
"clusterResourceType": {
"value": "[field('type')]"
},
"helmControllerEnabled": {
"value": "[parameters('helmControllerEnabled')]"
},
"notificationControllerEnabled": {
"value": "[parameters('notificationControllerEnabled')]"
},
"imageAutomationController": {
"value": "[parameters('imageAutomationController')]"
},
"imageReflectorController": {
"value": "[parameters('imageReflectorController')]"
},
"releaseTrain": {
"value": "[parameters('releaseTrain')]"
},
"autoUpgradeMinorVersion": {
"value": "[parameters('autoUpgradeMinorVersion')]"
},
"version": {
"value": "[parameters('version')]"
}
}
}
}
}
}
},
"versions": [
"1.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/f9175d5f-abc8-1dc3-bd3c-5d7476ada3d1",
"name": "f9175d5f-abc8-1dc3-bd3c-5d7476ada3d1"
}Bylawf9175d5f-abc8-1dc3-bd3c-5d7476ada3d1.bylaw.ps1 · 94 lines
# Converted from Deploy-GitOps-Flux2-Extension-to-Kubernetes-cluster_DINE.json by ConvertTo-Bylaw.
Policy 'f9175d5f-abc8-1dc3-bd3c-5d7476ada3d1' {
Properties @{
DisplayName = 'Configure installation of Flux extension on Kubernetes cluster'
Description = 'Install Flux extension on Kubernetes cluster to enable deployment of ''fluxconfigurations'' in the cluster'
Version = '1.0.0'
Category = 'Kubernetes'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter HelmControllerEnabled @{
Type = 'Boolean'
Default = $true
DisplayName = 'Enable Flux Helm Controller'
Description = 'Flag to enable or disable the Helm controller. Set to false if you don''t need Helm support. Learn more: https://aka.ms/flux-extension-management'
}
Parameter NotificationControllerEnabled @{
Type = 'Boolean'
Default = $true
DisplayName = 'Enable Flux Notification Controller'
Description = 'Flag to enable or disable the Notification controller. Set to false if you don''t need to use the Notification controller. Learn more: https://aka.ms/flux-extension-management'
}
Parameter ImageAutomationController @{
Type = 'Boolean'
Default = $false
DisplayName = 'Enable Flux Image Automation Controller'
Description = 'Flag to enable or disable the Image Automation controller. Set to true if you need Image Automation controller. Learn more: https://aka.ms/flux-extension-management'
}
Parameter ImageReflectorController @{
Type = 'Boolean'
Default = $false
DisplayName = 'Enable Flux Image Reflector Controller'
Description = 'Flag to enable or disable the Image Reflector controller. Set to true if you need to use the Image Reflector controller. Learn more: https://aka.ms/flux-extension-management'
}
Parameter ReleaseTrain @{
AllowedValues = @('Stable')
Default = 'Stable'
DisplayName = 'Release Train'
Description = 'The release train this extension participates in for auto-upgrade if autoUpgradeMinorVersion is ''true''.'
}
Parameter AutoUpgradeMinorVersion @{
Type = 'Boolean'
Default = $true
DisplayName = 'Auto Upgrade Minor Version'
Description = 'Flag to control if this extension participates in auto upgrade of minor version or not.'
}
Parameter Version @{
Default = ''
DisplayName = 'Version'
Description = 'Indicate a specific version you want to install, otherwise leave blank. autoUpgradeMinorVersion must be ''false''.'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource * {
Require 'type is not one of 2 values' {
Field type | Must -Not -BeIn @('Microsoft.Kubernetes/connectedClusters', 'Microsoft.ContainerService/managedClusters') -IfPresent
}
}
DeployIfNotExists 'Microsoft.KubernetesConfiguration/extensions' -Role 'Contributor' -Effect (Param Effect) {
Require 'extensionType, provisioningState, releaseTrain and 2 more are as required' {
Field extensionType | Must -Be 'microsoft.flux'
Field provisioningState | Must -Be 'Succeeded'
Field releaseTrain | Must -Be (Param ReleaseTrain)
Field autoUpgradeMinorVersion | Must -Be (Param AutoUpgradeMinorVersion)
AnyOf {
AllOf {
Field autoUpgradeMinorVersion | Must -Be 'false'
Field version | Must -Be (Param Version)
}
Field autoUpgradeMinorVersion | Must -Be 'true'
}
}
Deployment -TemplateFile './templates/f9175d5f-abc8-1dc3-bd3c-5d7476ada3d1.json' -Parameters ([ordered]@{
clusterName = (Arm '[field(''name'')]')
clusterResourceType = (Arm '[field(''type'')]')
helmControllerEnabled = (Param HelmControllerEnabled)
notificationControllerEnabled = (Param NotificationControllerEnabled)
imageAutomationController = (Param ImageAutomationController)
imageReflectorController = (Param ImageReflectorController)
releaseTrain = (Param ReleaseTrain)
autoUpgradeMinorVersion = (Param AutoUpgradeMinorVersion)
version = (Param Version)
})
}
}Its deployment templates are written beside it:
templates/f9175d5f-abc8-1dc3-bd3c-5d7476ada3d1.json
Source: built-in-policies/policyDefinitions/Kubernetes/Deploy-GitOps-Flux2-Extension-to-Kubernetes-cluster_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw