@@ -104,6 +104,9 @@ func pausePackageInstallReconciliation(ctx context.Context, clusterClient cluste
104
104
// PausedAdoonLifecycleManagement pauses/unpauses the lifecycle management of addon package with given name and namespace
105
105
func PauseAddonLifecycleManagement (mcip * ManagementComponentsInstallOptions , addonName , namespace string ) error {
106
106
clusterClient , err := clusterclient .NewClient (mcip .ClusterOptions .Kubeconfig , mcip .ClusterOptions .Kubecontext , clusterclient.Options {})
107
+ if err != nil {
108
+ return err
109
+ }
107
110
clusterName , err := clusterClient .GetCurrentClusterName (mcip .ClusterOptions .Kubecontext )
108
111
if err != nil {
109
112
return err
@@ -142,7 +145,7 @@ func InstallManagementComponents(mcip *ManagementComponentsInstallOptions) error
142
145
panic (err )
143
146
}
144
147
145
- // TODO (adduarte) add pkgi delete call
148
+ err = NoopDeletePackageInstall ( mcip , "addons-manager" , constants . TkgNamespace )
146
149
147
150
// TODO (adduarte) add addonsecret delete call
148
151
@@ -281,3 +284,33 @@ func WaitForManagementPackages(clusterClient clusterclient.Client, packageInstal
281
284
}
282
285
return nil
283
286
}
287
+
288
+ // NoopDeletePackageInstall sets spec.noopdelete = true before deleting the package install
289
+ func NoopDeletePackageInstall (mcip * ManagementComponentsInstallOptions , addonName , namespace string ) error {
290
+ clusterClient , err := clusterclient .NewClient (mcip .ClusterOptions .Kubeconfig , mcip .ClusterOptions .Kubecontext , clusterclient.Options {})
291
+ if err != nil {
292
+ return err
293
+ }
294
+ pkgiName := fmt .Sprintf ("tanzu-%s" , addonName )
295
+
296
+ jsonPatch := []map [string ]interface {}{
297
+ {
298
+ "op" : "add" ,
299
+ "path" : "/spec/noopDelete" ,
300
+ "value" : true ,
301
+ },
302
+ }
303
+ payloadBytes , err := json .Marshal (jsonPatch )
304
+ if err != nil {
305
+ return errors .Wrap (err , "unable to generate json patch" )
306
+ }
307
+ pkgi := & kappipkg.PackageInstall {}
308
+ err = clusterClient .PatchResource (pkgi , pkgiName , namespace , string (payloadBytes ), types .JSONPatchType , nil )
309
+ if apierrors .IsNotFound (err ) {
310
+ return nil
311
+ }
312
+ if err != nil {
313
+ return errors .Wrapf (err , "failed to patch %s packageinstall" , pkgiName )
314
+ }
315
+ return nil
316
+ }
0 commit comments