@@ -5,13 +5,15 @@ package managementcomponents
5
5
6
6
import (
7
7
"context"
8
+ "fmt"
8
9
"os"
9
10
"time"
10
11
11
12
"github.com/pkg/errors"
12
13
"golang.org/x/sync/errgroup"
13
14
"k8s.io/apimachinery/pkg/labels"
14
15
"k8s.io/apimachinery/pkg/selection"
16
+ "k8s.io/apimachinery/pkg/types"
15
17
crtclient "sigs.k8s.io/controller-runtime/pkg/client"
16
18
17
19
kappipkg "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
@@ -196,3 +198,30 @@ func WaitForManagementPackages(clusterClient clusterclient.Client, packageInstal
196
198
}
197
199
return nil
198
200
}
201
+
202
+ // DeletePackageInstall deletes the PackageInstall CR
203
+ func noopDeletePackageInstall (ctx context.Context , clusterClient clusterclient.Client , pkgClient tkgpackageclient.TKGPackageClient , pkgiName , pkgiNamespace string ) error {
204
+ pkgi := & kappipkg.PackageInstall {}
205
+ err := clusterClient .GetResource (pkgi , pkgiName , pkgiNamespace , nil , nil )
206
+ if err != nil {
207
+ return errors .Wrapf (err , "unable to get PackageInstall resource %s" , pkgiName )
208
+ }
209
+
210
+ patchPkgiSpec := fmt .Sprintf ("{\" spec\" :{ \" noopDelete\" : %t}}" , true )
211
+ err = clusterClient .PatchResource (pkgi , pkgiName , pkgiNamespace , patchPkgiSpec , types .MergePatchType , nil )
212
+ if err != nil {
213
+ return errors .Wrapf (err , "failed to patch PackageInstall resource %s" , pkgiName )
214
+ }
215
+
216
+ packageInstalledOp := & tkgpackagedatamodel.PackageOptions {
217
+ PkgInstallName : pkgiName ,
218
+ Namespace : pkgiNamespace ,
219
+ }
220
+ err = pkgClient .UninstallPackageSync (packageInstalledOp )
221
+ //err = clusterClient.DeleteResource(pkgi)
222
+ if err != nil {
223
+ return errors .Wrapf (err , "failed to delete PackageInstall resource %s" , pkgiName )
224
+ }
225
+
226
+ return nil
227
+ }
0 commit comments