@@ -35,7 +35,8 @@ type Migrator struct {
35
35
eksAPI awsapi.EKS
36
36
iamAPI awsapi.IAM
37
37
clientSet kubernetes.Interface
38
- aeCreator Creator
38
+ aeCreator CreatorInterface
39
+ aeGetter GetterInterface
39
40
curAuthMode ekstypes.AuthenticationMode
40
41
tgAuthMode ekstypes.AuthenticationMode
41
42
}
@@ -45,7 +46,8 @@ func NewMigrator(
45
46
eksAPI awsapi.EKS ,
46
47
iamAPI awsapi.IAM ,
47
48
clientSet kubernetes.Interface ,
48
- aeCreator Creator ,
49
+ aeCreator CreatorInterface ,
50
+ aeGetter GetterInterface ,
49
51
curAuthMode ekstypes.AuthenticationMode ,
50
52
tgAuthMode ekstypes.AuthenticationMode ,
51
53
) * Migrator {
@@ -55,6 +57,7 @@ func NewMigrator(
55
57
iamAPI : iamAPI ,
56
58
clientSet : clientSet ,
57
59
aeCreator : aeCreator ,
60
+ aeGetter : aeGetter ,
58
61
curAuthMode : curAuthMode ,
59
62
tgAuthMode : tgAuthMode ,
60
63
}
@@ -84,21 +87,17 @@ func (m *Migrator) MigrateToAccessEntry(ctx context.Context, options MigrationOp
84
87
})
85
88
}
86
89
87
- cmEntries , err := m .doGetIAMIdentityMappings (ctx )
88
- if err != nil {
89
- return err
90
- }
91
-
92
- curAccessEntries , err := m .doGetAccessEntries (ctx )
90
+ curAccessEntries , err := m .aeGetter .Get (ctx , api.ARN {})
93
91
if err != nil && m .curAuthMode != ekstypes .AuthenticationModeConfigMap {
94
- return err
92
+ return fmt . Errorf ( "fetching existing access entries: %w" , err )
95
93
}
96
94
97
- newAccessEntries , skipAPImode , err := doFilterAccessEntries ( cmEntries , curAccessEntries )
95
+ cmEntries , err := m . doGetIAMIdentityMappings ( ctx )
98
96
if err != nil {
99
97
return err
100
98
}
101
99
100
+ newAccessEntries , skipAPImode := doFilterAccessEntries (cmEntries , curAccessEntries )
102
101
if len (newAccessEntries ) > 0 {
103
102
aeTasks := m .aeCreator .CreateTasks (ctx , newAccessEntries )
104
103
aeTasks .IsSubTask = true
@@ -162,11 +161,6 @@ func (m *Migrator) doUpdateAuthenticationMode(ctx context.Context, authMode ekst
162
161
}
163
162
}
164
163
165
- func (m * Migrator ) doGetAccessEntries (ctx context.Context ) ([]Summary , error ) {
166
- aeGetter := NewGetter (m .clusterName , m .eksAPI )
167
- return aeGetter .Get (ctx , api.ARN {})
168
- }
169
-
170
164
func (m * Migrator ) doGetIAMIdentityMappings (ctx context.Context ) ([]iam.Identity , error ) {
171
165
acm , err := authconfigmap .NewFromClientSet (m .clientSet )
172
166
if err != nil {
@@ -197,7 +191,7 @@ func (m *Migrator) doGetIAMIdentityMappings(ctx context.Context) ([]iam.Identity
197
191
getRoleOutput , err := m .iamAPI .GetRole (ctx , & awsiam.GetRoleInput {RoleName : & cmeName })
198
192
if err != nil {
199
193
if errors .As (err , & noSuchEntity ) {
200
- return nil , fmt .Errorf ("role %s does not exists, either delete the iamidentitymapping using \" eksctl delete iamidentitymapping --cluster %s --arn %s\" or create the role in AWS" , cmeName , m .clusterName , cme .ARN ())
194
+ return nil , fmt .Errorf ("role %q does not exists, either delete the iamidentitymapping using \" eksctl delete iamidentitymapping --cluster %s --arn %s\" or create the role in AWS" , cmeName , m .clusterName , cme .ARN ())
201
195
}
202
196
return nil , err
203
197
}
@@ -218,7 +212,7 @@ func (m *Migrator) doGetIAMIdentityMappings(ctx context.Context) ([]iam.Identity
218
212
getUserOutput , err := m .iamAPI .GetUser (ctx , & awsiam.GetUserInput {UserName : & cmeName })
219
213
if err != nil {
220
214
if errors .As (err , & noSuchEntity ) {
221
- return nil , fmt .Errorf ("user \" %s \" does not exists, either delete the iamidentitymapping using \" eksctl delete iamidentitymapping --cluster %s --arn %s\" or create the user in AWS" , cmeName , m .clusterName , cme .ARN ())
215
+ return nil , fmt .Errorf ("user %q does not exists, either delete the iamidentitymapping using \" eksctl delete iamidentitymapping --cluster %s --arn %s\" or create the user in AWS" , cmeName , m .clusterName , cme .ARN ())
222
216
}
223
217
return nil , err
224
218
}
@@ -231,7 +225,7 @@ func (m *Migrator) doGetIAMIdentityMappings(ctx context.Context) ([]iam.Identity
231
225
return cmEntries , nil
232
226
}
233
227
234
- func doFilterAccessEntries (cmEntries []iam.Identity , accessEntries []Summary ) ([]api.AccessEntry , bool , error ) {
228
+ func doFilterAccessEntries (cmEntries []iam.Identity , accessEntries []Summary ) ([]api.AccessEntry , bool ) {
235
229
236
230
skipAPImode := false
237
231
var toDoEntries []api.AccessEntry
@@ -268,7 +262,7 @@ func doFilterAccessEntries(cmEntries []iam.Identity, accessEntries []Summary) ([
268
262
skipAPImode = true
269
263
}
270
264
case iam .ResourceTypeAccount :
271
- logger .Warning ("found account iamidentitymapping \" %s \" , can not create access entry" , cme .Account ())
265
+ logger .Warning ("found account iamidentitymapping %q, cannot create access entry, skipping " , cme .Account ())
272
266
skipAPImode = true
273
267
}
274
268
} else {
@@ -277,7 +271,7 @@ func doFilterAccessEntries(cmEntries []iam.Identity, accessEntries []Summary) ([
277
271
}
278
272
}
279
273
280
- return toDoEntries , skipAPImode , nil
274
+ return toDoEntries , skipAPImode
281
275
}
282
276
283
277
func doBuildNodeRoleAccessEntry (cme iam.Identity ) * api.AccessEntry {
@@ -295,7 +289,7 @@ func doBuildNodeRoleAccessEntry(cme iam.Identity) *api.AccessEntry {
295
289
Type : "EC2_LINUX" ,
296
290
}
297
291
}
298
- // For windows Nodes
292
+ // For Windows Nodes
299
293
return & api.AccessEntry {
300
294
PrincipalARN : api .MustParseARN (cme .ARN ()),
301
295
Type : "EC2_WINDOWS" ,
@@ -327,7 +321,7 @@ func doBuildAccessEntry(cme iam.Identity) *api.AccessEntry {
327
321
}
328
322
329
323
if containsSys { // Check if any GroupName start with "system:"" in name
330
- logger .Warning ("at least one group name associated with %s starts with \" system:\" , can not create access entry, skipping" , cme .ARN ())
324
+ logger .Warning ("at least one group name associated with %q starts with \" system:\" , can not create access entry, skipping" , cme .ARN ())
331
325
return nil
332
326
}
333
327
@@ -343,5 +337,4 @@ func doBuildAccessEntry(cme iam.Identity) *api.AccessEntry {
343
337
func doDeleteAWSAuthConfigMap (ctx context.Context , clientset kubernetes.Interface , namespace , name string ) error {
344
338
logger .Info ("deleting %q ConfigMap as it is no longer needed in API mode" , name )
345
339
return clientset .CoreV1 ().ConfigMaps (namespace ).Delete (ctx , name , metav1.DeleteOptions {})
346
-
347
340
}
0 commit comments