Skip to content

Commit 153f13f

Browse files
committed
feat: align managed cp spec and status with latest core capi
Signed-off-by: Carlos Salas <[email protected]>
1 parent 84d8696 commit 153f13f

File tree

7 files changed

+71
-13
lines changed

7 files changed

+71
-13
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
271271
},
272272
},
273273
}
274-
if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil {
275-
cluster.InitialClusterVersion = convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion)
274+
if initialClusterVersionFromSpec := getControlPlaneVersionFromSpec(&s.scope.GCPManagedControlPlane.Spec); initialClusterVersionFromSpec != nil {
275+
cluster.InitialClusterVersion = convertToSdkMasterVersion(*initialClusterVersionFromSpec)
276276
}
277277
if s.scope.GCPManagedControlPlane.Spec.ClusterNetwork != nil {
278278
cn := s.scope.GCPManagedControlPlane.Spec.ClusterNetwork
@@ -434,8 +434,8 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster
434434
}
435435
}
436436
// Master version
437-
if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil {
438-
desiredMasterVersion := convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion)
437+
if desiredMasterVersionFromSpec := getControlPlaneVersionFromSpec(&s.scope.GCPManagedControlPlane.Spec); desiredMasterVersionFromSpec != nil {
438+
desiredMasterVersion := convertToSdkMasterVersion(*desiredMasterVersionFromSpec)
439439
existingClusterMasterVersion := convertToSdkMasterVersion(existingCluster.GetCurrentMasterVersion())
440440
if desiredMasterVersion != existingClusterMasterVersion {
441441
needUpdate = true
@@ -506,3 +506,14 @@ func compareMasterAuthorizedNetworksConfig(a, b *containerpb.MasterAuthorizedNet
506506
}
507507
return true
508508
}
509+
510+
// get the desired master version
511+
func getControlPlaneVersionFromSpec(spec *infrav1exp.GCPManagedControlPlaneSpec) *string {
512+
if spec.Version != nil {
513+
return spec.Version
514+
}
515+
if spec.ControlPlaneVersion != nil {
516+
return spec.ControlPlaneVersion
517+
}
518+
return nil
519+
}

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ spec:
133133
ControlPlaneVersion represents the control plane version of the GKE cluster.
134134
If not specified, the default version currently supported by GKE will be
135135
used.
136+
137+
Deprecated: This field will soon be removed and you are expected to use Version instead.
136138
type: string
137139
description:
138140
description: Description describe the cluster.
@@ -217,6 +219,12 @@ spec:
217219
- regular
218220
- stable
219221
type: string
222+
version:
223+
description: |-
224+
Version represents the control plane version of the GKE cluster.
225+
If not specified, the default version currently supported by GKE will be
226+
used.
227+
type: string
220228
required:
221229
- location
222230
- project
@@ -272,8 +280,10 @@ spec:
272280
type: object
273281
type: array
274282
currentVersion:
275-
description: CurrentVersion shows the current version of the GKE control
276-
plane.
283+
description: |-
284+
CurrentVersion shows the current version of the GKE control plane.
285+
286+
Deprecated: This field will soon be removed and you are expected to use Version instead.
277287
type: string
278288
initialized:
279289
description: |-
@@ -286,6 +296,9 @@ spec:
286296
Ready denotes that the GCPManagedControlPlane API Server is ready to
287297
receive requests.
288298
type: boolean
299+
version:
300+
description: Version represents the version of the GKE control plane.
301+
type: string
289302
required:
290303
- ready
291304
type: object

exp/api/v1beta1/gcpmanagedcontrolplane_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ type GCPManagedControlPlaneSpec struct {
147147
// If not specified, the default version currently supported by GKE will be
148148
// used.
149149
// +optional
150+
//
151+
// Deprecated: This field will soon be removed and you are expected to use Version instead.
150152
ControlPlaneVersion *string `json:"controlPlaneVersion,omitempty"`
153+
// Version represents the control plane version of the GKE cluster.
154+
// If not specified, the default version currently supported by GKE will be
155+
// used.
156+
// +optional
157+
Version *string `json:"version,omitempty"`
151158
// Endpoint represents the endpoint used to communicate with the control plane.
152159
// +optional
153160
Endpoint clusterv1.APIEndpoint `json:"endpoint"`
@@ -184,7 +191,13 @@ type GCPManagedControlPlaneStatus struct {
184191

185192
// CurrentVersion shows the current version of the GKE control plane.
186193
// +optional
194+
//
195+
// Deprecated: This field will soon be removed and you are expected to use Version instead.
187196
CurrentVersion string `json:"currentVersion,omitempty"`
197+
198+
// Version represents the version of the GKE control plane.
199+
// +optional
200+
Version *string `json:"version,omitempty"`
188201
}
189202

190203
// +kubebuilder:object:root=true

exp/api/v1beta1/gcpmanagedcontrolplane_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func (r *GCPManagedControlPlane) ValidateCreate() (admission.Warnings, error) {
9898
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
9999
}
100100

101+
if r.Spec.ControlPlaneVersion != nil && r.Spec.Version != nil {
102+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "ControlPlaneVersion"),
103+
r.Spec.LoggingService, "spec.ControlPlaneVersion and spec.Version cannot be set at the same time: please use spec.Version"))
104+
}
105+
101106
if len(allErrs) == 0 {
102107
return nil, nil
103108
}
@@ -149,6 +154,11 @@ func (r *GCPManagedControlPlane) ValidateUpdate(oldRaw runtime.Object) (admissio
149154
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
150155
}
151156

