Skip to content

Commit fe85390

Browse files
authored
Merge pull request #6 from pluralsh/fix/machinepool
fix: machine pool version field format
2 parents a57345d + 1b44ac9 commit fe85390

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

cloud/scope/managedmachinepool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *ManagedMachinePoolScope) InstanceGroupManagersClient() *compute.Instanc
151151

152152
// NodePoolVersion returns the k8s version of the node pool.
153153
func (s *ManagedMachinePoolScope) NodePoolVersion() *string {
154-
return s.MachinePool.Spec.Template.Spec.Version
154+
return infrav1exp.NormalizeMachineVersion(s.MachinePool.Spec.Template.Spec.Version)
155155
}
156156

157157
// ConvertToSdkNodePool converts a node pool to format that is used by GCP SDK.
@@ -184,7 +184,7 @@ func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool
184184
}
185185

186186
if machinePool.Spec.Template.Spec.Version != nil {
187-
sdkNodePool.Version = *machinePool.Spec.Template.Spec.Version
187+
sdkNodePool.Version = *infrav1exp.NormalizeMachineVersion(machinePool.Spec.Template.Spec.Version)
188188
}
189189

190190
return &sdkNodePool

exp/api/v1beta1/types.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ limitations under the License.
1616

1717
package v1beta1
1818

19-
import "cloud.google.com/go/container/apiv1/containerpb"
19+
import (
20+
"strings"
21+
22+
"cloud.google.com/go/container/apiv1/containerpb"
23+
"k8s.io/utils/pointer"
24+
)
2025

2126
// TaintEffect is the effect for a Kubernetes taint.
2227
type TaintEffect string
@@ -63,3 +68,22 @@ func ConvertToSdkTaint(taints Taints) []*containerpb.NodeTaint {
6368
}
6469
return res
6570
}
71+
72+
// NormalizeMachineVersion removes "v" prefix from the machine/node pool version string.
73+
// It is being added automatically by one of the mutating webhooks installed
74+
// by the CAPI core.
75+
//
76+
// GKE expects version string to match below scheme:
77+
//
78+
// - "latest": picks the highest valid Kubernetes version
79+
// - "1.X": picks the highest valid patch+gke.N patch in the 1.X version
80+
// - "1.X.Y": picks the highest valid gke.N patch in the 1.X.Y version
81+
// - "1.X.Y-gke.N": picks an explicit Kubernetes version
82+
// - "-": picks the Kubernetes master version.
83+
func NormalizeMachineVersion(version *string) *string {
84+
if version == nil {
85+
return nil
86+
}
87+
88+
return pointer.String(strings.TrimPrefix(*version, "v"))
89+
}

0 commit comments

Comments
 (0)