@@ -283,23 +283,6 @@ func (r *GrafanaServiceAccountReconciler) reconcileWithInstance(
283
283
return fmt .Errorf ("upserting service account: %w" , err )
284
284
}
285
285
286
- updateForm := buildUpdateFormIfNeeded (& cr .Spec , cr .Status .Account )
287
- if updateForm != nil {
288
- update , err := gClient .ServiceAccounts .UpdateServiceAccount (
289
- service_accounts .
290
- NewUpdateServiceAccountParamsWithContext (ctx ).
291
- WithServiceAccountID (cr .Status .Account .ID ).
292
- WithBody (updateForm ),
293
- )
294
- if err != nil {
295
- return fmt .Errorf ("updating service account: %w" , err )
296
- }
297
-
298
- cr .Status .Account .IsDisabled = update .Payload .Serviceaccount .IsDisabled
299
- cr .Status .Account .Role = update .Payload .Serviceaccount .Role
300
- cr .Status .Account .Name = update .Payload .Serviceaccount .Name
301
- }
302
-
303
286
// Ensure tokens are always sorted for stable ordering
304
287
defer func () {
305
288
sort .Slice (cr .Status .Account .Tokens , func (i , j int ) bool {
@@ -351,37 +334,6 @@ func convertGrafanaExpiration(expiration strfmt.DateTime) *metav1.Time {
351
334
return ptr .To (metav1 .NewTime (time .Time (expiration )))
352
335
}
353
336
354
- // buildUpdateFormIfNeeded compares spec with current status and builds an update form if changes are needed.
355
- // Returns nil if the account is already in the desired state.
356
- func buildUpdateFormIfNeeded (spec * v1beta1.GrafanaServiceAccountSpec , status * v1beta1.GrafanaServiceAccountInfo ) * models.UpdateServiceAccountForm {
357
- form := & models.UpdateServiceAccountForm {
358
- // The form contains a ServiceAccountID field which is unused in Grafana, so it's ignored here.
359
- }
360
-
361
- hasChanges := false
362
-
363
- if status .Name != spec .Name {
364
- hasChanges = true
365
- form .Name = spec .Name
366
- }
367
-
368
- if status .Role != spec .Role {
369
- hasChanges = true
370
- form .Role = spec .Role
371
- }
372
-
373
- if status .IsDisabled != spec .IsDisabled {
374
- hasChanges = true
375
- form .IsDisabled = ptr .To (spec .IsDisabled )
376
- }
377
-
378
- if ! hasChanges {
379
- return nil
380
- }
381
-
382
- return form
383
- }
384
-
385
337
// removeOutdatedTokens removes tokens that are not in the desired spec or have mismatched expiration times.
386
338
// These tokens will be recreated later with the correct configuration.
387
339
func (r * GrafanaServiceAccountReconciler ) removeOutdatedTokens (
@@ -646,18 +598,24 @@ func (r *GrafanaServiceAccountReconciler) upsertAccount(
646
598
cr * v1beta1.GrafanaServiceAccount ,
647
599
) error {
648
600
if cr .Status .Account != nil {
649
- retrieve , err := gClient .ServiceAccounts .RetrieveServiceAccountWithParams (
601
+ update , err := gClient .ServiceAccounts .UpdateServiceAccount (
650
602
service_accounts .
651
- NewRetrieveServiceAccountParamsWithContext (ctx ).
652
- WithServiceAccountID (cr .Status .Account .ID ),
603
+ NewUpdateServiceAccountParamsWithContext (ctx ).
604
+ WithServiceAccountID (cr .Status .Account .ID ).
605
+ WithBody (& models.UpdateServiceAccountForm {
606
+ // The form contains a ServiceAccountID field which is unused in Grafana, so it's ignored here.
607
+ Name : cr .Spec .Name ,
608
+ Role : cr .Spec .Role ,
609
+ IsDisabled : ptr .To (cr .Spec .IsDisabled ),
610
+ }),
653
611
)
654
612
if err == nil {
655
613
cr .Status .Account = & v1beta1.GrafanaServiceAccountInfo {
656
- ID : retrieve .Payload .ID ,
657
- Role : retrieve .Payload .Role ,
658
- IsDisabled : retrieve .Payload .IsDisabled ,
659
- Name : retrieve .Payload .Name ,
660
- Login : retrieve .Payload .Login ,
614
+ ID : update .Payload . Serviceaccount .ID ,
615
+ Role : update .Payload . Serviceaccount .Role ,
616
+ IsDisabled : update .Payload . Serviceaccount .IsDisabled ,
617
+ Name : update .Payload . Serviceaccount .Name ,
618
+ Login : update .Payload . Serviceaccount .Login ,
661
619
}
662
620
663
621
// Load existing tokens from Grafana
@@ -684,14 +642,13 @@ func (r *GrafanaServiceAccountReconciler) upsertAccount(
684
642
return nil
685
643
}
686
644
687
- // ATM, service_accounts.RetrieveServiceAccountNotFound doesn't have Is, Unwrap, Unwrap.
645
+ // ATM, service_accounts.UpdateServiceAccountNotFound doesn't have Is, Unwrap, Unwrap.
688
646
// So, we cannot rely only on errors.Is().
689
- _ , notFound := err .(* service_accounts.RetrieveServiceAccountNotFound ) // nolint:errorlint
690
- if ! notFound && ! errors .Is (err , service_accounts .NewRetrieveServiceAccountNotFound ()) {
691
- return fmt .Errorf ("retrieving service account by ID %d : %w" , cr . Status . Account . ID , err )
647
+ _ , ok := err .(* service_accounts.UpdateServiceAccountNotFound ) // nolint:errorlint
648
+ if ! ok && ! errors .Is (err , service_accounts .NewUpdateServiceAccountNotFound ()) {
649
+ return fmt .Errorf ("updating service account: %w" , err )
692
650
}
693
651
694
- // Service account not found, clear the status and create a new one
695
652
cr .Status .Account = nil
696
653
}
697
654
0 commit comments