Skip to content

Commit 33a53fc

Browse files
giorio94adamjensenbot
authored andcommitted
liqoctl uninstall: add uninstallation check
1 parent 7524b89 commit 33a53fc

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

cmd/liqoctl/cmd/peer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func newPeerInBandCommand(ctx context.Context, peerOptions *peer.Options) *cobra
170170
Aliases: []string{"ib"},
171171
Short: "Enable an in-band peering towards a remote cluster",
172172
Long: WithTemplate(liqoctlPeerIBLongHelp),
173+
Args: cobra.NoArgs,
173174

174175
PersistentPreRun: func(cmd *cobra.Command, args []string) {
175176
twoClustersPersistentPreRun(cmd, local, remote, factory.WithScopedPrinter)

cmd/liqoctl/cmd/uninstall.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func newUninstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command
4747
Use: "uninstall",
4848
Short: "Uninstall Liqo from the selected cluster",
4949
Long: WithTemplate(liqoctlUninstallLongHelp),
50+
Args: cobra.NoArgs,
5051

5152
Run: func(cmd *cobra.Command, args []string) {
5253
output.ExitOnErr(options.Run(ctx))

cmd/liqoctl/cmd/unpeer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func newUnpeerInBandCommand(ctx context.Context, unpeerOptions *unpeeroob.Option
139139
Aliases: []string{"ib"},
140140
Short: "Disable an in-band peering towards a remote cluster",
141141
Long: WithTemplate(liqoctlUnpeerIBLongHelp),
142+
Args: cobra.NoArgs,
142143

143144
PersistentPreRun: func(cmd *cobra.Command, args []string) {
144145
twoClustersPersistentPreRun(cmd, local, remote, factory.WithScopedPrinter)

pkg/liqoctl/uninstall/handler.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"helm.sh/helm/v3/pkg/storage/driver"
2424
corev1 "k8s.io/api/core/v1"
25+
rbacv1 "k8s.io/api/rbac/v1"
2526
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -70,6 +71,13 @@ func (o *Options) Run(ctx context.Context) error {
7071
s.Fail("Error uninstalling Liqo: ", output.PrettyErr(err))
7172
return err
7273
}
74+
75+
// Ensure liqo has been correctly uninstalled before continuing, to prevent leaving leftover resources behind.
76+
if err := o.checkUninstalled(ctx); err != nil {
77+
s.Fail("Error uninstalling Liqo: ", output.PrettyErr(err))
78+
return err
79+
}
80+
7381
s.Success("Liqo uninstalled")
7482

7583
if o.Purge {
@@ -92,6 +100,19 @@ func (o *Options) Run(ctx context.Context) error {
92100
return nil
93101
}
94102

103+
func (o *Options) checkUninstalled(ctx context.Context) error {
104+
var clusterRoles rbacv1.ClusterRoleList
105+
if err := o.CRClient.List(ctx, &clusterRoles, client.MatchingLabels{"app.kubernetes.io/part-of": install.LiqoReleaseName}); err != nil {
106+
return fmt.Errorf("failed checking whether cluster-wide resources have been removed: %w", err)
107+
}
108+
109+
if len(clusterRoles.Items) > 0 {
110+
return errors.New("cluster-wide resources are still present - did you specify the right namespace?")
111+
}
112+
113+
return nil
114+
}
115+
95116
func (o *Options) purge(ctx context.Context) error {
96117
for _, groupVersion := range liqoGroupVersions {
97118
res, err := o.KubeClient.Discovery().ServerResourcesForGroupVersion(groupVersion.String())

0 commit comments

Comments
 (0)