-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kubernetes_cluster
-pod_cidrs
/service_cidrs
#16657
kubernetes_cluster
-pod_cidrs
/service_cidrs
#16657
Conversation
kubernetes_cluster
supports namespace_resources_enabled
/pod_cidrs
/service_cidrs
kubernetes_cluster
-namespace_resources_enabled
/pod_cidrs
/service_cidrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR @heiazuo.
I can't seem to find any docs on Namespace Resources. The test fails because the preview feature isn't enabled on the subscription. Registering it doesn't seem to work - usually when a preview feature is being registered I see the state as Registering
but in this case it's stuck on Pending
$ az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/EnableNamespaceResourcesPreview')].{Name:name,State:properties.state}"
Name State
---------------------------------------------------------- -------
Microsoft.ContainerService/EnableNamespaceResourcesPreview Pending
@@ -624,6 +624,62 @@ func TestAccKubernetesCluster_oidcIssuer(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestAccKubernetesCluster_namespace(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to
func TestAccKubernetesCluster_namespace(t *testing.T) { | |
func TestAccKubernetesCluster_namespaceToggle(t *testing.T) { |
}) | ||
} | ||
|
||
func (KubernetesClusterResource) namespaceEnabled(data acceptance.TestData, enabled bool) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this to
func (KubernetesClusterResource) namespaceEnabled(data acceptance.TestData, enabled bool) string { | |
func (KubernetesClusterResource) namespace(data acceptance.TestData, enabled bool) string { |
@@ -134,6 +134,8 @@ In addition, one of either `identity` or `service_principal` blocks must be spec | |||
|
|||
-> **Note:** This requires that the Preview Feature `Microsoft.ContainerService/AKS-AzureDefender` is enabled, see [the documentation](https://docs.microsoft.com/azure/defender-for-cloud/defender-for-containers-enable?tabs=aks-deploy-portal%2Ck8s-deploy-asc%2Ck8s-verify-asc%2Ck8s-remove-arc%2Caks-removeprofile-api&pivots=defender-for-container-aks) for more information. | |||
|
|||
* `namespace_resources_enabled` - (Optional) It can be enabled/disabled on creation and updation of the managed cluster. The default value is false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `namespace_resources_enabled` - (Optional) It can be enabled/disabled on creation and updation of the managed cluster. The default value is false. | |
* `namespace_resources_enabled` - (Optional) Specifies whether Namespace Resources should be enabled. Defaults to `false`. |
@@ -515,8 +517,12 @@ A `network_profile` block supports the following: | |||
|
|||
* `pod_cidr` - (Optional) The CIDR to use for pod IP addresses. This field can only be set when `network_plugin` is set to `kubenet`. Changing this forces a new resource to be created. | |||
|
|||
* `pod_cidrs` - (Optional) One IPv4 CIDR is expected for single-stack networking. Two CIDRs, one for each IP family (IPv4/IPv6), is expected for dual-stack networking. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `pod_cidrs` - (Optional) One IPv4 CIDR is expected for single-stack networking. Two CIDRs, one for each IP family (IPv4/IPv6), is expected for dual-stack networking. Changing this forces a new resource to be created. | |
* `pod_cidrs` - (Optional) A list of CIDRs to use for pod IP addresses. For single-stack networking a single IPv4 CIDR is expected. For dual-stack networking an IPv4 and IPv6 CIDR are expected. Changing this forces a new resource to be created. |
* `service_cidr` - (Optional) The Network Range used by the Kubernetes service. Changing this forces a new resource to be created. | ||
|
||
* `service_cidrs` - (Optional) One IPv4 CIDR is expected for single-stack networking. Two CIDRs, one for each IP family (IPv4/IPv6), is expected for dual-stack networking. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `service_cidrs` - (Optional) One IPv4 CIDR is expected for single-stack networking. Two CIDRs, one for each IP family (IPv4/IPv6), is expected for dual-stack networking. Changing this forces a new resource to be created. | |
* `service_cidrs` - (Optional) A list of CIDRs to use for Kubernetes services. For single-stack networking a single IPv4 CIDR is expected. For dual-stack networking an IPv4 and IPv6 CIDR are expected. Changing this forces a new resource to be created. |
…etesCluster_namespaceToggle`
Hi @stephybun - It seems |
Hi @stephybun - Just confirmed with service team, this feature is not ready to be exposed. @heiazuo , would you please help remove this property? |
kubernetes_cluster
-namespace_resources_enabled
/pod_cidrs
/service_cidrs
kubernetes_cluster
-pod_cidrs
/service_cidrs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more question, what happens if both service_cidr and service_cidrs or pod_cidr and pod_cidrs are supplied, does the API accept that?
Hi @stephybun, user can not set service_cidr and service_cidrs at the same time, we have validation function to check: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience @qiqingzhang, left a few more suggestions in-line, would you mind taking a look at them? Thanks!
|
||
// Azure network plugin is not compatible with pod_cidr | ||
if podCidr != "" && networkPlugin == "azure" { | ||
return fmt.Errorf("`pod_cidr` and `azure` cannot be set together") | ||
} | ||
|
||
// if not All empty values or All set values. | ||
if !(dockerBridgeCidr == "" && dnsServiceIP == "" && serviceCidr == "") && !(dockerBridgeCidr != "" && dnsServiceIP != "" && serviceCidr != "") { | ||
if !(dockerBridgeCidr == "" && dnsServiceIP == "" && !isCidrset) && !(dockerBridgeCidr != "" && dnsServiceIP != "" && isCidrset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation makes sure that docker_bridge_cidr
, dns_service_ip
and service_cidr
are either all set or empty rather than preventing the user from setting both service_cidr
/service_cidrs
and pod_cidr
/pod_cidrs
. In any case after trying this out it is indeed possible to set both _cidr
and _cidrs
.
However it seems this validation may no longer be relevant or needed since AKS no longer supports docker for the container runtime (see #18119). Could you please update the validation here while you're at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About depreciating docker_bridge_cidr
, I think it's better to make another PR for it.
@@ -1800,6 +1831,70 @@ resource "azurerm_kubernetes_cluster" "test" { | |||
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, enablePrivateCluster, data.RandomInteger) | |||
} | |||
|
|||
func (KubernetesClusterResource) podCidrs(data acceptance.TestData) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a test case where we're providing both an IPv4 and IPv6 address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
Hi @stephybun , I've added a commit to update this PR, and it allows user to supply both service_cidr and service_cidrs or pod_cidr and pod_cidrs. |
network_profile { | ||
network_plugin = "kubenet" | ||
pod_cidrs = ["10.1.1.0/24", "2002::1234:abcd:ffff:c0a8:101/120"] | ||
ip_versions = ["IPv4", "IPv6"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming this needs to be set in order to be able to provide both an IPv4 and IPv6 address? In which case we should probably add some validation in the create method to inform users as well as a note in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've added that info in the doc. But I think maybe leave the complicated validation to the service side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service side error message isn't particularly descriptive. AKS is complex enough as it is, so it would be beneficial to the users if we returned a more informative message such as
fmt.Errorf("dual-stack networking must be enabled and ip_versions must be set to [IPv4, IPv6] in order to specify multiple %s", field")
Can you please add that in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I misunderstood, it's not necessary to set ip_versions = ["IPv4", "IPv6"]
in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by order but the test TestAccKubernetesCluster_serviceCidrsDualStack
will fail if ip_versions
isn't set to ["IPv4", "IPv6"], this is what we should add validation for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I'll test it and add this validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @stephybun , I just tried, it still works.
resource "azurerm_kubernetes_cluster" "test" {
name = "henglu96"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "henglu96"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
network_profile {
network_plugin = "kubenet"
dns_service_ip = "10.1.1.10"
docker_bridge_cidr = "172.18.0.1/16"
service_cidrs = ["10.1.1.0/24", "2002::1234:abcd:ffff:c0a8:101/120"]
ip_versions = ["IPv6", "IPv4"] // Please notice here
}
identity {
type = "SystemAssigned"
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ms-henglu, the order of the arguments IPv4
/IPv6
is irrelevant here. If a user supplies the following configuration
network_profile {
network_plugin = "kubenet"
dns_service_ip = "10.1.1.10"
docker_bridge_cidr = "172.18.0.1/16"
service_cidrs = ["10.1.1.0/24", "2002::1234:abcd:ffff:c0a8:101/120"]
ip_versions = ["IPv4"] // <---- Only one ip family
}
It won't be accepted by the API
{
"code": "InvalidNetworkingConfig",
"message": "Service CIDRs do not match IP families.",
"subcode": "",
"target": "networkProfile.serviceCIDRs"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I'll add validation for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephybun , I've added this check, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ms-henglu and @qiqingzhang, LGTM 🌈
This functionality has been released in v3.26.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
public pr for
kubernetes_cluster
supports pod_cidrs/service_cidrstest result after update:
TestAccKubernetesCluster_serviceCidrs:

TestAccKubernetesCluster_podCidrs:
