Skip to content

Commit

Permalink
Bug fix for edgecontaienr update method and remove machine filter in …
Browse files Browse the repository at this point in the history
…test (#9412) (#16490)

* Fix edgecontainer cluster upgrade endpoint the internal test

* Bug fix for edgecontaienr update method and remove machine filter in test
[upstream:5923d4cb878396a04bed9beaf22a8478e8b1e6a5]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Nov 10, 2023
1 parent 4f15a97 commit 77b6058
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 58 deletions.
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

0 comments on commit 77b6058

Please sign in to comment.