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 902f86d5 [operator] Add some uninstallation logic
902f86d5 is described below

commit 902f86d52c9556c1e74c9f162e3cc017478c43c5
Author: mfordjody <[email protected]>
AuthorDate: Sat Dec 21 08:50:26 2024 +0800

    [operator] Add some uninstallation logic
---
 operator/pkg/install/installer.go   | 17 +++++++++++++++++
 operator/pkg/manifest/manifest.go   | 13 +++++++++++++
 operator/pkg/manifest/name.go       |  6 ++++++
 operator/pkg/uninstall/uninstall.go | 16 +++++++++++-----
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/operator/pkg/install/installer.go 
b/operator/pkg/install/installer.go
index a3d70cba..ab9b6869 100644
--- a/operator/pkg/install/installer.go
+++ b/operator/pkg/install/installer.go
@@ -119,6 +119,23 @@ func (i Installer) serverSideApply(obj manifest.Manifest) 
error {
        return nil
 }
 
+func (i Installer) prune(manifests []manifest.ManifestSet) error {
+       if i.DryRun {
+               return nil
+       }
+       i.ProgressInfo.SetState(progress.StatePruning)
+       excluded := map[component.Name]sets.String{}
+       for _, c := range component.AllComponents {
+               excluded[c.UserFacingName] = sets.New[string]()
+       }
+       for _, mfs := range manifests {
+               for _, m := range mfs.Manifests {
+                       excluded[mfs.Components].Insert(m.Hash())
+               }
+       }
+       return
+}
+
 var componentDependencies = map[component.Name][]component.Name{
        component.BaseComponentName: {},
 }
diff --git a/operator/pkg/manifest/manifest.go 
b/operator/pkg/manifest/manifest.go
index af3c3fa8..a08c49e9 100644
--- a/operator/pkg/manifest/manifest.go
+++ b/operator/pkg/manifest/manifest.go
@@ -60,3 +60,16 @@ func Parse(output []string) ([]Manifest, error) {
 func ParseMultiple(output string) ([]Manifest, error) {
        return Parse(parts.SplitString(output))
 }
+
+func ObjectHash(o *unstructured.Unstructured) string {
+       k := o.GroupVersionKind().Kind
+       switch o.GroupVersionKind().Kind {
+       case "ClusterRole", "ClusterRoleBinding":
+               return k + ":" + o.GetName()
+       }
+       return k + ":" + o.GetNamespace() + ":" + o.GetName()
+}
+
+func (m Manifest) Hash() string {
+       return ObjectHash(m.Unstructured)
+}
diff --git a/operator/pkg/manifest/name.go b/operator/pkg/manifest/name.go
new file mode 100644
index 00000000..27923f2d
--- /dev/null
+++ b/operator/pkg/manifest/name.go
@@ -0,0 +1,6 @@
+package manifest
+
+const (
+       OwningResourceName      = "install.operator.dubbo.io/owning-resource"
+       OwningResourceNamespace = 
"install.operator.dubbo.io/owning-resource-namespace"
+)
diff --git a/operator/pkg/uninstall/uninstall.go 
b/operator/pkg/uninstall/uninstall.go
index e76f8ff6..050b803f 100644
--- a/operator/pkg/uninstall/uninstall.go
+++ b/operator/pkg/uninstall/uninstall.go
@@ -3,6 +3,7 @@ package uninstall
 import (
        "context"
        "fmt"
+       "github.com/apache/dubbo-kubernetes/operator/pkg/manifest"
        "github.com/apache/dubbo-kubernetes/operator/pkg/util"
        "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
        "github.com/apache/dubbo-kubernetes/pkg/kube"
@@ -12,10 +13,16 @@ import (
        "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 )
 
-func GetPrunedResources(kc kube.CLIClient, dopName, dopNamespace string, 
includeClusterResources bool) (
-       []*unstructured.Unstructured, error,
-) {
-       return nil, nil
+func GetPrunedResources(dopName, dopNamespace string) 
([]*unstructured.UnstructuredList, error) {
+       var usList []*unstructured.UnstructuredList
+       labels := make(map[string]string)
+       if dopName != "" {
+               labels[manifest.OwningResourceName] = dopName
+       }
+       if dopNamespace != "" {
+               labels[manifest.OwningResourceNamespace] = dopNamespace
+       }
+       return usList, nil
 }
 
 func DeleteObjectsList(c kube.CLIClient, dryRun bool, log clog.Logger, 
objectsList []*unstructured.UnstructuredList) error {
@@ -27,7 +34,6 @@ func DeleteObjectsList(c kube.CLIClient, dryRun bool, log 
clog.Logger, objectsLi
                        }
                }
        }
-
        return errs.ToErrors()
 }
 

Reply via email to