@@ -528,23 +528,24 @@ func (a *Agent) deleteApplication(app *v1alpha1.Application) error {
528
528
529
529
logCtx .Infof ("Deleting application" )
530
530
531
+ if a .mode == types .AgentModeManaged {
532
+ a .sourceCache .Application .Delete (app .UID )
533
+ }
534
+
531
535
deletionPropagation := backend .DeletePropagationBackground
532
536
err := a .appManager .Delete (a .context , a .namespace , app , & deletionPropagation )
533
537
if err != nil {
534
538
if apierrors .IsNotFound (err ) {
535
539
logCtx .Debug ("application is not found, perhaps it is already deleted" )
536
- if a .mode == types .AgentModeManaged {
537
- a .sourceCache .Application .Delete (app .UID )
538
- }
539
540
return nil
540
541
}
542
+ // Restore the cache if the deletion fails
543
+ if a .mode == types .AgentModeManaged {
544
+ a .sourceCache .Application .Set (app .UID , app .Spec )
545
+ }
541
546
return err
542
547
}
543
548
544
- if a .mode == types .AgentModeManaged {
545
- a .sourceCache .Application .Delete (app .UID )
546
- }
547
-
548
549
err = a .appManager .Unmanage (app .QualifiedName ())
549
550
if err != nil {
550
551
log ().Warnf ("Could not unmanage app %s: %v" , app .QualifiedName (), err )
@@ -635,6 +636,8 @@ func (a *Agent) deleteAppProject(project *v1alpha1.AppProject) error {
635
636
636
637
logCtx .Infof ("Deleting appProject" )
637
638
639
+ a .sourceCache .AppProject .Delete (project .UID )
640
+
638
641
deletionPropagation := backend .DeletePropagationBackground
639
642
err := a .projectManager .Delete (a .context , project , & deletionPropagation )
640
643
if err != nil {
@@ -643,11 +646,11 @@ func (a *Agent) deleteAppProject(project *v1alpha1.AppProject) error {
643
646
a .sourceCache .AppProject .Delete (project .UID )
644
647
return nil
645
648
}
649
+ // Restore the cache if the deletion fails
650
+ a .sourceCache .AppProject .Set (project .UID , project .Spec )
646
651
return err
647
652
}
648
653
649
- a .sourceCache .AppProject .Delete (project .UID )
650
-
651
654
err = a .projectManager .Unmanage (project .Name )
652
655
if err != nil {
653
656
log ().Warnf ("Could not unmanage appProject %s: %v" , project .Name , err )
@@ -682,6 +685,8 @@ func (a *Agent) createRepository(incoming *corev1.Secret) (*corev1.Secret, error
682
685
incoming .Annotations = make (map [string ]string )
683
686
}
684
687
688
+ a .sourceCache .Repository .Set (incoming .UID , incoming .Data )
689
+
685
690
// Get rid of some fields that we do not want to have on the repository as we start fresh.
686
691
delete (incoming .Annotations , "kubectl.kubernetes.io/last-applied-configuration" )
687
692
@@ -716,6 +721,8 @@ func (a *Agent) updateRepository(incoming *corev1.Secret) (*corev1.Secret, error
716
721
717
722
logCtx .Infof ("Updating repository" )
718
723
724
+ a .sourceCache .Repository .Set (incoming .UID , incoming .Data )
725
+
719
726
return a .repoManager .UpdateManagedRepository (a .context , incoming )
720
727
}
721
728
@@ -732,13 +739,17 @@ func (a *Agent) deleteRepository(repo *corev1.Secret) error {
732
739
733
740
logCtx .Infof ("Deleting repository" )
734
741
742
+ a .sourceCache .Repository .Delete (repo .UID )
743
+
735
744
deletionPropagation := backend .DeletePropagationBackground
736
745
err := a .repoManager .Delete (a .context , repo .Name , repo .Namespace , & deletionPropagation )
737
746
if err != nil {
738
747
if apierrors .IsNotFound (err ) {
739
748
logCtx .Debug ("repository is not found, perhaps it is already deleted" )
740
749
return nil
741
750
}
751
+ // Restore the cache if the deletion fails
752
+ a .sourceCache .Repository .Set (repo .UID , repo .Data )
742
753
return err
743
754
}
744
755
0 commit comments