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

azurerm_kubernetes_cluster - support for upgrade_override_setting property #27962

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

hqhqhqhqhqhqhqhqhqhqhq
Copy link
Contributor

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

Support for upgrade_override_setting property in azurerm_kubernetes_cluster.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_resource - support for the thing1 property [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

feat: implement upgrade settings for container service

Revert "feat: implement upgrade settings for container service"
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"effective_until": {
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the guideline suggestions, we may make it a top level property.

Finally there are instances where the addtional fields/properties for a object/feature are optional or few in number, as shown below.
Example C.
```go
type ManagedClusterStorageProfileDiskCSIDriver struct {
Enabled *bool `json:"enabled,omitempty"`
Version *string `json:"version,omitempty"`
}
```
In cases like these one option is to flatten the block into two top level properties:

Copy link
Collaborator

@WodansSon WodansSon Nov 22, 2024

Choose a reason for hiding this comment

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

@wuxu92, totally agree with you here, however it appears that not all of the possible fields have been exposed here as well based on the REST API documentation for this property. We should also drop the _settings part from the name of the exposed field in the provider, also per the contributing guide. 🙂

  • For blocks avoid redundant words in the name that don't add informational value e.g.

firewall_properties can be shortened to firewall, the same can apply to individual properties e.g. email_address to email.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only other field in the block is forceUpgrade as a boolean, which doesn't need to be exposed. So we may only need to expose one property named upgrade_override_until and keep the expand/flatten logic as it is now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am hesistant to add this as a top level as service team indicated there may be additional properties relevant to upgrade_override_setting added later. We may, in future, need to wrap around these properties a layer down in upgrade_override_setting as it doesn't make sense to expose all of them in top level.

I will update the naming to upgrade_override.

@wuxu92 @WodansSon

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @hqhqhqhqhqhqhqhqhqhqhq - this looks mostly good, but I have questions on the schema design and the testing approach if you can take a look?

Comment on lines 1453 to 1466
"upgrade_override_setting": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"effective_until": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.IsRFC3339Time,
},
},
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Is this the only configurable property in this block? If so, it might be worth flattening this down to a single property, for example upgrade_override_until?

What happens to this value when the specified point in time passes, is it removed from the response, or still returned?

Should we also validate that the supplied time is in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jackofallops

  1. There is only one property that user should configure, but service team indicated more may be added later.
  2. When the value is in the past in time, it will stay in the response
  3. I prefer not to add this check because if the time is in the past, users don't need to update it every single time; they can leave it as is (and it will not have any impact).

if isUpgradeOverrideSettingEnabled {
upgradeOverrideSetting = `
upgrade_override_setting {
effective_until = "2024-01-01T00:00:00Z"
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to be testing a time in the past here? It's unlikely this will be representative of user input? Could we generate a value for this based on time.Now() plus some realistic duration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@hqhqhqhqhqhqhqhqhqhqhq
Copy link
Contributor Author

Hi @jackofallops @WodansSon
Thank you for review, I have made updates according to requested and changes and ready for re-review.
Please take another look when available and let me know anythings to change, thanks!

Also reran the test:
image

@WodansSon
Copy link
Collaborator

@hqhqhqhqhqhqhqhqhqhqhq, Thanks for pushing those changes, this LGTM 🚀

@andyliuliming
Copy link
Contributor

when will this merge?

@hqhqhqhqhqhqhqhqhqhqhq
Copy link
Contributor Author

hqhqhqhqhqhqhqhqhqhqhq commented Dec 16, 2024 via email

@github-actions github-actions bot added size/L and removed size/M labels Jan 20, 2025
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@hqhqhqhqhqhqhqhqhqhqhq , thanks for pushing those changes. This looks pretty good, one last suggestion in the documentation, after that's fix I think this PR will be good to go! 🚀

website/docs/r/kubernetes_cluster.html.markdown Outdated Show resolved Hide resolved
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

So sorry, I missed this one in the last review. 😞

website/docs/r/kubernetes_cluster.html.markdown Outdated Show resolved Hide resolved
WodansSon
WodansSon previously approved these changes Jan 22, 2025
Copy link
Collaborator

@WodansSon WodansSon 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 pushing those changes @hqhqhqhqhqhqhqhqhqhqhq . This LGTM now! 🚀

@WodansSon
Copy link
Collaborator

All of the tests are failing, if you can fix those up that would be great!

image

@WodansSon
Copy link
Collaborator

Some tests are still failing, but they are also failing in main:

image

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@hqhqhqhqhqhqhqhqhqhqhq , this is getting very close, however I have left a couple of new comments I would like to see addressed. Once that is done, and the tests pass. I think this should be good to go and get merged! 🚀

if d.HasChange("upgrade_override") {
upgradeOverrideSettingRaw := d.Get("upgrade_override").([]interface{})

err = validateKubernetesClusterUpgradeOverrideSetting(d.GetChange("upgrade_override"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make more sense to put this logic inline rather than in a helper function to be more consistent with the other resources in the provider? I might be wrong but I believe this is the only place this function is called, so to me it would make more sense to make that logic inline, here in the update fuction, to be more readable for future maintainers is they need to modify this code.


newOverrideSetting, canConvert := new.([]interface{})
if !canConvert || len(newOverrideSetting) == 0 {
return fmt.Errorf("upgrade_override cannot be unset")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here...

Suggested change
return fmt.Errorf("upgrade_override cannot be unset")
return fmt.Errorf("`upgrade_override` cannot be unset")

@@ -2531,6 +2568,19 @@ func resourceKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}
return resourceKubernetesClusterRead(d, meta)
}

func validateKubernetesClusterUpgradeOverrideSetting(_, new interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this function and make it inline in the update function? I think we should be able to use something like d.GetRawConfig so we could compare the old values of the fields against the new values of the fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to inline function, but left it as d.Get("upgrade_override") rather than d.GetRawConfig because it is easier to work with the expand function below (easier to parse to []interface{}).

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

One last thing, it appears the annotation for Notes has a new contributor docs guideline page dedicated to it so I added one more comment to address this in this PR as well. 🙂

website/docs/r/kubernetes_cluster.html.markdown Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants