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

Added support for load_balancer_profile #277

Merged
merged 13 commits into from
Dec 13, 2022

Conversation

mazilu88
Copy link
Contributor

@mazilu88 mazilu88 commented Nov 21, 2022

Describe your changes

Added support for load_balancer_profile

Issue number

#274

Checklist before requesting a review

  • The pr title can be used to describe what this pr did in CHANGELOG.md file
  • I have executed pre-commit on my machine
  • I have passed pr-check on my machine

Thanks for your cooperation!

@mazilu88
Copy link
Contributor Author

@microsoft-github-policy-service agree

main.tf Outdated Show resolved Hide resolved
variables.tf Outdated
type = bool
description = "(Optional) A load_balancer_profile block. This can only be specified when load_balancer_sku is set to standard."
default = null
nullable = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: if the default is null you can omit the nullable = true.
asking @lonegunmanb for confirmation on this style issue

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, could you change the default to false here?

main.tf Outdated Show resolved Hide resolved
@zioproto
Copy link
Collaborator

@lonegunmanb can we please start the E2E tests for this PR ? it looks good for testing

General Question: what is the best option to test this functionality in the E2E tests ? should we patch an existing one or creating a new one to test just this feature ?

Thanks

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Hello @mazilu88, thanks for opening this pr. I've some comments for you, and most of your new added variables are for the locad_balancer_profile block, could we add a locad_balancer_profile_ prefix to all these variables' name? For example, the nat_gateway_profile block also has an argument named idle_timeout_in_minutes, once we want to support this nat_gateway_profile block we might meet a conflict with this pr.

Another thought is whether we should use an object type for load_balancer_profile variable and include all related variables as it's fields. The cons of this object solution is, we cannot write clear descriptions for the object's fields.

We can add prefix to there variables' names, or we can make them an object with the help of Optional Object Type Attributes, and that would require Terraform 1.3+.

variables.tf Outdated
type = bool
description = "(Optional) A load_balancer_profile block. This can only be specified when load_balancer_sku is set to standard."
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, could you change the default to false here?

variables.tf Outdated
@@ -216,6 +223,24 @@ variable "kubernetes_version" {
default = null
}

