@@ -14,14 +14,11 @@ import (
14
14
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
15
15
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
16
16
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
17
- "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v3"
18
17
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
19
- "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi"
20
18
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
21
19
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
22
20
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
23
21
"github.com/coreos/stream-metadata-go/arch"
24
- "github.com/google/uuid"
25
22
"github.com/sirupsen/logrus"
26
23
corev1 "k8s.io/api/core/v1"
27
24
"k8s.io/utils/ptr"
@@ -144,109 +141,6 @@ func (p *Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionI
144
141
logrus .Debugf ("ResourceGroup.ID=%s" , * resourceGroup .ID )
145
142
p .ResourceGroupName = resourceGroupName
146
143
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
-
250
144
// Creating a dummy nsg for existing vnets installation to appease the ingress operator.
251
145
if in .InstallConfig .Config .Azure .VirtualNetwork != "" {
252
146
networkClientFactory , err := armnetwork .NewClientFactory (
0 commit comments