diff --git a/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml b/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml index 12a7e49b51a..90961207d5a 100644 --- a/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml +++ b/config/crd/bases/exp.infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml @@ -107,7 +107,6 @@ spec: version: description: Version defines the desired Kubernetes version. minLength: 2 - pattern: ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$ type: string required: - defaultPoolRef diff --git a/exp/api/v1alpha3/azuremanagedcontrolplane_types.go b/exp/api/v1alpha3/azuremanagedcontrolplane_types.go index 79e5fe022b3..2a5474d64c1 100644 --- a/exp/api/v1alpha3/azuremanagedcontrolplane_types.go +++ b/exp/api/v1alpha3/azuremanagedcontrolplane_types.go @@ -26,7 +26,6 @@ import ( type AzureManagedControlPlaneSpec struct { // Version defines the desired Kubernetes version. // +kubebuilder:validation:MinLength:=2 - // +kubebuilder:validation:Pattern:=^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$ Version string `json:"version"` // ResourceGroup is the name of the Azure resource group for this AKS Cluster. diff --git a/exp/controllers/azuremanagedmachinepool_reconciler.go b/exp/controllers/azuremanagedmachinepool_reconciler.go index 1911415d0bb..8a3b37e1f37 100644 --- a/exp/controllers/azuremanagedmachinepool_reconciler.go +++ b/exp/controllers/azuremanagedmachinepool_reconciler.go @@ -19,6 +19,7 @@ package controllers import ( "context" "fmt" + "strings" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-01/compute" "github.com/pkg/errors" @@ -54,13 +55,20 @@ func newAzureManagedMachinePoolReconciler(scope *scope.ManagedControlPlaneScope) // Reconcile reconciles all the services in pre determined order func (r *azureManagedMachinePoolReconciler) Reconcile(ctx context.Context, scope *scope.ManagedControlPlaneScope) error { scope.Logger.Info("reconciling machine pool") + + var normalizedVersion *string + if scope.MachinePool.Spec.Template.Spec.Version != nil { + v := strings.TrimPrefix(*scope.MachinePool.Spec.Template.Spec.Version, "v") + normalizedVersion = &v + } + agentPoolSpec := &agentpools.Spec{ Name: scope.InfraMachinePool.Name, ResourceGroup: scope.ControlPlane.Spec.ResourceGroup, Cluster: scope.ControlPlane.Name, SKU: scope.InfraMachinePool.Spec.SKU, Replicas: 1, - Version: scope.MachinePool.Spec.Template.Spec.Version, + Version: normalizedVersion, } if scope.InfraMachinePool.Spec.OSDiskSizeGB != nil { diff --git a/exp/controllers/helpers.go b/exp/controllers/helpers.go index 3244b38a43b..b7310973cee 100644 --- a/exp/controllers/helpers.go +++ b/exp/controllers/helpers.go @@ -174,6 +174,11 @@ func AzureManagedClusterToAzureManagedControlPlaneMapper(c client.Client, log lo return nil } + if cluster == nil { + log.Error(err, "cluster has not set owner ref yet") + return nil + } + ref := cluster.Spec.ControlPlaneRef if ref == nil || ref.Name == "" { return nil