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

Bug fix for edgecontaienr update method and remove machine filter in test #16490

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9412.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Bug fix for edgecontaienr update method and remove machine filter in test
```
97 changes: 66 additions & 31 deletions google/services/edgecontainer/resource_edgecontainer_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
Expand Down Expand Up @@ -850,24 +851,12 @@ func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{}
billingProject = project

obj := make(map[string]interface{})
fleetProp, err := expandEdgecontainerClusterFleet(d.Get("fleet"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("fleet"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, fleetProp)) {
obj["fleet"] = fleetProp
}
networkingProp, err := expandEdgecontainerClusterNetworking(d.Get("networking"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("networking"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, networkingProp)) {
obj["networking"] = networkingProp
}
authorizationProp, err := expandEdgecontainerClusterAuthorization(d.Get("authorization"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("authorization"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, authorizationProp)) {
obj["authorization"] = authorizationProp
}
defaultMaxPodsPerNodeProp, err := expandEdgecontainerClusterDefaultMaxPodsPerNode(d.Get("default_max_pods_per_node"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -923,35 +912,81 @@ func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{}
}

log.Printf("[DEBUG] Updating Cluster %q: %#v", d.Id(), obj)
updateMask := []string{}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
if d.HasChange("networking") {
updateMask = append(updateMask, "networking")
}

res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PUT",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})
if d.HasChange("default_max_pods_per_node") {
updateMask = append(updateMask, "defaultMaxPodsPerNode")
}

if err != nil {
return fmt.Errorf("Error updating Cluster %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating Cluster %q: %#v", d.Id(), res)
if d.HasChange("maintenance_policy") {
updateMask = append(updateMask, "maintenancePolicy")
}

err = EdgecontainerOperationWaitTime(
config, res, project, "Updating Cluster", userAgent,
d.Timeout(schema.TimeoutUpdate))
if d.HasChange("control_plane") {
updateMask = append(updateMask, "controlPlane")
}

if d.HasChange("system_addons_config") {
updateMask = append(updateMask, "systemAddonsConfig")
}

if d.HasChange("external_load_balancer_ipv4_address_pools") {
updateMask = append(updateMask, "externalLoadBalancerIpv4AddressPools")
}

if d.HasChange("control_plane_encryption") {
updateMask = append(updateMask, "controlPlaneEncryption")
}

if d.HasChange("release_channel") {
updateMask = append(updateMask, "releaseChannel")
}

if d.HasChange("effective_labels") {
updateMask = append(updateMask, "labels")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}

// if updateMask is empty we are not updating anything so skip the post
if len(updateMask) > 0 {
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PATCH",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})

if err != nil {
return fmt.Errorf("Error updating Cluster %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating Cluster %q: %#v", d.Id(), res)
}

err = EdgecontainerOperationWaitTime(
config, res, project, "Updating Cluster", userAgent,
d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
}
}
d.Partial(true)

if d.HasChange("target_version") {
Expand Down
75 changes: 50 additions & 25 deletions google/services/edgecontainer/resource_edgecontainer_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
Expand Down Expand Up @@ -376,12 +377,6 @@ func resourceEdgecontainerNodePoolUpdate(d *schema.ResourceData, meta interface{
billingProject = project

obj := make(map[string]interface{})
nodeLocationProp, err := expandEdgecontainerNodePoolNodeLocation(d.Get("node_location"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("node_location"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, nodeLocationProp)) {
obj["nodeLocation"] = nodeLocationProp
}
nodeCountProp, err := expandEdgecontainerNodePoolNodeCount(d.Get("node_count"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -419,36 +414,66 @@ func resourceEdgecontainerNodePoolUpdate(d *schema.ResourceData, meta interface{
}

log.Printf("[DEBUG] Updating NodePool %q: %#v", d.Id(), obj)
updateMask := []string{}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
if d.HasChange("node_count") {
updateMask = append(updateMask, "nodeCount")
}

res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PUT",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})
if d.HasChange("machine_filter") {
updateMask = append(updateMask, "machineFilter")
}

if err != nil {
return fmt.Errorf("Error updating NodePool %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating NodePool %q: %#v", d.Id(), res)
if d.HasChange("local_disk_encryption") {
updateMask = append(updateMask, "localDiskEncryption")
}

err = EdgecontainerOperationWaitTime(
config, res, project, "Updating NodePool", userAgent,
d.Timeout(schema.TimeoutUpdate))
if d.HasChange("node_config") {
updateMask = append(updateMask, "nodeConfig")
}

if d.HasChange("effective_labels") {
updateMask = append(updateMask, "labels")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}

// if updateMask is empty we are not updating anything so skip the post
if len(updateMask) > 0 {
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "PATCH",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutUpdate),
})

if err != nil {
return fmt.Errorf("Error updating NodePool %q: %s", d.Id(), err)
} else {
log.Printf("[DEBUG] Finished updating NodePool %q: %#v", d.Id(), res)
}

err = EdgecontainerOperationWaitTime(
config, res, project, "Updating NodePool", userAgent,
d.Timeout(schema.TimeoutUpdate))

if err != nil {
return err
}
}

return resourceEdgecontainerNodePoolRead(d, meta)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ resource "google_edgecontainer_cluster" "cluster" {
local {
node_location = "us-central1-edge-den25349"
node_count = 1
machine_filter = "den25349-01"
shared_deployment_policy = "ALLOWED"
}
}
Expand All @@ -94,7 +93,6 @@ resource "google_edgecontainer_node_pool" "default" {
cluster = google_edgecontainer_cluster.cluster.name
location = "us-central1"
node_location = "us-central1-edge-den25349"
machine_filter = "den25349-02"
node_count = 1
}

Expand Down