From 74251b118a4964e4406b18eb95ab7e6a26585e78 Mon Sep 17 00:00:00 2001
From: Marcin Maciaszczyk <marcin9yk@icloud.com>
Date: Wed, 27 Sep 2023 13:29:21 +0200
Subject: [PATCH] replace Paid SKU tier with Standard

---
 api/v1beta1/azuremanagedcontrolplane_types.go               | 5 ++++-
 api/v1beta1/azuremanagedcontrolplane_webhook.go             | 6 ++++++
 api/v1beta1/azuremanagedcontrolplane_webhook_test.go        | 2 +-
 ...tructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml | 1 +
 docs/book/src/topics/managedcluster.md                      | 2 +-
 5 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/api/v1beta1/azuremanagedcontrolplane_types.go b/api/v1beta1/azuremanagedcontrolplane_types.go
index e417a56b9fc..4935d1f8413 100644
--- a/api/v1beta1/azuremanagedcontrolplane_types.go
+++ b/api/v1beta1/azuremanagedcontrolplane_types.go
@@ -262,14 +262,17 @@ type AddonProfile struct {
 }
 
 // AzureManagedControlPlaneSkuTier - Tier of a managed cluster SKU.
-// +kubebuilder:validation:Enum=Free;Paid
+// +kubebuilder:validation:Enum=Free;Paid;Standard
 type AzureManagedControlPlaneSkuTier string
 
 const (
 	// FreeManagedControlPlaneTier is the free tier of AKS without corresponding SLAs.
 	FreeManagedControlPlaneTier AzureManagedControlPlaneSkuTier = "Free"
 	// PaidManagedControlPlaneTier is the paid tier of AKS with corresponding SLAs.
+	// Deprecated. It has been replaced with StandardManagedControlPlaneTier.
 	PaidManagedControlPlaneTier AzureManagedControlPlaneSkuTier = "Paid"
+	// StandardManagedControlPlaneTier is the standard tier of AKS with corresponding SLAs.
+	StandardManagedControlPlaneTier AzureManagedControlPlaneSkuTier = "Standard"
 )
 
 // AKSSku - AKS SKU.
diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook.go b/api/v1beta1/azuremanagedcontrolplane_webhook.go
index df5f6b26456..bd17a91def7 100644
--- a/api/v1beta1/azuremanagedcontrolplane_webhook.go
+++ b/api/v1beta1/azuremanagedcontrolplane_webhook.go
@@ -96,6 +96,12 @@ func (mw *azureManagedControlPlaneWebhook) Default(ctx context.Context, obj runt
 		ctrl.Log.WithName("AzureManagedControlPlaneWebHookLogger").Error(err, "setDefaultSSHPublicKey failed")
 	}
 
+	// PaidManagedControlPlaneTier has been replaced with StandardManagedControlPlaneTier since v2023-02-01.
+	if m.Spec.SKU != nil && m.Spec.SKU.Tier == PaidManagedControlPlaneTier {
+		m.Spec.SKU.Tier = StandardManagedControlPlaneTier
+		ctrl.Log.WithName("AzureManagedControlPlaneWebHookLogger").Info("Paid SKU tier is deprecated and has been replaced by Standard")
+	}
+
 	m.setDefaultNodeResourceGroupName()
 	m.setDefaultVirtualNetwork()
 	m.setDefaultSubnet()
diff --git a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go
index 438bcbf0266..27aff0b6bf2 100644
--- a/api/v1beta1/azuremanagedcontrolplane_webhook_test.go
+++ b/api/v1beta1/azuremanagedcontrolplane_webhook_test.go
@@ -87,7 +87,7 @@ func TestDefaultingWebhook(t *testing.T) {
 	g.Expect(amcp.Spec.NodeResourceGroupName).To(Equal("fooNodeRg"))
 	g.Expect(amcp.Spec.VirtualNetwork.Name).To(Equal("fooVnetName"))
 	g.Expect(amcp.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooSubnetName"))
-	g.Expect(amcp.Spec.SKU.Tier).To(Equal(PaidManagedControlPlaneTier))
+	g.Expect(amcp.Spec.SKU.Tier).To(Equal(StandardManagedControlPlaneTier))
 	g.Expect(*amcp.Spec.OIDCIssuerProfile.Enabled).To(BeTrue())
 
 	t.Logf("Testing amcp defaulting webhook with overlay")
diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml
index 4d1bac26596..d372ab6cc8e 100644
--- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml
+++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml
@@ -421,6 +421,7 @@ spec:
                     enum:
                     - Free
                     - Paid
+                    - Standard
                     type: string
                 required:
                 - tier
diff --git a/docs/book/src/topics/managedcluster.md b/docs/book/src/topics/managedcluster.md
index e015fadeee0..11ffa5b1435 100644
--- a/docs/book/src/topics/managedcluster.md
+++ b/docs/book/src/topics/managedcluster.md
@@ -130,7 +130,7 @@ spec:
   networkPolicy: azure # or calico
   networkPlugin: azure # or kubenet
   sku:
-    tier: Free # or Paid
+    tier: Free # or Standard
   addonProfiles:
   - name: azureKeyvaultSecretsProvider
     enabled: true