157+
if old.Spec.Version != nil && r.Spec.ControlPlaneVersion != nil {
158+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "ControlPlaneVersion"),
159+
r.Spec.LoggingService, "spec.ControlPlaneVersion and spec.Version cannot be set at the same time: please use spec.Version"))
160+
}
161+
152162
if r.Spec.LoggingService != nil {
153163
err := r.Spec.LoggingService.Validate()
154164
if err != nil {

exp/api/v1beta1/gcpmanagedcontrolplane_webhook_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ func TestGCPManagedControlPlaneDefaultingWebhook(t *testing.T) {
7272
resourceName: "cluster1",
7373
resourceNS: "default",
7474
spec: GCPManagedControlPlaneSpec{
75-
ClusterName: "cluster1_27_1",
76-
ControlPlaneVersion: &vV1_27_1,
75+
ClusterName: "cluster1_27_1",
76+
Version: &vV1_27_1,
7777
},
78-
expectSpec: GCPManagedControlPlaneSpec{ClusterName: "cluster1_27_1", ControlPlaneVersion: &vV1_27_1},
78+
expectSpec: GCPManagedControlPlaneSpec{ClusterName: "cluster1_27_1", Version: &vV1_27_1},
7979
},
8080
{
8181
name: "with autopilot enabled",
8282
resourceName: "cluster1",
8383
resourceNS: "default",
8484
spec: GCPManagedControlPlaneSpec{
85-
ClusterName: "cluster1_autopilot",
86-
ControlPlaneVersion: &vV1_27_1,
87-
EnableAutopilot: true,
85+
ClusterName: "cluster1_autopilot",
86+
Version: &vV1_27_1,
87+
EnableAutopilot: true,
8888
},
89-
expectSpec: GCPManagedControlPlaneSpec{ClusterName: "cluster1_autopilot", ControlPlaneVersion: &vV1_27_1, EnableAutopilot: true},
89+
expectSpec: GCPManagedControlPlaneSpec{ClusterName: "cluster1_autopilot", Version: &vV1_27_1, EnableAutopilot: true},
9090
},
9191
}
9292

exp/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/data/infrastructure-gcp/cluster-template-ci-gke.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ metadata:
3333
spec:
3434
project: "${GCP_PROJECT}"
3535
location: "${GCP_REGION}"
36+
version: "${KUBERNETES_VERSION}"
3637
releaseChannel: "regular"
3738
---
3839
apiVersion: cluster.x-k8s.io/v1beta1

0 commit comments

Comments
 (0)