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

Add support for Kubernetes maintenance policy #631

Merged

Conversation

atombrella
Copy link
Contributor

I'm not too familiar with GoLang, but maybe this is a good opportunity to work a bit with it.

@atombrella atombrella marked this pull request as draft May 2, 2021 18:02
@atombrella atombrella force-pushed the kubernetes_maintenance_policy branch from 0e7d044 to a8d56ab Compare May 23, 2021 14:47
@atombrella
Copy link
Contributor Author

@scotchneat Could you please have a look to see if this is moving in the right direction? Thanks.

@scotchneat
Copy link
Contributor

Hi @atombrella, thanks for your patience. I'll take a look at it shortly.

@scotchneat
Copy link
Contributor

@atombrella I just wanted to drop an update to let you know we haven't forgotten about your contribution.

While reviewing it, I noticed some strange behavior with the tests which relate to the outdated SDK version of Terraform we're using. We're looking into this now and will likely have to wait for that to be resolved before proceeding with this change.

@atombrella
Copy link
Contributor Author

@atombrella I just wanted to drop an update to let you know we haven't forgotten about your contribution.

While reviewing it, I noticed some strange behavior with the tests which relate to the outdated SDK version of Terraform we're using. We're looking into this now and will likely have to wait for that to be resolved before proceeding with this change.

Good :) I think there's still work that needs to be done, so I'm primarily hoping for a few hints on what I'm missing. In particular, regarding the unit tests.

@atombrella atombrella force-pushed the kubernetes_maintenance_policy branch from a8d56ab to 36f8e49 Compare May 28, 2021 20:57
@atombrella atombrella marked this pull request as ready for review May 31, 2021 06:57
@ChiefMateStarbuck ChiefMateStarbuck requested a review from a team June 1, 2021 15:07
Copy link
Member

@andrewsomething andrewsomething 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 working on this! I've left a few comments and suggestions in line.

In addition to those, you'll also need to make a change to the read function to set the policy returned by the API to state:

You'll need to create a "flatten" function to do so. (More detail about what that means in one of the inline comments.) Something like this:

func flattenMaintPolicyOpts(opts *godo.KubernetesMaintenancePolicy) []map[string]interface{} {
	result := make([]map[string]interface{}, 0)
	item := make(map[string]interface{})

	item["day"] = opts.Day.String()
	item["duration"] = opts.Duration
	item["start_time"] = opts.StartTime
	result = append(result, item)

	return result
}

digitalocean/resource_digitalocean_kubernetes_cluster.go Outdated Show resolved Hide resolved
@@ -345,6 +368,8 @@ func resourceDigitalOceanKubernetesClusterUpdate(ctx context.Context, d *schema.
Tags: expandTags(d.Get("tags").(*schema.Set).List()),
AutoUpgrade: godo.Bool(d.Get("auto_upgrade").(bool)),
SurgeUpgrade: d.Get("surge_upgrade").(bool),

MaintenancePolicy: d.Get("maintenance_policy").(*godo.KubernetesMaintenancePolicy),
Copy link
Member

Choose a reason for hiding this comment

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

This also needs to call expandMaintPolicyOpts.

Also, this line above will need to updated to for the addition:

if d.HasChange("name") || d.HasChange("tags") || d.HasChange("auto_upgrade") || d.HasChange("surge_upgrade") {

The SDK has actually grown a new method recently that can make this cleaner:

https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/schema#ResourceData.HasChanges

So it can now look like:

if d.HasChanges("name", "tags", "auto_upgrade", "surge_upgrade", "maintenance_policy") {

digitalocean/resource_digitalocean_kubernetes_cluster.go Outdated Show resolved Hide resolved
@atombrella atombrella changed the title WIP Kubernetes maintenance policy Kubernetes maintenance policy Jun 2, 2021
@atombrella atombrella changed the title Kubernetes maintenance policy Add support for Kubernetes maintenance policy Jun 2, 2021
@atombrella atombrella force-pushed the kubernetes_maintenance_policy branch from 2427940 to 5d8a632 Compare June 3, 2021 13:24
Copy link
Contributor Author

@atombrella atombrella left a comment

Choose a reason for hiding this comment

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

@andrewsomething Thanks a lot for the input. I'll work a bit more with it, and then ask for a second review, so it can be merged.

digitalocean/kubernetes.go Show resolved Hide resolved
@andrewsomething
Copy link
Member

@atombrella Sounds good! Let us know if you run into any problems.

@atombrella atombrella force-pushed the kubernetes_maintenance_policy branch from 5d8a632 to 3872ff1 Compare June 5, 2021 07:24
@atombrella
Copy link
Contributor Author

@andrewsomething I opened an issue with a suggestion how to test the provider locally (and have used this trick 👍 ). I did a terraform plan on the Kubernetes example in the repository, with maintenance_policy and got back this:

      + maintenance_policy {
          + day        = "any"
          + duration   = (known after apply)
          + start_time = "05:00"
        }

So seems to work :)

On a related note, I get a warning that the empty provider block in the doks-cluster folder is not needed.

@atombrella atombrella force-pushed the kubernetes_maintenance_policy branch from 3872ff1 to 7d3cbd3 Compare June 5, 2021 15:57
Copy link
Member

@andrewsomething andrewsomething left a comment

Choose a reason for hiding this comment

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

👍 Looks great!

I did add an additional commit with some more testing and one addressing something I missed in my initial review. Specifically, maintenance_policy needs to be both Optional and Computed. As it does not have a default value, it needs to be "computed" from the API if it is not explicitly set by the user.

Thanks again for working on this!

@andrewsomething andrewsomething merged commit 2cfbc46 into digitalocean:main Jun 7, 2021
@atombrella atombrella deleted the kubernetes_maintenance_policy branch June 8, 2021 07:53
@atombrella
Copy link
Contributor Author

@andrewsomething Thanks :) I'm learning something, so that's a nice reward.

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.

None yet

3 participants