Skip to content

Commit

Permalink
feat: Add support for setting a different CNI config on cilium cluste…
Browse files Browse the repository at this point in the history
…rs (#5482)
  • Loading branch information
santhoshmprabhu authored Jan 10, 2025
1 parent 3041708 commit d415be3
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 3 deletions.
2 changes: 2 additions & 0 deletions parts/windows/kuberneteswindowssetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ $global:NetworkPlugin = "{{GetParameter "networkPlugin"}}"
$global:VNetCNIPluginsURL = "{{GetParameter "vnetCniWindowsPluginsURL"}}"
$global:IsDualStackEnabled = {{if IsIPv6DualStackFeatureEnabled}}$true{{else}}$false{{end}}
$global:IsAzureCNIOverlayEnabled = {{if IsAzureCNIOverlayFeatureEnabled}}$true{{else}}$false{{end}}
$global:CiliumDataplaneEnabled = {{if CiliumDataplaneEnabled}}$true{{else}}$false{{end}}

# Kubelet credential provider
$global:CredentialProviderURL = "{{GetParameter "windowsCredentialProviderURL"}}"
Expand Down Expand Up @@ -398,6 +399,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
3 changes: 3 additions & 0 deletions pkg/agent/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ func getContainerServiceFuncMap(config *datamodel.NodeBootstrappingConfiguration
"IsAzureCNIOverlayFeatureEnabled": func() bool {
return cs.Properties.OrchestratorProfile.KubernetesConfig.IsUsingNetworkPluginMode("overlay")
},
"CiliumDataplaneEnabled": func() bool {
return cs.Properties.OrchestratorProfile.KubernetesConfig.EbpfDataplane == datamodel.EbpfDataplane_cilium
},
"GetBase64EncodedEnvironmentJSON": func() string {
customEnvironmentJSON, _ := cs.Properties.GetCustomEnvironmentJSON(false)
return base64.StdEncoding.EncodeToString([]byte(customEnvironmentJSON))
Expand Down
17 changes: 17 additions & 0 deletions pkg/agent/datamodel/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ type KubernetesAddon struct {
Data string `json:"data,omitempty"`
}

// EbpfDataplane controls the eBPF networking dataplane.
type EbpfDataplane int32

const (
// none means don't install an eBPF dataplane.
EbpfDataplane_none EbpfDataplane = 0
// cilium means use Cilium as the eBPF dataplane.
EbpfDataplane_cilium EbpfDataplane = 1
// unspecified means the cx didn't provide a value.
// This is used only during validation / defaulting, never written to the database.
EbpfDataplane_unspecified EbpfDataplane = 3
// invalid means the cx provided a value that isn't an enum in the API version.
// This will always be rejected by validation (and therefore never written to the database).
EbpfDataplane_invalid EbpfDataplane = 4
)

// KubernetesConfig contains the Kubernetes config structure, containing Kubernetes specific configuration.
type KubernetesConfig struct {
KubernetesImageBase string `json:"kubernetesImageBase,omitempty"`
Expand Down Expand Up @@ -678,6 +694,7 @@ type KubernetesConfig struct {
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount,omitempty"`
PrivateAzureRegistryServer string `json:"privateAzureRegistryServer,omitempty"`
NetworkPluginMode string `json:"networkPluginMode,omitempty"`
EbpfDataplane EbpfDataplane `json:"ebpfDataplane,omitempty"`
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = "https://acs-mirror.azureedge.net/cloud-provider-azure/v1.29.0/binaries/azure-acr-credential-provider-windows-amd64-v1.29.0.tar.gz"
Expand Down Expand Up @@ -394,6 +395,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -394,6 +395,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S116/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S117/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S118/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+K8S119/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = "https://acs-mirror.azureedge.net/cloud-provider-azure/v1.29.7/binaries/azure-acr-credential-provider-windows-amd64-v1.29.7.tar.gz"
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
2 changes: 2 additions & 0 deletions pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = ""
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ $global:NetworkPlugin = "azure"
$global:VNetCNIPluginsURL = "https://acs-mirror.azureedge.net/azure-cni/v1.1.3/binaries/azure-vnet-cni-singletenancy-windows-amd64-v1.1.3.zip"
$global:IsDualStackEnabled = $false
$global:IsAzureCNIOverlayEnabled = $false
$global:CiliumDataplaneEnabled = $false

# Kubelet credential provider
$global:CredentialProviderURL = "https://acs-mirror.azureedge.net/cloud-provider-azure/v1.29.0/binaries/azure-acr-credential-provider-windows-amd64-v1.29.0.tar.gz"
Expand Down Expand Up @@ -388,6 +389,7 @@ try
-VNetCIDR $global:VNetCIDR `
-IsDualStackEnabled $global:IsDualStackEnabled `
-IsAzureCNIOverlayEnabled $global:IsAzureCNIOverlayEnabled


if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
Expand Down
8 changes: 7 additions & 1 deletion staging/cse/windows/azurecnifunc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ function Set-AzureCNIConfig
[Parameter(Mandatory=$false)][bool]
$IsAzureCNIOverlayEnabled
)
Logs-To-Event -TaskName "AKS.WindowsCSE.SetAzureCNIConfig" -TaskMessage "Start to set Azure CNI config. IsDualStackEnabled: $global:IsDualStackEnabled, IsAzureCNIOverlayEnabled: $global:IsAzureCNIOverlayEnabled, IsDisableWindowsOutboundNat: $global:IsDisableWindowsOutboundNat"
Logs-To-Event -TaskName "AKS.WindowsCSE.SetAzureCNIConfig" -TaskMessage "Start to set Azure CNI config. IsDualStackEnabled: $global:IsDualStackEnabled, IsAzureCNIOverlayEnabled: $global:IsAzureCNIOverlayEnabled, IsDisableWindowsOutboundNat: $global:IsDisableWindowsOutboundNat, CiliumDataplaneEnabled: $global:CiliumDataplaneEnabled"

$fileName = [Io.path]::Combine("$AzureCNIConfDir", "10-azure.conflist")
$configJson = Get-Content $fileName | ConvertFrom-Json
$configJson.plugins.dns.Nameservers[0] = $KubeDnsServiceIp
$configJson.plugins.dns.Search[0] = $KubeDnsSearchPath

if (Test-Path variable:global:CiliumDataplaneEnabled) {
if($global:CiliumDataplaneEnabled) {
$configJson.plugins.ipam.type = "azure-cns"
}
}

if ($global:IsDisableWindowsOutboundNat) {
# Replace OutBoundNAT with LoopbackDSR for IMDS acess if AKS cluster disabled Windows OutBoundNAT.
Expand Down
24 changes: 22 additions & 2 deletions staging/cse/windows/azurecnifunc.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Describe 'Set-AzureCNIConfig' {
$isDualStackEnabled = $false
$KubeDnsServiceIp = "10.0.0.10"
$global:IsDisableWindowsOutboundNat = $false
$global:CiliumDataplaneEnabled = $false
$global:KubeproxyFeatureGates = @("WinDSR=true")
$azureCNIConfigFile = [Io.path]::Combine($azureCNIConfDir, "10-azure.conflist")

Expand All @@ -55,8 +56,27 @@ Describe 'Set-AzureCNIConfig' {
}
}

Context 'WinDSR is enabled by default' {
It "Should remove ROUTE" {
Context 'Cilium (ebpf dataplane) is enabled' {
It "Should use azure-cns as IPAM" {
Set-Default-AzureCNI "AzureCNI.Default.conflist"

$global:CiliumDataplaneEnabled = $true
Set-AzureCNIConfig -AzureCNIConfDir $azureCNIConfDir `
-KubeDnsSearchPath $kubeDnsSearchPath `
-KubeClusterCIDR $kubeClusterCIDR `
-KubeServiceCIDR $kubeServiceCIDR `
-VNetCIDR $vNetCIDR `
-IsDualStackEnabled $isDualStackEnabled

$actualConfigJson = Read-Format-Json $azureCNIConfigFile
$expectedConfigJson = Read-Format-Json ([Io.path]::Combine($azureCNIConfDir, "AzureCNI.Expect.CiliumNodeSubnet.conflist"))
$difference = Compare-Object $actualConfigJson $expectedConfigJson
$difference | Should -Be $null
}
}

Context 'WinDSR is enabled, ebpf dataplane disabled by default' {
It "Should remove ROUTE and use azure-vnet-ipam for IPAM" {
Set-Default-AzureCNI "AzureCNI.Default.conflist"

Set-AzureCNIConfig -AzureCNIConfDir $azureCNIConfDir `
Expand Down
Loading

0 comments on commit d415be3

Please sign in to comment.