@@ -37,7 +37,7 @@ type kube struct {
3737
3838// Client has all the meathod for helm chart kube operation.
3939type Client interface {
40- Apply (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource , shouldDelete bool ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error )
40+ Apply (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error )
4141 Delete (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error )
4242
4343 ApplyNewClusterStack (ctx context.Context , oldTemplate , newTemplate []byte ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error )
@@ -163,7 +163,7 @@ func (k *kube) DeleteNewClusterStack(ctx context.Context, template []byte) (newR
163163 return newResources , shouldRequeue , nil
164164}
165165
166- func (k * kube ) Apply (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource , shouldDelete bool ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error ) {
166+ func (k * kube ) Apply (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error ) {
167167 logger := log .FromContext (ctx )
168168
169169 objs , err := parseK8sYaml (template )
@@ -212,32 +212,29 @@ func (k *kube) Apply(ctx context.Context, template []byte, oldResources []*csov1
212212 newResources = append (newResources , resource )
213213 }
214214
215- // TODO: cleanup shouldDelete
216- if shouldDelete {
217- // make a diff between new objs and oldResources to find out
218- // a) if an object is in oldResources and synced and not in new objs, then delete should be attempted
219- // then, all objs should be applied by create or update
220- // at the end, we should delete objects that are supposed to be deleted
221- for _ , resource := range resourcesToBeDeleted (oldResources , objs ) {
222- // call the function and get dynamic.ResourceInterface
223- // getDynamicResourceInterface
224- logger .Info ("resource are being deleted" , "kind" , resource .Kind , "name" , resource .Name , "namespace" , resource .Namespace )
225-
226- dr , err := GetDynamicResourceInterface (k .Namespace , k .RestConfig , resource .GroupVersionKind ())
227- if err != nil {
228- return nil , false , fmt .Errorf ("failed to get dynamic resource interface: %w" , err )
229- }
230-
231- if err := dr .Delete (ctx , resource .Name , metav1.DeleteOptions {}); err != nil && ! apierrors .IsNotFound (err ) {
232- reterr := fmt .Errorf ("failed to delete object: %w" , err )
233- logger .Error (reterr , "failed to delete object" , "obj" , resource .GroupVersionKind (), "namespacedName" , resource .NamespacedName ())
234-
235- // append resource to status and requeue again to be able to retry deletion
236- resource .Status = csov1alpha1 .ResourceStatusNotSynced
237- resource .Error = reterr .Error ()
238- newResources = append (newResources , resource )
239- shouldRequeue = true
240- }
215+ // make a diff between new objs and oldResources to find out
216+ // a) if an object is in oldResources and synced and not in new objs, then delete should be attempted
217+ // then, all objs should be applied by create or update
218+ // at the end, we should delete objects that are supposed to be deleted
219+ for _ , resource := range resourcesToBeDeleted (oldResources , objs ) {
220+ // call the function and get dynamic.ResourceInterface
221+ // getDynamicResourceInterface
222+ logger .Info ("resource are being deleted" , "kind" , resource .Kind , "name" , resource .Name , "namespace" , resource .Namespace )
223+
224+ dr , err := GetDynamicResourceInterface (k .Namespace , k .RestConfig , resource .GroupVersionKind ())
225+ if err != nil {
226+ return nil , false , fmt .Errorf ("failed to get dynamic resource interface: %w" , err )
227+ }
228+
229+ if err := dr .Delete (ctx , resource .Name , metav1.DeleteOptions {}); err != nil && ! apierrors .IsNotFound (err ) {
230+ reterr := fmt .Errorf ("failed to delete object: %w" , err )
231+ logger .Error (reterr , "failed to delete object" , "obj" , resource .GroupVersionKind (), "namespacedName" , resource .NamespacedName ())
232+
233+ // append resource to status and requeue again to be able to retry deletion
234+ resource .Status = csov1alpha1 .ResourceStatusNotSynced
235+ resource .Error = reterr .Error ()
236+ newResources = append (newResources , resource )
237+ shouldRequeue = true
241238 }
242239 }
243240
0 commit comments