@@ -186,54 +186,60 @@ func (c *profileClient) List(ctx context.Context, list model.ListInterface, revi
186
186
return nil , err
187
187
}
188
188
189
- // Enumerate matching namespaces, paginated.
190
- listFunc := func (ctx context.Context , opts metav1.ListOptions ) (runtime.Object , error ) {
191
- if saName != "" {
192
- // We've been asked to list a particular service account, skip
193
- // listing namespaces.
194
- return & v1.NamespaceList {}, nil
189
+ var nsKVPs * model.KVPairList
190
+ if saName == "" {
191
+ // We haven't been asked for a specific service account, so we
192
+ // must query the namespaces.
193
+ listFunc := func (ctx context.Context , opts metav1.ListOptions ) (runtime.Object , error ) {
194
+ if nsName != "" {
195
+ opts .FieldSelector = fields .OneTermEqualSelector ("metadata.name" , nsName ).String ()
196
+ }
197
+ return c .clientSet .CoreV1 ().Namespaces ().List (ctx , opts )
195
198
}
196
- if nsName != "" {
197
- opts .FieldSelector = fields .OneTermEqualSelector ("metadata.name" , nsName ).String ()
199
+ convertFunc := func (r Resource ) ([]* model.KVPair , error ) {
200
+ ns := r .(* v1.Namespace )
201
+ kvp , err := c .getNsKv (ns )
202
+ if err != nil {
203
+ return nil , err
204
+ }
205
+ return []* model.KVPair {kvp }, nil
198
206
}
199
- return c .clientSet .CoreV1 ().Namespaces ().List (ctx , opts )
200
- }
201
- convertFunc := func (r Resource ) ([]* model.KVPair , error ) {
202
- ns := r .(* v1.Namespace )
203
- kvp , err := c .getNsKv (ns )
207
+ nsKVPs , err = pagedList (ctx , logContext .WithField ("from" , "namespaces" ), nsRev , list , convertFunc , listFunc )
204
208
if err != nil {
205
209
return nil , err
206
210
}
207
- return []* model.KVPair {kvp }, nil
208
- }
209
- nsKVPs , err := pagedList (ctx , logContext .WithField ("from" , "namespaces" ), nsRev , list , convertFunc , listFunc )
210
- if err != nil {
211
- return nil , err
212
- }
213
-
214
- // Enumerate matching service accounts, paginated.
215
- listFunc = func (ctx context.Context , opts metav1.ListOptions ) (runtime.Object , error ) {
216
- if nsName != "" && saName == "" {
217
- // We've been asked to list a particular namespace, skip
218
- // listing service accounts.
219
- return & v1.ServiceAccountList {}, nil
211
+ } else {
212
+ // We have been asked for a specific service account, so we don't
213
+ // need to query namespaces.
214
+ nsKVPs = & model.KVPairList {}
215
+ }
216
+
217
+ var saKVPs * model.KVPairList
218
+ if nsName == "" || saName != "" {
219
+ // We haven't been asked for a specific namespace, so we need to
220
+ // query the service accounts.
221
+ listFunc := func (ctx context.Context , opts metav1.ListOptions ) (runtime.Object , error ) {
222
+ if saName != "" {
223
+ opts .FieldSelector = fields .OneTermEqualSelector ("metadata.name" , saName ).String ()
224
+ }
225
+ return c .clientSet .CoreV1 ().ServiceAccounts (nsName ).List (ctx , opts )
220
226
}
221
- if saName != "" {
222
- opts .FieldSelector = fields .OneTermEqualSelector ("metadata.name" , saName ).String ()
227
+ convertFunc := func (r Resource ) ([]* model.KVPair , error ) {
228
+ sa := r .(* v1.ServiceAccount )
229
+ kvp , err := c .getSaKv (sa )
230
+ if err != nil {
231
+ return nil , err
232
+ }
233
+ return []* model.KVPair {kvp }, nil
223
234
}
224
- return c .clientSet .CoreV1 ().ServiceAccounts (nsName ).List (ctx , opts )
225
- }
226
- convertFunc = func (r Resource ) ([]* model.KVPair , error ) {
227
- sa := r .(* v1.ServiceAccount )
228
- kvp , err := c .getSaKv (sa )
235
+ saKVPs , err = pagedList (ctx , logContext .WithField ("from" , "serviceaccounts" ), saRev , list , convertFunc , listFunc )
229
236
if err != nil {
230
237
return nil , err
231
238
}
232
- return []* model.KVPair {kvp }, nil
233
- }
234
- saKVPs , err := pagedList (ctx , logContext .WithField ("from" , "serviceaccounts" ), saRev , list , convertFunc , listFunc )
235
- if err != nil {
236
- return nil , err
239
+ } else {
240
+ // We have been asked for a specific namespace, so we don't need to
241
+ // query service accounts.
242
+ saKVPs = & model.KVPairList {}
237
243
}
238
244
239
245
// Return a merged KVPairList including both results and the default-allow profile.
0 commit comments