From b638509dfb6efc7ad532139a80b2008a7f31e390 Mon Sep 17 00:00:00 2001 From: dantiandb Date: Tue, 17 Oct 2023 11:26:52 -0700 Subject: [PATCH] fix bug where maintenance exclusions were not set independently --- ...ster.x-k8s.io_gcpmanagedcontrolplanes.yaml | 4 +- .../v1beta1/gcpmanagedcontrolplane_types.go | 6 +-- exp/api/v1beta1/types.go | 37 ++++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml index 60e400af0..166f97d28 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml @@ -60,7 +60,7 @@ spec: properties: addonsConfig: description: AddonsConfig represents the configuration options for - GKE cluster add ons. + GKE cluster add-ons. properties: dnsCacheConfig: description: DNSCacheConfig represents a configuration for NodeLocalDNS, @@ -424,7 +424,7 @@ spec: workloadIdentityConfig: description: WorkloadIdentityConfig represents configuration options for the use of Kubernetes Service Accounts in GCP IAM policies. - This feature is diabled if this field is not specified. + This feature is disabled if this field is not specified. properties: workloadPool: description: WorkloadPool represents the node pool to attach all diff --git a/exp/api/v1beta1/gcpmanagedcontrolplane_types.go b/exp/api/v1beta1/gcpmanagedcontrolplane_types.go index a204e262e..28a20c60c 100644 --- a/exp/api/v1beta1/gcpmanagedcontrolplane_types.go +++ b/exp/api/v1beta1/gcpmanagedcontrolplane_types.go @@ -60,7 +60,7 @@ type GCPManagedControlPlaneSpec struct { // Endpoint represents the endpoint used to communicate with the control plane. // +optional Endpoint clusterv1.APIEndpoint `json:"endpoint"` - // AddonsConfig represents the configuration options for GKE cluster add ons. + // AddonsConfig represents the configuration options for GKE cluster add-ons. // +optional AddonsConfig *AddonsConfig `json:"addonsConfig,omitempty"` // LoggingConfig represents the configuration options for GKE cluster logging. @@ -79,7 +79,7 @@ type GCPManagedControlPlaneSpec struct { // +optional PrivateClusterConfig *PrivateClusterConfig `json:"privateClusterConfig,omitempty"` // WorkloadIdentityConfig represents configuration options for the use of Kubernetes Service Accounts in GCP IAM - // policies. This feature is diabled if this field is not specified. + // policies. This feature is disabled if this field is not specified. // +optional WorkloadIdentityConfig *WorkloadIdentityConfig `json:"workloadIdentityConfig,omitempty"` // ResourceLabels represents the resource labels for the GKE cluster to use to annotate any related @@ -279,7 +279,7 @@ const ( NoMinorOrNodeUpgrades MaintenanceExclusionOption = "no-minor-or-node-upgrades" ) -// AddonsConfig contains configurations for various add ons available to run in the GKE cluster. +// AddonsConfig contains configurations for various add-ons available to run in the GKE cluster. type AddonsConfig struct { // DNSCacheConfig represents a configuration for NodeLocalDNS, a dns cache running on GKE cluster nodes // If omitted it is disabled by default. diff --git a/exp/api/v1beta1/types.go b/exp/api/v1beta1/types.go index a33249017..0e3abdf87 100644 --- a/exp/api/v1beta1/types.go +++ b/exp/api/v1beta1/types.go @@ -191,16 +191,23 @@ func ConvertToSdkMaintenancePolicy(policy *MaintenancePolicy) (*containerpb.Main } exclusions[k] = tw } + maintenancePolicy.Window = &containerpb.MaintenanceWindow{ + MaintenanceExclusions: exclusions, + } } if policy.DailyMaintenanceWindow != nil { - maintenancePolicy.Window = &containerpb.MaintenanceWindow{ - Policy: &containerpb.MaintenanceWindow_DailyMaintenanceWindow{ - DailyMaintenanceWindow: &containerpb.DailyMaintenanceWindow{ - StartTime: policy.DailyMaintenanceWindow.StartTime, - }, + dailyMaintenanceWindowPolicy := &containerpb.MaintenanceWindow_DailyMaintenanceWindow{ + DailyMaintenanceWindow: &containerpb.DailyMaintenanceWindow{ + StartTime: policy.DailyMaintenanceWindow.StartTime, }, - MaintenanceExclusions: exclusions, + } + if maintenancePolicy.Window == nil { + maintenancePolicy.Window = &containerpb.MaintenanceWindow{ + Policy: dailyMaintenanceWindowPolicy, + } + } else { + maintenancePolicy.Window.Policy = dailyMaintenanceWindowPolicy } } @@ -209,14 +216,18 @@ func ConvertToSdkMaintenancePolicy(policy *MaintenancePolicy) (*containerpb.Main if err != nil { return nil, err } - maintenancePolicy.Window = &containerpb.MaintenanceWindow{ - Policy: &containerpb.MaintenanceWindow_RecurringWindow{ - RecurringWindow: &containerpb.RecurringTimeWindow{ - Window: tw, - Recurrence: policy.RecurringMaintenanceWindow.Recurrence, - }, + recurringWindowPolicy := &containerpb.MaintenanceWindow_RecurringWindow{ + RecurringWindow: &containerpb.RecurringTimeWindow{ + Window: tw, + Recurrence: policy.RecurringMaintenanceWindow.Recurrence, }, - MaintenanceExclusions: exclusions, + } + if maintenancePolicy.Window == nil { + maintenancePolicy.Window = &containerpb.MaintenanceWindow{ + Policy: recurringWindowPolicy, + } + } else { + maintenancePolicy.Window.Policy = recurringWindowPolicy } }