Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip the patch number in GKE master version #1105

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cloud/services/container/clusters/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package clusters
import (
"context"
"fmt"
"strings"

"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/shared"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) {
}

log.V(2).Info("gke cluster found", "status", cluster.Status)
s.scope.GCPManagedControlPlane.Status.CurrentVersion = cluster.CurrentMasterVersion
s.scope.GCPManagedControlPlane.Status.CurrentVersion = convertToSdkMasterVersion(cluster.CurrentMasterVersion)

switch cluster.Status {
case containerpb.Cluster_PROVISIONING:
Expand Down Expand Up @@ -262,7 +263,7 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
MasterAuthorizedNetworksConfig: convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig),
}
if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil {
cluster.InitialClusterVersion = *s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion
cluster.InitialClusterVersion = convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion)
}
if !s.scope.IsAutopilotCluster() {
cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.Name)
Expand Down Expand Up @@ -333,6 +334,11 @@ func convertToSdkReleaseChannel(channel *infrav1exp.ReleaseChannel) containerpb.
}
}

func convertToSdkMasterVersion(masterVersion string) string {
// For example, the master version returned from GCP SDK can be 1.27.2-gke.2100, we want to convert it to 1.27.2
return strings.Replace(strings.Split(masterVersion, "-")[0], "v", "", 1)
}

// convertToSdkMasterAuthorizedNetworksConfig converts the MasterAuthorizedNetworksConfig defined in CRs to the SDK version.
func convertToSdkMasterAuthorizedNetworksConfig(config *infrav1exp.MasterAuthorizedNetworksConfig) *containerpb.MasterAuthorizedNetworksConfig {
// if config is nil, it means that the user wants to disable the feature.
Expand Down Expand Up @@ -376,11 +382,12 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster
}
// Master version
if s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion != nil {
desiredMasterVersion := *s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion
if desiredMasterVersion != existingCluster.CurrentMasterVersion {
desiredMasterVersion := convertToSdkMasterVersion(*s.scope.GCPManagedControlPlane.Spec.ControlPlaneVersion)
existingClusterMasterVersion := convertToSdkMasterVersion(existingCluster.CurrentMasterVersion)
if desiredMasterVersion != existingClusterMasterVersion {
needUpdate = true
clusterUpdate.DesiredMasterVersion = desiredMasterVersion
log.V(2).Info("Master version update required", "current", existingCluster.CurrentMasterVersion, "desired", desiredMasterVersion)
log.V(2).Info("Master version update required", "current", existingClusterMasterVersion, "desired", desiredMasterVersion)
}
}

Expand Down
Loading