Skip to content

Commit

Permalink
Assign TenantID to managed cluster identity
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Guevara committed Jun 23, 2023
1 parent e30c5e0 commit 9675da8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/aks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ func createManagedCluster(ctx context.Context, cred *Credentials, workplacesClie
managedCluster.APIServerAccessProfile.EnablePrivateCluster = spec.PrivateCluster
}

if cred.TenantID != "" {
managedCluster.Identity = &containerservice.ManagedClusterIdentity{
TenantID: to.StringPtr(cred.TenantID),
Type: containerservice.ResourceIdentityTypeSystemAssigned,
}
}

return managedCluster, nil
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/aks/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var _ = Describe("newManagedCluster", func() {
cred = &Credentials{
ClientID: "test-client-id",
ClientSecret: "test-client-secret",
TenantID: "test-tenant-id",
}
})

Expand Down Expand Up @@ -147,6 +148,9 @@ var _ = Describe("newManagedCluster", func() {
Expect(ipRanges).To(HaveLen(1))
Expect(ipRanges[0]).To(Equal(clusterSpecIPRanges[0]))
Expect(managedCluster.APIServerAccessProfile.EnablePrivateCluster).To(Equal(clusterSpec.PrivateCluster))
Expect(managedCluster.Identity).ToNot(BeNil())
Expect(managedCluster.Identity.Type).To(Equal(containerservice.ResourceIdentityTypeSystemAssigned))
Expect(managedCluster.Identity.TenantID).To(Equal(to.StringPtr(cred.TenantID)))
})

It("should successfully create managed cluster with custom load balancer sku", func() {
Expand Down Expand Up @@ -366,6 +370,18 @@ var _ = Describe("newManagedCluster", func() {
Expect(err).ToNot(HaveOccurred())
Expect(managedCluster.ManagedClusterProperties.NodeResourceGroup).To(Equal(to.StringPtr(truncated)))
})

It("should successfully create managed cluster with no TenantID provided", func() {
workplacesClientMock.EXPECT().Get(ctx, to.String(clusterSpec.LogAnalyticsWorkspaceGroup), to.String(clusterSpec.LogAnalyticsWorkspaceName)).
Return(operationalinsights.Workspace{
ID: to.StringPtr("test-workspace-id"),
}, nil)
cred.TenantID = ""
managedCluster, err := createManagedCluster(ctx, cred, workplacesClientMock, clusterSpec, "test-phase")
Expect(err).ToNot(HaveOccurred())

Expect(managedCluster.Identity).To(BeNil())
})
})

var _ = Describe("CreateCluster", func() {
Expand Down

0 comments on commit 9675da8

Please sign in to comment.