From f2eb22c0a19de93869e60d4404e92dc9c7043582 Mon Sep 17 00:00:00 2001 From: James Cooke Date: Thu, 27 Aug 2020 08:38:34 +0100 Subject: [PATCH 1/4] Add rollout option to osconfig patch deployment --- products/osconfig/api.yaml | 35 ++++++++++++++++++++++++++++++++ products/osconfig/terraform.yaml | 6 ++++++ 2 files changed, 41 insertions(+) diff --git a/products/osconfig/api.yaml b/products/osconfig/api.yaml index 83b7b26bf8aa..ef019d7e979d 100644 --- a/products/osconfig/api.yaml +++ b/products/osconfig/api.yaml @@ -844,6 +844,41 @@ objects: One day of the month. 1-31 indicates the 1st to the 31st day. -1 indicates the last day of the month. Months without the target day will be skipped. For example, a schedule to run "every month on the 31st" will not run in February, April, June, etc. + - !ruby/object:Api::Type::NestedObject + name: 'rollout' + description: | + Rollout strategy of the patch job. + properties: + - !ruby/object:Api::Type::Enum + name: 'mode' + description: | + Mode of the patch rollout. + values: + - :ZONE_BY_ZONE + - :CONCURRENT_ZONES + - !ruby/object:Api::Type::NestedObject + name: 'disruptionBudget' + description: | + The maximum number (or percentage) of VMs per zone to disrupt at any given moment. The number of VMs calculated from multiplying the percentage by the total number of VMs in a zone is rounded up. + During patching, a VM is considered disrupted from the time the agent is notified to begin until patching has completed. This disruption time includes the time to complete reboot and any post-patch steps. + A VM contributes to the disruption budget if its patching operation fails either when applying the patches, running pre or post patch steps, or if it fails to respond with a success notification before timing out. VMs that are not running or do not have an active agent do not count toward this disruption budget. + For zone-by-zone rollouts, if the disruption budget in a zone is exceeded, the patch job stops, because continuing to the next zone requires completion of the patch process in the previous zone. + For example, if the disruption budget has a fixed value of 10, and 8 VMs fail to patch in the current zone, the patch job continues to patch 2 VMs at a time until the zone is completed. When that zone is completed successfully, patching begins with 10 VMs at a time in the next zone. If 10 VMs in the next zone fail to patch, the patch job stops. + properties: + - !ruby/object:Api::Type::Integer + name: fixed + description: | + Specifies a fixed value. + exactly_one_of: + - fixed + - percentage + - !ruby/object:Api::Type::Integer + name: percentage + description: | + Specifies the relative value defined as a percentage, which will be multiplied by a reference value. + exactly_one_of: + - fixed + - percentage - !ruby/object:Api::Resource name: 'GuestPolicies' base_url: "projects/{{project}}/guestPolicies" diff --git a/products/osconfig/terraform.yaml b/products/osconfig/terraform.yaml index 913b88b85bd9..049ac9c91110 100644 --- a/products/osconfig/terraform.yaml +++ b/products/osconfig/terraform.yaml @@ -58,6 +58,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides function: 'validation.IntBetween(-1,31)' recurringSchedule.frequency: !ruby/object:Overrides::Terraform::PropertyOverride exclude: true + rollout.disruptionBudget.percentage: !ruby/object:Overrides::Terraform::PropertyOverride + validation: !ruby/object:Provider::Terraform::Validation + function: 'validation.IntBetween(0,100)' + rollout.disruptionBudget.fixed: !ruby/object:Overrides::Terraform::PropertyOverride + validation: !ruby/object:Provider::Terraform::Validation + function: 'validation.IntAtLeast(1)' custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/set_computed_name.erb encoder: templates/terraform/encoders/os_config_patch_deployment.go.erb From d7c591623d121409557e560fde9ae5e97d90a640 Mon Sep 17 00:00:00 2001 From: James Cooke Date: Fri, 28 Aug 2020 21:40:31 +0100 Subject: [PATCH 2/4] Add test --- .../examples/os_config_patch_deployment_full.tf.erb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/terraform/examples/os_config_patch_deployment_full.tf.erb b/templates/terraform/examples/os_config_patch_deployment_full.tf.erb index 4eba717f73d8..848e67c72c62 100644 --- a/templates/terraform/examples/os_config_patch_deployment_full.tf.erb +++ b/templates/terraform/examples/os_config_patch_deployment_full.tf.erb @@ -94,4 +94,11 @@ resource "google_os_config_patch_deployment" "<%= ctx[:primary_resource_id] %>" } } } + + rollout { + mode = "ZONE_BY_ZONE" + disruptionBudget { + fixed = 1 + } + } } From 2c98fc1bffa3ab67fdd37b8da5bf742588409b21 Mon Sep 17 00:00:00 2001 From: James Cooke Date: Fri, 28 Aug 2020 21:42:30 +0100 Subject: [PATCH 3/4] Set properties to required and correctly specify exactly one of --- products/osconfig/api.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/products/osconfig/api.yaml b/products/osconfig/api.yaml index ef019d7e979d..b9e93610919c 100644 --- a/products/osconfig/api.yaml +++ b/products/osconfig/api.yaml @@ -856,6 +856,7 @@ objects: values: - :ZONE_BY_ZONE - :CONCURRENT_ZONES + required: true - !ruby/object:Api::Type::NestedObject name: 'disruptionBudget' description: | @@ -870,8 +871,8 @@ objects: description: | Specifies a fixed value. exactly_one_of: - - fixed - - percentage + - rollout.0.disruption_budget.0.fixed + - rollout.0.disruption_budget.0.percentage - !ruby/object:Api::Type::Integer name: percentage description: | @@ -879,6 +880,7 @@ objects: exactly_one_of: - fixed - percentage + required: true - !ruby/object:Api::Resource name: 'GuestPolicies' base_url: "projects/{{project}}/guestPolicies" From ba69ced2a66e683f44fc587eeb9481defd729fb7 Mon Sep 17 00:00:00 2001 From: James Cooke Date: Tue, 1 Sep 2020 10:41:29 +0100 Subject: [PATCH 4/4] Fix typos --- products/osconfig/api.yaml | 4 ++-- .../terraform/examples/os_config_patch_deployment_full.tf.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/products/osconfig/api.yaml b/products/osconfig/api.yaml index b9e93610919c..43fbe585b201 100644 --- a/products/osconfig/api.yaml +++ b/products/osconfig/api.yaml @@ -878,8 +878,8 @@ objects: description: | Specifies the relative value defined as a percentage, which will be multiplied by a reference value. exactly_one_of: - - fixed - - percentage + - rollout.0.disruption_budget.0.fixed + - rollout.0.disruption_budget.0.percentage required: true - !ruby/object:Api::Resource name: 'GuestPolicies' diff --git a/templates/terraform/examples/os_config_patch_deployment_full.tf.erb b/templates/terraform/examples/os_config_patch_deployment_full.tf.erb index 848e67c72c62..53030f0d1ba4 100644 --- a/templates/terraform/examples/os_config_patch_deployment_full.tf.erb +++ b/templates/terraform/examples/os_config_patch_deployment_full.tf.erb @@ -97,7 +97,7 @@ resource "google_os_config_patch_deployment" "<%= ctx[:primary_resource_id] %>" rollout { mode = "ZONE_BY_ZONE" - disruptionBudget { + disruption_budget { fixed = 1 } }