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 d0acf64a [operator] Trying to implement the unloading logic
d0acf64a is described below

commit d0acf64a59c9683d016200d84ce06266de63ea88
Author: mfordjody <[email protected]>
AuthorDate: Tue Dec 24 12:23:23 2024 +0800

    [operator] Trying to implement the unloading logic
---
 operator/pkg/uninstall/uninstaller.go  | 15 ++++++++-----
 pkg/config/schema/gvk/resources.gen.go | 39 +++++++++++++++++++++++++++++++++-
 pkg/config/schema/gvr/resource.gen.go  |  7 ++++++
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/operator/pkg/uninstall/uninstaller.go 
b/operator/pkg/uninstall/uninstaller.go
index 629e5011..e420bb7f 100644
--- a/operator/pkg/uninstall/uninstaller.go
+++ b/operator/pkg/uninstall/uninstaller.go
@@ -17,7 +17,9 @@ import (
 
 var (
        ClusterResources    = []schema.GroupVersionKind{}
-       AllClusterResources = append(ClusterResources, 
gvk.CustomResourceDefinition.K8s())
+       AllClusterResources = append(ClusterResources,
+               gvk.CustomResourceDefinition.K8s())
+       ClusterCPResources []schema.GroupVersionKind
 )
 
 func GetPrunedResources(clt kube.CLIClient, dopName, dopNamespace string, 
includeClusterResources bool) ([]*unstructured.UnstructuredList, error) {
@@ -30,10 +32,13 @@ func GetPrunedResources(clt kube.CLIClient, dopName, 
dopNamespace string, includ
                labels[manifest.OwningResourceNamespace] = dopNamespace
        }
        resources := NamespacedResources()
-       gvkList := append(resources, AllClusterResources...)
-       for _, gvks := range gvkList {
+       gvkList := append(resources, ClusterCPResources...)
+       if includeClusterResources {
+               gvkList = append(resources, AllClusterResources...)
+       }
+       for _, g := range gvkList {
                var result *unstructured.UnstructuredList
-               c, err := clt.DynamicClientFor(gvks, nil, "")
+               c, err := clt.DynamicClientFor(g, nil, "")
                if err != nil {
                        return nil, err
                }
@@ -49,7 +54,7 @@ func GetPrunedResources(clt kube.CLIClient, dopName, 
dopNamespace string, includ
 }
 
 func NamespacedResources() []schema.GroupVersionKind {
-       var res []schema.GroupVersionKind
+       res := []schema.GroupVersionKind{}
        return res
 }
 
diff --git a/pkg/config/schema/gvk/resources.gen.go 
b/pkg/config/schema/gvk/resources.gen.go
index 2d8073b9..87fcb94a 100644
--- a/pkg/config/schema/gvk/resources.gen.go
+++ b/pkg/config/schema/gvk/resources.gen.go
@@ -1,7 +1,44 @@
 package gvk
 
-import "github.com/apache/dubbo-kubernetes/operator/pkg/config"
+import (
+       "github.com/apache/dubbo-kubernetes/operator/pkg/config"
+       "github.com/apache/dubbo-kubernetes/pkg/config/schema/gvr"
+       "k8s.io/apimachinery/pkg/runtime/schema"
+)
 
 var (
        CustomResourceDefinition = config.GroupVersionKind{Group: 
"apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}
 )
+
+func ToGVR(g config.GroupVersionKind) (schema.GroupVersionResource, bool) {
+       switch g {
+       case CustomResourceDefinition:
+               return gvr.CustomResourceDefinition, true
+       }
+       return schema.GroupVersionResource{}, false
+}
+
+func MustToGVR(g config.GroupVersionKind) schema.GroupVersionResource {
+       r, ok := ToGVR(g)
+       if !ok {
+               panic("unknown kind: " + g.String())
+       }
+       return r
+}
+
+func FromGVR(g schema.GroupVersionResource) (config.GroupVersionKind, bool) {
+       switch g {
+       case gvr.CustomResourceDefinition:
+               return CustomResourceDefinition, true
+       }
+
+       return config.GroupVersionKind{}, false
+}
+
+func MustFromGVR(g schema.GroupVersionResource) config.GroupVersionKind {
+       r, ok := FromGVR(g)
+       if !ok {
+               panic("unknown kind: " + g.String())
+       }
+       return r
+}
diff --git a/pkg/config/schema/gvr/resource.gen.go 
b/pkg/config/schema/gvr/resource.gen.go
new file mode 100644
index 00000000..f299669e
--- /dev/null
+++ b/pkg/config/schema/gvr/resource.gen.go
@@ -0,0 +1,7 @@
+package gvr
+
+import "k8s.io/apimachinery/pkg/runtime/schema"
+
+var (
+       CustomResourceDefinition = schema.GroupVersionResource{Group: 
"apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"}
+)

Reply via email to