Skip to content

Commit db51271

Browse files
authored
feat: add blue/green upgrade strategy settings (#1551)
1 parent 4abb170 commit db51271

File tree

16 files changed

+296
-46
lines changed

16 files changed

+296
-46
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,13 @@ The node_pools variable takes the following parameters:
276276
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with total limits. | 100 | Optional |
277277
| total_max_count | Total maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with per zone limits. | null | Optional |
278278
| max_pods_per_node | The maximum number of pods per node in this cluster | null | Optional |
279-
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. | 1 | Optional |
280-
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
279+
| strategy | The upgrade stragey to be used for upgrading the nodes. Valid values of state are: `SURGE` or `BLUE_GREEN` | "SURGE" | Optional |
280+
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. Only works with `SURGE` strategy. | 1 | Optional |
281+
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. Only works with `SURGE` strategy. | 0 | Optional |
282+
| node_pool_soak_duration | Time needed after draining the entire blue pool. After this period, the blue pool will be cleaned up. By default, it is set to one hour (3600 seconds). The maximum length of the soak time is 7 days (604,800 seconds). Only works with `BLUE_GREEN` strategy. | "3600s" | Optional |
283+
| batch_soak_duration | Soak time after each batch gets drained, with the default being zero seconds. Only works with `BLUE_GREEN` strategy. | "0s" | Optional |
284+
| batch_node_count | Absolute number of nodes to drain in a batch. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_percentage`. Only works with `BLUE_GREEN` strategy. | 1 | Optional |
285+
| batch_percentage | Percentage of nodes to drain in a batch. Must be in the range of [0.0, 1.0]. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_node_count`. Only works with `BLUE_GREEN` strategy. | null | Optional |
281286
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with total limits. | 1 | Optional |
282287
| total_min_count | Total minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with per zone limits. | null | Optional |
283288
| name | The name of the node pool | | Required |

autogen/main/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,13 @@ The node_pools variable takes the following parameters:
213213
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with total limits. | 100 | Optional |
214214
| total_max_count | Total maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with per zone limits. | null | Optional |
215215
| max_pods_per_node | The maximum number of pods per node in this cluster | null | Optional |
216-
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. | 1 | Optional |
217-
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
216+
| strategy | The upgrade stragey to be used for upgrading the nodes. Valid values of state are: `SURGE` or `BLUE_GREEN` | "SURGE" | Optional |
217+
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. Only works with `SURGE` strategy. | 1 | Optional |
218+
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. Only works with `SURGE` strategy. | 0 | Optional |
219+
| node_pool_soak_duration | Time needed after draining the entire blue pool. After this period, the blue pool will be cleaned up. By default, it is set to one hour (3600 seconds). The maximum length of the soak time is 7 days (604,800 seconds). Only works with `BLUE_GREEN` strategy. | "3600s" | Optional |
220+
| batch_soak_duration | Soak time after each batch gets drained, with the default being zero seconds. Only works with `BLUE_GREEN` strategy. | "0s" | Optional |
221+
| batch_node_count | Absolute number of nodes to drain in a batch. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_percentage`. Only works with `BLUE_GREEN` strategy. | 1 | Optional |
222+
| batch_percentage | Percentage of nodes to drain in a batch. Must be in the range of [0.0, 1.0]. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_node_count`. Only works with `BLUE_GREEN` strategy. | null | Optional |
218223
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with total limits. | 1 | Optional |
219224
| total_min_count | Total minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with per zone limits. | null | Optional |
220225
| name | The name of the node pool | | Required |

autogen/main/cluster.tf.tmpl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,22 @@ resource "google_container_node_pool" "windows_pools" {
697697
}
698698

699699
upgrade_settings {
700-
max_surge = lookup(each.value, "max_surge", 1)
701-
max_unavailable = lookup(each.value, "max_unavailable", 0)
700+
strategy = lookup(each.value, "strategy", "SURGE")
701+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
702+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
703+
704+
dynamic "blue_green_settings" {
705+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
706+
content {
707+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
708+
709+
standard_rollout_policy {
710+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
711+
batch_percentage = lookup(each.value, "batch_percentage", null)
712+
batch_node_count = lookup(each.value, "batch_node_count", null)
713+
}
714+
}
715+
}
702716
}
703717

704718
node_config {

cluster.tf

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,22 @@ resource "google_container_node_pool" "pools" {
406406
}
407407

408408
upgrade_settings {
409-
max_surge = lookup(each.value, "max_surge", 1)
410-
max_unavailable = lookup(each.value, "max_unavailable", 0)
409+
strategy = lookup(each.value, "strategy", "SURGE")
410+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
411+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
412+
413+
dynamic "blue_green_settings" {
414+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
415+
content {
416+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
417+
418+
standard_rollout_policy {
419+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
420+
batch_percentage = lookup(each.value, "batch_percentage", null)
421+
batch_node_count = lookup(each.value, "batch_node_count", null)
422+
}
423+
}
424+
}
411425
}
412426

413427
node_config {
@@ -578,8 +592,22 @@ resource "google_container_node_pool" "windows_pools" {
578592
}
579593

580594
upgrade_settings {
581-
max_surge = lookup(each.value, "max_surge", 1)
582-
max_unavailable = lookup(each.value, "max_unavailable", 0)
595+
strategy = lookup(each.value, "strategy", "SURGE")
596+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
597+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
598+
599+
dynamic "blue_green_settings" {
600+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
601+
content {
602+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
603+
604+
standard_rollout_policy {
605+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
606+
batch_percentage = lookup(each.value, "batch_percentage", null)
607+
batch_node_count = lookup(each.value, "batch_node_count", null)
608+
}
609+
}
610+
}
583611
}
584612

585613
node_config {

modules/beta-private-cluster-update-variant/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,13 @@ The node_pools variable takes the following parameters:
341341
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with total limits. | 100 | Optional |
342342
| total_max_count | Total maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with per zone limits. | null | Optional |
343343
| max_pods_per_node | The maximum number of pods per node in this cluster | null | Optional |
344-
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. | 1 | Optional |
345-
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
344+
| strategy | The upgrade stragey to be used for upgrading the nodes. Valid values of state are: `SURGE` or `BLUE_GREEN` | "SURGE" | Optional |
345+
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. Only works with `SURGE` strategy. | 1 | Optional |
346+
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. Only works with `SURGE` strategy. | 0 | Optional |
347+
| node_pool_soak_duration | Time needed after draining the entire blue pool. After this period, the blue pool will be cleaned up. By default, it is set to one hour (3600 seconds). The maximum length of the soak time is 7 days (604,800 seconds). Only works with `BLUE_GREEN` strategy. | "3600s" | Optional |
348+
| batch_soak_duration | Soak time after each batch gets drained, with the default being zero seconds. Only works with `BLUE_GREEN` strategy. | "0s" | Optional |
349+
| batch_node_count | Absolute number of nodes to drain in a batch. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_percentage`. Only works with `BLUE_GREEN` strategy. | 1 | Optional |
350+
| batch_percentage | Percentage of nodes to drain in a batch. Must be in the range of [0.0, 1.0]. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_node_count`. Only works with `BLUE_GREEN` strategy. | null | Optional |
346351
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with total limits. | 1 | Optional |
347352
| total_min_count | Total minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with per zone limits. | null | Optional |
348353
| name | The name of the node pool | | Required |

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,22 @@ resource "google_container_node_pool" "pools" {
595595
}
596596

597597
upgrade_settings {
598-
max_surge = lookup(each.value, "max_surge", 1)
599-
max_unavailable = lookup(each.value, "max_unavailable", 0)
598+
strategy = lookup(each.value, "strategy", "SURGE")
599+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
600+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
601+
602+
dynamic "blue_green_settings" {
603+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
604+
content {
605+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
606+
607+
standard_rollout_policy {
608+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
609+
batch_percentage = lookup(each.value, "batch_percentage", null)
610+
batch_node_count = lookup(each.value, "batch_node_count", null)
611+
}
612+
}
613+
}
600614
}
601615

602616
node_config {
@@ -807,8 +821,22 @@ resource "google_container_node_pool" "windows_pools" {
807821
}
808822

809823
upgrade_settings {
810-
max_surge = lookup(each.value, "max_surge", 1)
811-
max_unavailable = lookup(each.value, "max_unavailable", 0)
824+
strategy = lookup(each.value, "strategy", "SURGE")
825+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
826+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
827+
828+
dynamic "blue_green_settings" {
829+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
830+
content {
831+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
832+
833+
standard_rollout_policy {
834+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
835+
batch_percentage = lookup(each.value, "batch_percentage", null)
836+
batch_node_count = lookup(each.value, "batch_node_count", null)
837+
}
838+
}
839+
}
812840
}
813841

814842
node_config {

modules/beta-private-cluster/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,13 @@ The node_pools variable takes the following parameters:
319319
| max_count | Maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with total limits. | 100 | Optional |
320320
| total_max_count | Total maximum number of nodes in the NodePool. Must be >= min_count. Cannot be used with per zone limits. | null | Optional |
321321
| max_pods_per_node | The maximum number of pods per node in this cluster | null | Optional |
322-
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. | 1 | Optional |
323-
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional |
322+
| strategy | The upgrade stragey to be used for upgrading the nodes. Valid values of state are: `SURGE` or `BLUE_GREEN` | "SURGE" | Optional |
323+
| max_surge | The number of additional nodes that can be added to the node pool during an upgrade. Increasing max_surge raises the number of nodes that can be upgraded simultaneously. Can be set to 0 or greater. Only works with `SURGE` strategy. | 1 | Optional |
324+
| max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. Only works with `SURGE` strategy. | 0 | Optional |
325+
| node_pool_soak_duration | Time needed after draining the entire blue pool. After this period, the blue pool will be cleaned up. By default, it is set to one hour (3600 seconds). The maximum length of the soak time is 7 days (604,800 seconds). Only works with `BLUE_GREEN` strategy. | "3600s" | Optional |
326+
| batch_soak_duration | Soak time after each batch gets drained, with the default being zero seconds. Only works with `BLUE_GREEN` strategy. | "0s" | Optional |
327+
| batch_node_count | Absolute number of nodes to drain in a batch. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_percentage`. Only works with `BLUE_GREEN` strategy. | 1 | Optional |
328+
| batch_percentage | Percentage of nodes to drain in a batch. Must be in the range of [0.0, 1.0]. If it is set to zero, this phase will be skipped. Cannot be used together with `batch_node_count`. Only works with `BLUE_GREEN` strategy. | null | Optional |
324329
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with total limits. | 1 | Optional |
325330
| total_min_count | Total minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true. Cannot be used with per zone limits. | null | Optional |
326331
| name | The name of the node pool | | Required |

modules/beta-private-cluster/cluster.tf

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,22 @@ resource "google_container_node_pool" "pools" {
501501
}
502502

503503
upgrade_settings {
504-
max_surge = lookup(each.value, "max_surge", 1)
505-
max_unavailable = lookup(each.value, "max_unavailable", 0)
504+
strategy = lookup(each.value, "strategy", "SURGE")
505+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
506+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
507+
508+
dynamic "blue_green_settings" {
509+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
510+
content {
511+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
512+
513+
standard_rollout_policy {
514+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
515+
batch_percentage = lookup(each.value, "batch_percentage", null)
516+
batch_node_count = lookup(each.value, "batch_node_count", null)
517+
}
518+
}
519+
}
506520
}
507521

508522
node_config {
@@ -712,8 +726,22 @@ resource "google_container_node_pool" "windows_pools" {
712726
}
713727

714728
upgrade_settings {
715-
max_surge = lookup(each.value, "max_surge", 1)
716-
max_unavailable = lookup(each.value, "max_unavailable", 0)
729+
strategy = lookup(each.value, "strategy", "SURGE")
730+
max_surge = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_surge", 1) : null
731+
max_unavailable = lookup(each.value, "strategy", "SURGE") == "SURGE" ? lookup(each.value, "max_unavailable", 0) : null
732+
733+
dynamic "blue_green_settings" {
734+
for_each = lookup(each.value, "strategy", "SURGE") == "BLUE_GREEN" ? [1] : []
735+
content {
736+
node_pool_soak_duration = lookup(each.value, "node_pool_soak_duration", null)
737+
738+
standard_rollout_policy {
739+
batch_soak_duration = lookup(each.value, "batch_soak_duration", null)
740+
batch_percentage = lookup(each.value, "batch_percentage", null)
741+
batch_node_count = lookup(each.value, "batch_node_count", null)
742+
}
743+
}
744+
}
717745
}
718746

719747
node_config {

0 commit comments

Comments
 (0)