Skip to content
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

Conversation

qiqingzhang
Copy link
Contributor

@qiqingzhang qiqingzhang commented May 5, 2022

public pr for kubernetes_cluster supports pod_cidrs/service_cidrs

test result after update:

TestAccKubernetesCluster_serviceCidrs:
image

TestAccKubernetesCluster_podCidrs:
image

@qiqingzhang qiqingzhang changed the title kubernetes_cluster supports namespace_resources_enabled/pod_cidrs/service_cidrs kubernetes_cluster -namespace_resources_enabled/pod_cidrs/service_cidrs May 11, 2022
Copy link
Member

@stephybun stephybun left a 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) {
Copy link
Member

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

Suggested change
func TestAccKubernetesCluster_namespace(t *testing.T) {
func TestAccKubernetesCluster_namespaceToggle(t *testing.T) {

})
}

func (KubernetesClusterResource) namespaceEnabled(data acceptance.TestData, enabled bool) string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this to

Suggested change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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.

@ms-henglu
Copy link
Contributor

Hi @stephybun - It seems Microsoft.ContainerService/EnableNamespaceResourcesPreview needs to be manually approved, I'll contact service team see if this is a private preview feature.

@ms-henglu
Copy link
Contributor

Hi @stephybun - Just confirmed with service team, this feature is not ready to be exposed.

@heiazuo , would you please help remove this property?

@github-actions github-actions bot added size/M and removed size/L labels Jun 1, 2022
@qiqingzhang qiqingzhang changed the title kubernetes_cluster -namespace_resources_enabled/pod_cidrs/service_cidrs kubernetes_cluster -pod_cidrs/service_cidrs Jun 1, 2022
Copy link
Member

@stephybun stephybun left a 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?

@qiqingzhang
Copy link
Contributor Author

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:
validateKubernetesCluster

Copy link
Member

@stephybun stephybun left a 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) {
Copy link
Member

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?

Copy link
Contributor

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 {
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@ms-henglu
Copy link
Contributor

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"]
Copy link
Member

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?

Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

@stephybun stephybun Sep 6, 2022

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.

Copy link
Contributor

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.

Copy link
Contributor

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"
  }
}

Copy link
Member

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"
}

Copy link
Contributor

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.

Copy link
Contributor

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!

Copy link
Member

@stephybun stephybun left a 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 🌈

@stephybun stephybun merged commit 1307680 into hashicorp:main Oct 6, 2022
@github-actions github-actions bot added this to the v3.26.0 milestone Oct 6, 2022
stephybun added a commit that referenced this pull request Oct 6, 2022
@github-actions
Copy link

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!

@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants