Skip to content

Commit

Permalink
Reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Mar 6, 2024
1 parent 78ecf76 commit 5ff9539
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 377 deletions.
6 changes: 0 additions & 6 deletions api/v1beta1/azuremanagedcontrolplane_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,3 @@ func (m *AzureManagedControlPlane) setDefaultAKSExtensions() {
}
}
}

func (m *AzureManagedControlPlane) setDefaultEnablePreviewFeatures() {
if m.Spec.EnablePreviewFeatures == nil {
m.Spec.EnablePreviewFeatures = ptr.To(false)
}
}
2 changes: 1 addition & 1 deletion api/v1beta1/azuremanagedcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (mw *azureManagedControlPlaneWebhook) Default(ctx context.Context, obj runt
setDefault[*Identity](&m.Spec.Identity, &Identity{
Type: ManagedControlPlaneIdentityTypeSystemAssigned,
})
setDefault[*bool](&m.Spec.EnablePreviewFeatures, ptr.To(false))
m.Spec.Version = setDefaultVersion(m.Spec.Version)
m.Spec.SKU = setDefaultSku(m.Spec.SKU)
m.Spec.AutoScalerProfile = setDefaultAutoScalerProfile(m.Spec.AutoScalerProfile)
Expand All @@ -97,7 +98,6 @@ func (mw *azureManagedControlPlaneWebhook) Default(ctx context.Context, obj runt
m.setDefaultOIDCIssuerProfile()
m.setDefaultDNSPrefix()
m.setDefaultAKSExtensions()
m.setDefaultEnablePreviewFeatures()

return nil
}
Expand Down
1 change: 1 addition & 0 deletions api/v1beta1/azuremanagedcontrolplanetemplate_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
func (mcp *AzureManagedControlPlaneTemplate) setDefaults() {
setDefault[*string](&mcp.Spec.Template.Spec.NetworkPlugin, ptr.To(AzureNetworkPluginName))
setDefault[*string](&mcp.Spec.Template.Spec.LoadBalancerSKU, ptr.To("Standard"))
setDefault[*bool](&mcp.Spec.Template.Spec.EnablePreviewFeatures, ptr.To(false))

if mcp.Spec.Template.Spec.Version != "" && !strings.HasPrefix(mcp.Spec.Template.Spec.Version, "v") {
mcp.Spec.Template.Spec.Version = setDefaultVersion(mcp.Spec.Template.Spec.Version)
Expand Down
3 changes: 3 additions & 0 deletions api/v1beta1/azuremanagedcontrolplanetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestControlPlaneTemplateDefaultingWebhook(t *testing.T) {
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooName"))
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.Subnet.CIDRBlock).To(Equal(defaultAKSNodeSubnetCIDR))
g.Expect(amcpt.Spec.Template.Spec.SKU.Tier).To(Equal(FreeManagedControlPlaneTier))
g.Expect(*amcpt.Spec.Template.Spec.EnablePreviewFeatures).To(BeFalse())

t.Logf("Testing amcp defaulting webhook with baseline")
netPlug := "kubenet"
Expand All @@ -53,6 +54,7 @@ func TestControlPlaneTemplateDefaultingWebhook(t *testing.T) {
amcpt.Spec.Template.Spec.VirtualNetwork.Name = "fooVnetName"
amcpt.Spec.Template.Spec.VirtualNetwork.Subnet.Name = "fooSubnetName"
amcpt.Spec.Template.Spec.SKU.Tier = PaidManagedControlPlaneTier
amcpt.Spec.Template.Spec.EnablePreviewFeatures = ptr.To(true)

err = mcptw.Default(context.Background(), amcpt)
g.Expect(err).NotTo(HaveOccurred())
Expand All @@ -63,6 +65,7 @@ func TestControlPlaneTemplateDefaultingWebhook(t *testing.T) {
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.Name).To(Equal("fooVnetName"))
g.Expect(amcpt.Spec.Template.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooSubnetName"))
g.Expect(amcpt.Spec.Template.Spec.SKU.Tier).To(Equal(StandardManagedControlPlaneTier))
g.Expect(*amcpt.Spec.Template.Spec.EnablePreviewFeatures).To(BeTrue())
}

func TestControlPlaneTemplateUpdateWebhook(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() azure.ASOResourceSpecGet
NetworkPluginMode: s.ControlPlane.Spec.NetworkPluginMode,
DNSPrefix: s.ControlPlane.Spec.DNSPrefix,
Patches: s.ControlPlane.Spec.ASOManagedClusterPatches,
Preview: ptr.Deref(s.ControlPlane.Spec.EnablePreviewFeatures, false),
}

if s.ControlPlane.Spec.SSHPublicKey != nil {
Expand Down Expand Up @@ -686,10 +687,6 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() azure.ASOResourceSpecGet
managedClusterSpec.SecurityProfile = s.getManagedClusterSecurityProfile()
}

if s.ControlPlane.Spec.EnablePreviewFeatures != nil {
managedClusterSpec.Preview = *s.ControlPlane.Spec.EnablePreviewFeatures
}

return &managedClusterSpec
}

Expand Down
5 changes: 1 addition & 4 deletions azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane,
EnableFIPS: managedMachinePool.Spec.EnableFIPS,
EnableEncryptionAtHost: managedMachinePool.Spec.EnableEncryptionAtHost,
Patches: managedMachinePool.Spec.ASOManagedClustersAgentPoolPatches,
Preview: ptr.Deref(managedControlPlane.Spec.EnablePreviewFeatures, false),
}

if managedMachinePool.Spec.OSDiskSizeGB != nil {
Expand Down Expand Up @@ -240,10 +241,6 @@ func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane,
}
}

if managedControlPlane.Spec.EnablePreviewFeatures != nil {
agentPoolSpec.Preview = *managedControlPlane.Spec.EnablePreviewFeatures
}

return agentPoolSpec
}

Expand Down
111 changes: 23 additions & 88 deletions azure/scope/managedmachinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,107 +900,42 @@ func TestManagedMachinePoolScope_KubeletDiskType(t *testing.T) {
}

func TestManagedMachinePoolScope_EnablePreviewFeatures(t *testing.T) {
scheme := runtime.NewScheme()
_ = expv1.AddToScheme(scheme)
_ = infrav1.AddToScheme(scheme)

cases := []struct {
Name string
Input ManagedMachinePoolScopeParams
Expected bool
Name string
previewEnabled *bool
Expected bool
}{
{
Name: "Without EnablePreviewFeatures",
Input: ManagedMachinePoolScopeParams{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
},
ControlPlane: &infrav1.AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
Spec: infrav1.AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
SubscriptionID: "00000000-0000-0000-0000-000000000000",
},
},
},
ManagedMachinePool: ManagedMachinePool{
MachinePool: getMachinePool("pool1"),
InfraMachinePool: getAzureMachinePool("pool1", infrav1.NodePoolModeUser),
},
},
Expected: false,
Name: "Without EnablePreviewFeatures",
previewEnabled: nil,
Expected: false,
},
{
Name: "With EnablePreviewFeatures false",
Input: ManagedMachinePoolScopeParams{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
},
ControlPlane: &infrav1.AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
Spec: infrav1.AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
SubscriptionID: "00000000-0000-0000-0000-000000000000",
EnablePreviewFeatures: ptr.To(false),
},
},
},
ManagedMachinePool: ManagedMachinePool{
MachinePool: getMachinePool("pool1"),
InfraMachinePool: getAzureMachinePool("pool1", infrav1.NodePoolModeUser),
},
},
Expected: false,
Name: "With EnablePreviewFeatures false",
previewEnabled: ptr.To(false),
Expected: false,
},
{
Name: "With EnablePreviewFeatures true",
Input: ManagedMachinePoolScopeParams{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
},
ControlPlane: &infrav1.AzureManagedControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Namespace: "default",
},
Spec: infrav1.AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
SubscriptionID: "00000000-0000-0000-0000-000000000000",
EnablePreviewFeatures: ptr.To(true),
},
},
},
ManagedMachinePool: ManagedMachinePool{
MachinePool: getMachinePool("pool1"),
InfraMachinePool: getAzureMachinePool("pool1", infrav1.NodePoolModeUser),
},
},
Expected: true,
Name: "With EnablePreviewFeatures true",
previewEnabled: ptr.To(true),
Expected: true,
},
}
for _, c := range cases {
c := c
t.Run(c.Name, func(t *testing.T) {
g := NewWithT(t)
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(c.Input.MachinePool, c.Input.InfraMachinePool, c.Input.ControlPlane).Build()
c.Input.Client = fakeClient
s, err := NewManagedMachinePoolScope(context.TODO(), c.Input)
g.Expect(err).To(Succeed())
s := &ManagedMachinePoolScope{
ControlPlane: &infrav1.AzureManagedControlPlane{
Spec: infrav1.AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
EnablePreviewFeatures: c.previewEnabled,
},
},
},
MachinePool: &expv1.MachinePool{},
InfraMachinePool: &infrav1.AzureManagedMachinePool{},
}
agentPoolGetter := s.AgentPoolSpec()
agentPool, ok := agentPoolGetter.(*agentpools.AgentPoolSpec)
g.Expect(ok).To(BeTrue())
Expand Down
4 changes: 2 additions & 2 deletions azure/services/agentpools/agentpools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func TestPostCreateOrUpdateResourceHook(t *testing.T) {
scope.EXPECT().SetCAPIMachinePoolReplicas(ptr.To(1234))
scope.EXPECT().IsPreviewEnabled().Return(true)

managedCluster := &asocontainerservicev1preview.ManagedClustersAgentPool{
agentPool := &asocontainerservicev1preview.ManagedClustersAgentPool{
Status: asocontainerservicev1preview.ManagedClusters_AgentPool_STATUS{
EnableAutoScaling: ptr.To(true),
Count: ptr.To(1234),
},
}

g.Expect(postCreateOrUpdateResourceHook(context.Background(), scope, managedCluster, nil)).To(Succeed())
g.Expect(postCreateOrUpdateResourceHook(context.Background(), scope, agentPool, nil)).To(Succeed())
})
}
Loading

0 comments on commit 5ff9539

Please sign in to comment.