Skip to content

Commit 782fe13

Browse files
author
Sebastian Florek
committed
update node pool and control plane version check
1 parent 88d0ac1 commit 782fe13

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ func (s *Service) hasDesiredVersion(controlPlaneVersion *string, clusterVersion
429429
return true
430430
}
431431

432+
// In case user defined "latest" or "-" as control plane version assume
433+
// that cluster is already at the desired version
434+
if *controlPlaneVersion == "latest" || *controlPlaneVersion == "-" {
435+
return true
436+
}
437+
432438
// Allow partial version matching i.e. '1.24' and '1.24.14' should be a desired version match
433439
// for cluster version '1.24.14-gke.2700'
434440
if strings.HasPrefix(clusterVersion, *controlPlaneVersion) {

cloud/services/container/nodepools/reconcile.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"reflect"
23+
"strings"
2324

2425
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
2526
"sigs.k8s.io/cluster-api-provider-gcp/util/resourceurl"
@@ -32,15 +33,16 @@ import (
3233
"github.com/go-logr/logr"
3334
"github.com/googleapis/gax-go/v2/apierror"
3435
"github.com/pkg/errors"
36+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37+
"sigs.k8s.io/cluster-api/util/conditions"
38+
ctrl "sigs.k8s.io/controller-runtime"
39+
"sigs.k8s.io/controller-runtime/pkg/log"
40+
3541
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
3642
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
3743
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/shared"
3844
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
3945
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
40-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
41-
"sigs.k8s.io/cluster-api/util/conditions"
42-
ctrl "sigs.k8s.io/controller-runtime"
43-
"sigs.k8s.io/controller-runtime/pkg/log"
4446
)
4547

4648
// Reconcile reconcile GKE node pool.
@@ -335,7 +337,7 @@ func (s *Service) checkDiffAndPrepareUpdateVersionOrImage(existingNodePool *cont
335337
Name: s.scope.NodePoolFullName(),
336338
}
337339
// Node version
338-
if s.scope.NodePoolVersion() != nil && *s.scope.NodePoolVersion() != existingNodePool.Version {
340+
if !s.hasDesiredVersion(s.scope.NodePoolVersion(), existingNodePool.Version) {
339341
needUpdate = true
340342
updateNodePoolRequest.NodeVersion = *s.scope.NodePoolVersion()
341343
}
@@ -357,6 +359,26 @@ func (s *Service) checkDiffAndPrepareUpdateVersionOrImage(existingNodePool *cont
357359
return needUpdate, &updateNodePoolRequest
358360
}
359361

362+
func (s *Service) hasDesiredVersion(nodePoolVersion *string, existingNodePoolVersion string) bool {
363+
if nodePoolVersion == nil {
364+
return true
365+
}
366+
367+
// In case user defined "latest" or "-" as node pool version assume
368+
// that node pool is already at the desired version
369+
if *nodePoolVersion == "latest" || *nodePoolVersion == "-" {
370+
return true
371+
}
372+
373+
// Allow partial version matching i.e. '1.24' and '1.24.14' should be a desired version match
374+
// for node pool version '1.24.14-gke.2700'
375+
if strings.HasPrefix(existingNodePoolVersion, *nodePoolVersion) {
376+
return true
377+
}
378+
379+
return *nodePoolVersion == existingNodePoolVersion
380+
}
381+
360382
func (s *Service) checkDiffAndPrepareUpdateAutoscaling(existingNodePool *containerpb.NodePool) (bool, *containerpb.SetNodePoolAutoscalingRequest) {
361383
needUpdate := false
362384

0 commit comments

Comments
 (0)