-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for GKE Accelerator Network Profile #15474
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
Changes from 24 commits
f233324
5d92815
34ed6bb
9a150ce
b157711
5dcce91
4142462
a632037
22c5448
c84be68
d6db86b
0279c7c
ddcb650
7f217ab
5306804
8ac77f8
6d59673
07b8147
9030c54
b991e1c
04c946f
57fb041
e239557
f93ce25
a5feeda
9b26e66
6ac4b40
acdbfef
da880fa
92f631b
afe6d83
15788a5
7eb4e4c
6b19f15
e0daabc
a2fea2f
f8d272a
326b968
da20cba
d577f38
6c9e632
a7e075d
256c83c
3045323
02e46af
06e9dde
65081de
024be3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,7 @@ func ResourceContainerNodePool() *schema.Resource { | |
| CustomizeDiff: customdiff.All( | ||
| tpgresource.DefaultProviderProject, | ||
| resourceNodeConfigEmptyGuestAccelerator, | ||
| nodePoolAcceleratorNetworkProfileCustomizeDiff, | ||
| ), | ||
|
|
||
| UseJSONNumber: true, | ||
|
|
@@ -522,6 +523,14 @@ var schemaNodePool = map[string]*schema.Schema{ | |
| Description: `Networking configuration for this NodePool. If specified, it overrides the cluster-level defaults.`, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| {{ if ne $.TargetVersionName `ga` }} | ||
| "accelerator_network_profile": { | ||
| Type: schema.TypeString, | ||
| Description: "The accelerator network profile to use for this node pool.", | ||
| Optional: true, | ||
| ForceNew: true, | ||
| }, | ||
| {{- end }} | ||
| "create_pod_range": { | ||
| Type: schema.TypeBool, | ||
| Optional: true, | ||
|
|
@@ -552,20 +561,23 @@ var schemaNodePool = map[string]*schema.Schema{ | |
| "additional_node_network_configs": { | ||
| Type: schema.TypeList, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Computed: true, | ||
| ForceNew: true, | ||
ellenjzh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Description: `We specify the additional node networks for this node pool using this list. Each node network corresponds to an additional interface`, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "network": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Computed: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been a while, so just to triple-check before we make these changes: Optional+Computed means that if the user has a value set for this field and then removes the field from their config, Terraform will consider it to still be set to the last value returned from the API (the last value the user had set). Will that cause any problems on any of these fields? Potential impacts could include:
The flipside, just for my own reference / to make sure I've got it right, is that all these fields will have API defaults if |
||
| ForceNew: true, | ||
| Description: `Name of the VPC where the additional interface belongs.`, | ||
| }, | ||
| "subnetwork": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| Computed: true, | ||
| ForceNew: true, | ||
| Description: `Name of the subnetwork where the additional interface belongs.`, | ||
| }, | ||
| }, | ||
|
|
@@ -639,7 +651,6 @@ var schemaNodePool = map[string]*schema.Schema{ | |
| }, | ||
| }, | ||
| }, | ||
|
|
||
| } | ||
|
|
||
| type NodePoolInformation struct { | ||
|
|
@@ -1438,6 +1449,9 @@ func flattenNodeNetworkConfig(c *container.NodeNetworkConfig, d *schema.Resource | |
| "additional_node_network_configs": flattenAdditionalNodeNetworkConfig(c.AdditionalNodeNetworkConfigs), | ||
| "additional_pod_network_configs": flattenAdditionalPodNetworkConfig(c.AdditionalPodNetworkConfigs), | ||
| "subnetwork": c.Subnetwork, | ||
| {{ if ne $.TargetVersionName `ga` }} | ||
| "accelerator_network_profile": c.AcceleratorNetworkProfile, | ||
| {{- end }} | ||
| }) | ||
| } | ||
| return result | ||
|
|
@@ -1552,7 +1566,11 @@ func expandNodeNetworkConfig(v interface{}) *container.NodeNetworkConfig { | |
| nnc.NetworkPerformanceConfig.TotalEgressBandwidthTier = total_egress_bandwidth_tier.(string) | ||
| } | ||
| } | ||
|
|
||
| {{ if ne $.TargetVersionName `ga` }} | ||
| if v, ok := networkNodeConfig["accelerator_network_profile"]; ok { | ||
| nnc.AcceleratorNetworkProfile = v.(string) | ||
| } | ||
| {{- end }} | ||
| return nnc | ||
| } | ||
|
|
||
|
|
@@ -1917,3 +1935,97 @@ func retryWhileIncompatibleOperation(timeout time.Duration, lockKey string, f fu | |
| return nil | ||
| }) | ||
| } | ||
|
|
||
| func nodePoolAcceleratorNetworkProfileCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta any) error { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: Running...") | ||
|
|
||
| // 1. SKIP ON CREATE | ||
| if diff.Id() == "" { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: SKIP - Resource is being created (no ID).") | ||
| return nil | ||
| } | ||
|
|
||
| // 2. DETECT USER CONFIG | ||
| userHasAdditionalConfigs := false | ||
| rawConfig := diff.GetRawConfig() | ||
| rawNetworkConfig := rawConfig.GetAttr("network_config") | ||
|
|
||
| if !rawNetworkConfig.IsNull() { | ||
| if rawNetworkConfig.Type().IsCollectionType() { | ||
| it := rawNetworkConfig.ElementIterator() | ||
| for it.Next() { | ||
| _, val := it.Element() | ||
| userConfig := val.GetAttr("additional_node_network_configs") | ||
| if !userConfig.IsNull() && userConfig.LengthInt() > 0 { | ||
| userHasAdditionalConfigs = true | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // 3. LOGIC CHECK | ||
| shouldClear := false | ||
|
|
||
| oldProfile, newProfile := diff.GetChange("network_config.0.accelerator_network_profile") | ||
| anpIsActive := newProfile.(string) != "" | ||
| anpIsChanging := oldProfile.(string) != newProfile.(string) | ||
|
|
||
| if !userHasAdditionalConfigs { | ||
| if anpIsActive && anpIsChanging { | ||
ellenjzh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shouldClear = true | ||
| } | ||
| if !anpIsActive { | ||
| shouldClear = true | ||
| } | ||
| } | ||
|
|
||
| // Check the OLD state to avoid "Plan Not Empty" on defaults | ||
| currentCount := 0 | ||
| if c, ok := diff.Get("network_config.0.additional_node_network_configs.#").(int); ok { | ||
| currentCount = c | ||
| } | ||
|
|
||
| log.Printf("[DEBUG] ANP CustomizeDiff: ANALYSIS: ID=%s, UserHasConfig=%v, ANP=%v, CurrentCount=%d", | ||
| diff.Id(), userHasAdditionalConfigs, anpIsActive, currentCount) | ||
|
|
||
| if shouldClear { | ||
| if currentCount == 0 { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: ACTION SKIPPED - Config is already empty (Count is 0). Avoiding drift.") | ||
| shouldClear = false | ||
| } else { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: ACTION REQUIRED - Sticky value detected (Count is %d). Clearing it.", currentCount) | ||
| } | ||
| } else { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: NO ACTION - Conditions not met.") | ||
| } | ||
|
|
||
| // 4. EXECUTE THE FIX | ||
| if shouldClear { | ||
| log.Printf("[DEBUG] ANP CustomizeDiff: EXECUTING FIX - Rewriting network_config block...") | ||
| var newConfigMap map[string]interface{} | ||
| existingConfigs := diff.Get("network_config").([]interface{}) | ||
|
|
||
| if len(existingConfigs) > 0 && existingConfigs[0] != nil { | ||
| currentMap := existingConfigs[0].(map[string]interface{}) | ||
| newConfigMap = make(map[string]interface{}) | ||
| for k, v := range currentMap { | ||
| newConfigMap[k] = v | ||
| } | ||
| } else { | ||
| newConfigMap = make(map[string]interface{}) | ||
| } | ||
|
|
||
| newConfigMap["additional_node_network_configs"] = []interface{}{} | ||
| if !anpIsActive { | ||
| newConfigMap["accelerator_network_profile"] = "" | ||
| } | ||
|
|
||
| err := diff.SetNew("network_config", []interface{}{newConfigMap}) | ||
| if err != nil { | ||
| return fmt.Errorf("Error updating network_config: %s", err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.