Skip to content

Commit c26d2bb

Browse files
committed
pkg/infrastructure/azure: remove identity creation
Removes automatic creation of the user-assigned identity, as it is no longer required to authenticate the cloud-provider (CCM handles this). All subsequent identity-VM relationships will be handled directly through CAPZ. Subsequent commits will mirror the CAPZ API to the install config.
1 parent 191936a commit c26d2bb

File tree

1 file changed

+0
-106
lines changed

1 file changed

+0
-106
lines changed

pkg/infrastructure/azure/azure.go

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ import (
1414
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
1515
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1616
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
17-
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v3"
1817
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
19-
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi"
2018
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
2119
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
2220
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
2321
"github.com/coreos/stream-metadata-go/arch"
24-
"github.com/google/uuid"
2522
"github.com/sirupsen/logrus"
2623
corev1 "k8s.io/api/core/v1"
2724
"k8s.io/utils/ptr"
@@ -144,109 +141,6 @@ func (p *Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionI
144141
logrus.Debugf("ResourceGroup.ID=%s", *resourceGroup.ID)
145142
p.ResourceGroupName = resourceGroupName
146143

147-
// Create user assigned identity
148-
userAssignedIdentityName := fmt.Sprintf("%s-identity", in.InfraID)
149-
armmsiClientFactory, err := armmsi.NewClientFactory(
150-
subscriptionID,
151-
tokenCredential,
152-
&arm.ClientOptions{
153-
ClientOptions: policy.ClientOptions{
154-
Cloud: cloudConfiguration,
155-
},
156-
},
157-
)
158-
if err != nil {
159-
return fmt.Errorf("failed to create armmsi client: %w", err)
160-
}
161-
_, err = armmsiClientFactory.NewUserAssignedIdentitiesClient().CreateOrUpdate(
162-
ctx,
163-
resourceGroupName,
164-
userAssignedIdentityName,
165-
armmsi.Identity{
166-
Location: ptr.To(platform.Region),
167-
Tags: tags,
168-
},
169-
nil,
170-
)
171-
if err != nil {
172-
return fmt.Errorf("failed to create user assigned identity %s: %w", userAssignedIdentityName, err)
173-
}
174-
userAssignedIdentity, err := armmsiClientFactory.NewUserAssignedIdentitiesClient().Get(
175-
ctx,
176-
resourceGroupName,
177-
userAssignedIdentityName,
178-
nil,
179-
)
180-
if err != nil {
181-
return fmt.Errorf("failed to get user assigned identity %s: %w", userAssignedIdentityName, err)
182-
}
183-
principalID := *userAssignedIdentity.Properties.PrincipalID
184-
185-
logrus.Debugf("UserAssignedIdentity.ID=%s", *userAssignedIdentity.ID)
186-
logrus.Debugf("PrinciapalID=%s", principalID)
187-
188-
clientFactory, err := armauthorization.NewClientFactory(
189-
subscriptionID,
190-
tokenCredential,
191-
&arm.ClientOptions{
192-
ClientOptions: policy.ClientOptions{
193-
Cloud: cloudConfiguration,
194-
},
195-
},
196-
)
197-
if err != nil {
198-
return fmt.Errorf("failed to create armauthorization client: %w", err)
199-
}
200-
201-
roleDefinitionsClient := clientFactory.NewRoleDefinitionsClient()
202-
203-
var contributor *armauthorization.RoleDefinition
204-
roleDefinitionsPager := roleDefinitionsClient.NewListPager(*resourceGroup.ID, nil)
205-
for roleDefinitionsPager.More() {
206-
roleDefinitionsList, err := roleDefinitionsPager.NextPage(ctx)
207-
if err != nil {
208-
return fmt.Errorf("failed to find any role definitions: %w", err)
209-
}
210-
for _, roleDefinition := range roleDefinitionsList.Value {
211-
if *roleDefinition.Properties.RoleName == "Contributor" {
212-
contributor = roleDefinition
213-
break
214-
}
215-
}
216-
}
217-
if contributor == nil {
218-
return fmt.Errorf("failed to find contributor definition")
219-
}
220-
221-
roleAssignmentsClient := clientFactory.NewRoleAssignmentsClient()
222-
scope := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", subscriptionID, resourceGroupName)
223-
roleAssignmentUUID := uuid.New().String()
224-
225-
// XXX: Azure doesn't like creating an identity and immediately
226-
// creating a role assignment for the identity. There can be
227-
// replication delays. So, retry every 10 seconds for a minute until
228-
// the role assignment gets created.
229-
//
230-
// See https://aka.ms/docs-principaltype
231-
for i := 0; i < retryCount; i++ {
232-
_, err = roleAssignmentsClient.Create(ctx, scope, roleAssignmentUUID,
233-
armauthorization.RoleAssignmentCreateParameters{
234-
Properties: &armauthorization.RoleAssignmentProperties{
235-
PrincipalID: ptr.To(principalID),
236-
RoleDefinitionID: contributor.ID,
237-
},
238-
},
239-
nil,
240-
)
241-
if err == nil {
242-
break
243-
}
244-
time.Sleep(retryTime)
245-
}
246-
if err != nil {
247-
return fmt.Errorf("failed to create role assignment: %w", err)
248-
}
249-
250144
// Creating a dummy nsg for existing vnets installation to appease the ingress operator.
251145
if in.InstallConfig.Config.Azure.VirtualNetwork != "" {
252146
networkClientFactory, err := armnetwork.NewClientFactory(

0 commit comments

Comments
 (0)