variable "load_balancer_profile" {
Copy link
Member

Choose a reason for hiding this comment

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

Would load_balancer_enabled be better here?

variables.tf Outdated
@@ -216,6 +223,24 @@ variable "kubernetes_version" {
default = null
}

variable "load_balancer_profile" {
type = bool
description = "(Optional) A load_balancer_profile block. This can only be specified when load_balancer_sku is set to standard."
Copy link
Member

Choose a reason for hiding this comment

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

This bool variable doesn't seem like a block, could we change a better description here?
Could we also add a precondition block in aks resource to enforce this pre condition?

variables.tf Outdated

variable "load_balancer_sku" {
type = string
description = "(Optional) Specifies the SKU of the Load Balancer used for this Kubernetes Cluster. Possible values are basic and standard. Defaults to standard."
Copy link
Member

Choose a reason for hiding this comment

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

According to the provider code the load_balancer_sku argument is a ForceNew argument, which means that if we change this variable's value, the aks cluster would be re-created. The official document need to be upgrade, could we append Changing this forces a new kubernetes cluster to be created. to the description?

variables.tf Outdated

validation {
condition = var.load_balancer_sku == "basic" || var.load_balancer_sku == "standard"
error_message = "Possible values are basic and standard"
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 change the error message to the following code?:

error_message = "Possible values are `basic` and `standard`"

variables.tf Outdated
type = number
description = "(Optional) Number of desired SNAT port for each VM in the clusters load balancer. Must be between 0 and 64000 inclusive. Defaults to 0"
default = 0
nullable = false
Copy link
Member

Choose a reason for hiding this comment

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

According to the provider schema, the outbound_ports_allocated is optional, which means we could set it to null here.

variables.tf Outdated

variable "outbound_ports_allocated" {
type = number
description = "(Optional) Number of desired SNAT port for each VM in the clusters load balancer. Must be between 0 and 64000 inclusive. Defaults to 0"
Copy link
Member

Choose a reason for hiding this comment

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

We also need to backquote the number as the official document did here.

variables.tf Outdated
default = "standard"

validation {
condition = var.load_balancer_sku == "basic" || var.load_balancer_sku == "standard"
Copy link
Member

Choose a reason for hiding this comment

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

Would the following code be better?:

condition = contains(["basic", "standard"], var.load_balancer_sku)

variables.tf Outdated
@@ -172,6 +172,13 @@ variable "identity_type" {
}
}

variable "idle_timeout_in_minutes" {
type = number
description = "(Optional) Desired outbound flow idle timeout in minutes for the cluster load balancer. Must be between 4 and 120 inclusive."
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 backquote the number as official document did here? And I think we should declare the default value in the description too.

variables.tf Outdated
type = number
description = "(Optional) Desired outbound flow idle timeout in minutes for the cluster load balancer. Must be between 4 and 120 inclusive."
default = 30
nullable = false
Copy link
Member

Choose a reason for hiding this comment

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

According to the provider schema, the idle_timeout_in_minutes argument is optional, which means we can set it to null.

@mazilu88
Copy link
Contributor Author

Hello @lonegunmanb. Thank you for the review. I hope I understood all the recommendations correctly and made the appropriate changes.

The only thing I skipped was the precondition. Is it really needed if we check prior to enabling the profile with this?

for_each = var.enable_load_balancer_profile == true && var.load_balancer_sku == "standard" ? ["load_balancer_profile"] : []

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mazilu88 for this update, almost LGTM but some tiny suggestions.

variables.tf Outdated
@@ -143,6 +143,12 @@ variable "enable_host_encryption" {
default = false
}

variable "enable_load_balancer_profile" {
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 rename this variable to load_balancer_profile_enabled since now in AzureRM provider we're following such naming convention? Now there're many legacy variables with enable_xxx name but we'd like to keep them to keep backward compatible, but for new variables we`d like to follow the latest naming convention. Thanks!

variables.tf Outdated
variable "enable_load_balancer_profile" {
type = bool
description = "(Optional) Enable a load_balancer_profile block. This can only be used when load_balancer_sku is set to `standard`."
default = false
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to restrict this variable as nullable = false since I don't think anyone should set this variable to null.

main.tf Outdated
network_policy = var.network_policy
outbound_type = var.net_profile_outbound_type
pod_cidr = var.net_profile_pod_cidr
service_cidr = var.net_profile_service_cidr

dynamic "load_balancer_profile" {
for_each = var.enable_load_balancer_profile == true && var.load_balancer_sku == "standard" ? ["load_balancer_profile"] : []
Copy link
Member

Choose a reason for hiding this comment

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

Since the var.enable_load_balancer_profile should not be null, could we simplify the expression to the following code?:

for_each = var.enable_load_balancer_profile && var.load_balancer_sku == "standard" ? ["load_balancer_profile"] : []

variables.tf Outdated
type = number
description = "(Optional) Desired outbound flow idle timeout in minutes for the cluster load balancer. Must be between `4` and `120` inclusive."
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

nullable is default to true so I think we could just omit this expression here.

variables.tf Outdated
type = number
description = "(Optional) Count of desired managed outbound IPs for the cluster load balancer. Must be between `1` and `100` inclusive"
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

nullable is default to true so I think we could just omit this expression here.

variables.tf Outdated
type = number
description = "(Optional) The desired number of IPv6 outbound IPs created and managed by Azure for the cluster load balancer. Must be in the range of `1` to `100` (inclusive). The default value is `0` for single-stack and `1` for dual-stack. Note: managed_outbound_ipv6_count requires dual-stack networking. To enable dual-stack networking the Preview Feature Microsoft.ContainerService/AKS-EnableDualStack needs to be enabled and the Resource Provider re-registered, see the documentation for more information. https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%!C(MISSING)kubectl#register-the-aks-enabledualstack-preview-feature"
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

nullable is default to true so I think we could just omit this expression here.

variables.tf Outdated
type = set(string)
description = "(Optional) The ID of the Public IP Addresses which should be used for outbound communication for the cluster load balancer."
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

nullable is default to true so I think we could just omit this expression here.

variables.tf Outdated
type = set(string)
description = "(Optional) The ID of the outbound Public IP Address Prefixes which should be used for the cluster load balancer."
default = null
nullable = true
Copy link
Member

Choose a reason for hiding this comment

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

nullable is default to true so I think we could just omit this expression here.

variables.tf Outdated
variable "load_balancer_profile_outbound_ports_allocated" {
type = number
description = "(Optional) Number of desired SNAT port for each VM in the clusters load balancer. Must be between `0` and `64000` inclusive. Defaults to `0`"
default = null
Copy link
Member

Choose a reason for hiding this comment

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

According to the document, I would suggest that we could set the default to 0 here.

variables.tf Outdated Show resolved Hide resolved
@lonegunmanb
Copy link
Member

Hello @lonegunmanb. Thank you for the review. I hope I understood all the recommendations correctly and made the appropriate changes.

The only thing I skipped was the precondition. Is it really needed if we check prior to enabling the profile with this?

for_each = var.enable_load_balancer_profile == true && var.load_balancer_sku == "standard" ? ["load_balancer_profile"] : []

@mazilu88 I'd like to have this precondition since if we set load_balancer_sku to basic and enable_load_balancer_profile, that should be a misconfiguration and should be rejected explicitly, the current design would just swallow this misconfiguration and omit the load balancer block, which might confuse our users.

@mazilu88
Copy link
Contributor Author

mazilu88 commented Dec 5, 2022

I have added the precondition

@mazilu88 mazilu88 temporarily deployed to acctests December 7, 2022 09:05 — with GitHub Actions Inactive
Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mazilu88 for the update, we've passed almost all checks, only one description issue, once we've fixed it we're good to merge.

variables.tf Outdated

variable "load_balancer_profile_managed_outbound_ipv6_count" {
type = number
description = "(Optional) The desired number of IPv6 outbound IPs created and managed by Azure for the cluster load balancer. Must be in the range of `1` to `100` (inclusive). The default value is `0` for single-stack and `1` for dual-stack. Note: managed_outbound_ipv6_count requires dual-stack networking. To enable dual-stack networking the Preview Feature Microsoft.ContainerService/AKS-EnableDualStack needs to be enabled and the Resource Provider re-registered, see the documentation for more information. https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%!!(MISSING)C(MISSING)kubectl#register-the-aks-enabledualstack-preview-feature"
Copy link
Member

Choose a reason for hiding this comment

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

It seems like some typos in the description's tail:

...https://docs.microsoft.com/azure/aks/configure-kubenet-dual-stack?tabs=azure-cli%!!(MISSING)C(MISSING)kubectl#register-the-aks-enabledualstack-preview-feature

@mazilu88
Copy link
Contributor Author

mazilu88 commented Dec 8, 2022

Thank you again for the review @lonegunmanb. It was a copy-paste issue when rendering the results of tflint on my machine.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Potential Breaking Changes in db53a41:
[update] "Variables.log_analytics_workspace_resource_group_name.Nullable" from 'true' to ''
[update] "Variables.log_analytics_solution_id.Nullable" from 'true' to ''
[update] "Variables.log_analytics_workspace.Nullable" from 'true' to ''

@zioproto
Copy link
Collaborator

What is the purpose of commit db53a41 ?

@lonegunmanb I have seen this also in other PRs, it seems contributors are trying to address some tflint change that was introduced in the CI ?

@lonegunmanb
Copy link
Member

What is the purpose of commit db53a41 ?

@lonegunmanb I have seen this also in other PRs, it seems contributors are trying to address some tflint change that was introduced in the CI ?

Hi @zioproto , the variable's nullable is default to true so we don't need to declare it explicitly, I've upgrade our tflint plugin to scan for such issue so we don't need to address them in our code review anymore, the pr-check would do the job.

@mazilu88 mazilu88 temporarily deployed to acctests December 13, 2022 03:11 — with GitHub Actions Inactive
Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mazilu88 , LGTM! 🚀

@lonegunmanb lonegunmanb merged commit 533fb2c into Azure:master Dec 13, 2022
@zioproto zioproto mentioned this pull request Dec 19, 2022
1 task
@mazilu88 mazilu88 deleted the feat/load_balancer_profile branch January 15, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants