@@ -37,7 +37,7 @@ type kube struct {
37
37
38
38
// Client has all the meathod for helm chart kube operation.
39
39
type 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 )
41
41
Delete (ctx context.Context , template []byte , oldResources []* csov1alpha1.Resource ) (newResources []* csov1alpha1.Resource , shouldRequeue bool , err error )
42
42
43
43
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
163
163
return newResources , shouldRequeue , nil
164
164
}
165
165
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 ) {
167
167
logger := log .FromContext (ctx )
168
168
169
169
objs , err := parseK8sYaml (template )
@@ -212,32 +212,29 @@ func (k *kube) Apply(ctx context.Context, template []byte, oldResources []*csov1
212
212
newResources = append (newResources , resource )
213
213
}
214
214
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
241
238
}
242
239
}
243
240
0 commit comments