This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 26094c94 [operator] Fix uninstalling panic v2
26094c94 is described below
commit 26094c94f6f926e74ce8ac9d8b3e7e3be4e032bb
Author: mfordjody <[email protected]>
AuthorDate: Tue Dec 24 17:13:29 2024 +0800
[operator] Fix uninstalling panic v2
---
dubboctl/pkg/cli/context.go | 1 +
operator/cmd/cluster/uninstall.go | 8 +++++---
operator/pkg/config/protogvk.go | 2 +-
operator/pkg/manifest/name.go | 1 +
operator/pkg/uninstall/uninstaller.go | 15 +++++++++++----
pkg/config/schema/gvk/resources.gen.go | 1 -
6 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/dubboctl/pkg/cli/context.go b/dubboctl/pkg/cli/context.go
index bb210026..4899570c 100644
--- a/dubboctl/pkg/cli/context.go
+++ b/dubboctl/pkg/cli/context.go
@@ -12,6 +12,7 @@ type instance struct {
}
type Context interface {
+ CLIClientWithRevision(rev string) (kube.CLIClient, error)
CLIClient() (kube.CLIClient, error)
}
diff --git a/operator/cmd/cluster/uninstall.go
b/operator/cmd/cluster/uninstall.go
index 2c85e5e0..f32fb103 100644
--- a/operator/cmd/cluster/uninstall.go
+++ b/operator/cmd/cluster/uninstall.go
@@ -28,8 +28,8 @@ type uninstallArgs struct {
func addUninstallFlags(cmd *cobra.Command, args *uninstallArgs) {
cmd.PersistentFlags().StringVarP(&args.files, "filename", "f", "",
"The filename of the DubboOperator CR.")
- cmd.PersistentFlags().StringArrayVarP(&args.sets, "set", "s", nil,
"Override dubboOperator values, such as selecting profiles, etc")
- cmd.PersistentFlags().BoolVar(&args.purge, "purge", false, "Remove all
dubbo-related source code")
+ cmd.PersistentFlags().StringArrayVarP(&args.sets, "set", "s", nil,
`Override dubboOperator values, such as selecting profiles, etc.`)
+ cmd.PersistentFlags().BoolVar(&args.purge, "purge", false, `Remove all
dubbo related source code.`)
cmd.PersistentFlags().BoolVarP(&args.skipConfirmation,
"skip-confirmation", "y", false, `The skipConfirmation determines whether the
user is prompted for confirmation.`)
}
@@ -65,7 +65,7 @@ func UninstallCmd(ctx cli.Context) *cobra.Command {
return uicmd
}
-func Uninstall(cmd *cobra.Command, _ cli.Context, rootArgs *RootArgs, uiArgs
*uninstallArgs) error {
+func Uninstall(cmd *cobra.Command, ctx cli.Context, rootArgs *RootArgs, uiArgs
*uninstallArgs) error {
cl := clog.NewConsoleLogger(cmd.OutOrStdout(), cmd.ErrOrStderr(),
installerScope)
var kubeClient kube.CLIClient
var err error
@@ -74,6 +74,8 @@ func Uninstall(cmd *cobra.Command, _ cli.Context, rootArgs
*RootArgs, uiArgs *un
return err
}
+ kubeClient, err = ctx.CLIClientWithRevision("")
+
pl := progress.NewInfo()
if uiArgs.purge && uiArgs.files != "" {
cl.LogAndPrint(PurgeWithRevisionOrOperatorSpecifiedWarning)
diff --git a/operator/pkg/config/protogvk.go b/operator/pkg/config/protogvk.go
index a45680a0..b20cd64b 100644
--- a/operator/pkg/config/protogvk.go
+++ b/operator/pkg/config/protogvk.go
@@ -27,7 +27,7 @@ func (g GroupVersionKind) CanonicalGroup() string {
return CanoncalGroup(g.Group)
}
-func (g GroupVersionKind) K8s() schema.GroupVersionKind {
+func (g GroupVersionKind) Kubernetes() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: g.Group,
Version: g.Version,
diff --git a/operator/pkg/manifest/name.go b/operator/pkg/manifest/name.go
index 27923f2d..8d26cc4b 100644
--- a/operator/pkg/manifest/name.go
+++ b/operator/pkg/manifest/name.go
@@ -3,4 +3,5 @@ package manifest
const (
OwningResourceName = "install.operator.dubbo.io/owning-resource"
OwningResourceNamespace =
"install.operator.dubbo.io/owning-resource-namespace"
+ DubboComponentLabel = "operator.dubbo.io/component"
)
diff --git a/operator/pkg/uninstall/uninstaller.go
b/operator/pkg/uninstall/uninstaller.go
index dae48994..54e87e96 100644
--- a/operator/pkg/uninstall/uninstaller.go
+++ b/operator/pkg/uninstall/uninstaller.go
@@ -12,17 +12,19 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+ klabels "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
+ "k8s.io/apimachinery/pkg/selection"
)
var (
ClusterResources = []schema.GroupVersionKind{}
ClusterCPResources = []schema.GroupVersionKind{}
AllClusterResources = append(ClusterResources,
- gvk.CustomResourceDefinition.K8s())
+ gvk.CustomResourceDefinition.Kubernetes())
)
-func GetPrunedResources(clt kube.CLIClient, dopName, dopNamespace string,
includeClusterResources bool) ([]*unstructured.UnstructuredList, error) {
+func GetPrunedResources(kcli kube.CLIClient, dopName, dopNamespace string,
includeClusterResources bool) ([]*unstructured.UnstructuredList, error) {
var usList []*unstructured.UnstructuredList
labels := make(map[string]string)
if dopName != "" {
@@ -38,12 +40,17 @@ func GetPrunedResources(clt kube.CLIClient, dopName,
dopNamespace string, includ
}
for _, g := range gvkList {
var result *unstructured.UnstructuredList
- c, err := clt.DynamicClientFor(g, nil, "")
+ compReq, err :=
klabels.NewRequirement(manifest.DubboComponentLabel, selection.Exists, nil)
+ if err != nil {
+ return nil, err
+ }
+ c, err := kcli.DynamicClientFor(g, nil, "")
if err != nil {
return nil, err
}
if includeClusterResources {
- result, err = c.List(context.Background(),
metav1.ListOptions{})
+ s := klabels.NewSelector()
+ result, err = c.List(context.Background(),
metav1.ListOptions{LabelSelector: s.Add(*compReq).String()})
}
if result == nil || len(result.Items) == 0 {
continue
diff --git a/pkg/config/schema/gvk/resources.gen.go
b/pkg/config/schema/gvk/resources.gen.go
index 87fcb94a..4fb124cb 100644
--- a/pkg/config/schema/gvk/resources.gen.go
+++ b/pkg/config/schema/gvk/resources.gen.go
@@ -17,7 +17,6 @@ func ToGVR(g config.GroupVersionKind)
(schema.GroupVersionResource, bool) {
}
return schema.GroupVersionResource{}, false
}
-
func MustToGVR(g config.GroupVersionKind) schema.GroupVersionResource {
r, ok := ToGVR(g)
if !ok {