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 6e3bad29 [operator] Add delete resources object logic
6e3bad29 is described below
commit 6e3bad297d24efda6e6a9aff13f85c72d72c9f06
Author: mfordjody <[email protected]>
AuthorDate: Sat Dec 21 08:17:19 2024 +0800
[operator] Add delete resources object logic
---
operator/cmd/cluster/install.go | 24 ++++++++--------
operator/cmd/cluster/uninstall.go | 28 +++++++++++++++----
operator/pkg/uninstall/uninstall.go | 55 +++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+), 18 deletions(-)
diff --git a/operator/cmd/cluster/install.go b/operator/cmd/cluster/install.go
index 84a1a059..5fc7b1b4 100644
--- a/operator/cmd/cluster/install.go
+++ b/operator/cmd/cluster/install.go
@@ -20,23 +20,23 @@ import (
var installerScope = log.RegisterScope("installer", "installer")
type installArgs struct {
- Files []string
- Sets []string
- ManifestPath string
- SkipConfirmation bool
+ files []string
+ sets []string
+ manifestPath string
+ skipConfirmation bool
}
func (i *installArgs) String() string {
var b strings.Builder
- b.WriteString("Files: " + (fmt.Sprint(i.Files) + "\n"))
- b.WriteString("Sets: " + (fmt.Sprint(i.Sets) + "\n"))
- b.WriteString("ManifestPath: " + (fmt.Sprint(i.ManifestPath) + "\n"))
+ b.WriteString("files: " + (fmt.Sprint(i.files) + "\n"))
+ b.WriteString("sets: " + (fmt.Sprint(i.sets) + "\n"))
+ b.WriteString("manifestPath: " + (fmt.Sprint(i.manifestPath) + "\n"))
return b.String()
}
func addInstallFlags(cmd *cobra.Command, args *installArgs) {
- cmd.PersistentFlags().StringSliceVarP(&args.Files, "files", "f", nil,
`Path to the file containing the dubboOperator's custom resources`)
- cmd.PersistentFlags().StringArrayVarP(&args.Sets, "set", "s", nil,
`Override dubboOperator values, such as selecting profiles, etc`)
+ cmd.PersistentFlags().StringSliceVarP(&args.files, "files", "f", nil,
`Path to the file containing the dubboOperator's custom resources`)
+ cmd.PersistentFlags().StringArrayVarP(&args.sets, "set", "s", nil,
`Override dubboOperator values, such as selecting profiles, etc`)
}
@@ -78,13 +78,13 @@ func InstallCmdWithArgs(ctx cli.Context, rootArgs
*RootArgs, iArgs *installArgs)
}
func Install(kubeClient kube.CLIClient, rootArgs *RootArgs, iArgs
*installArgs, cl clog.Logger, stdOut io.Writer, p Printer) error {
- setFlags := applyFlagAliases(iArgs.Sets, iArgs.ManifestPath)
- manifests, vals, err := render.GenerateManifest(iArgs.Files, setFlags,
cl, kubeClient)
+ setFlags := applyFlagAliases(iArgs.sets, iArgs.manifestPath)
+ manifests, vals, err := render.GenerateManifest(iArgs.files, setFlags,
cl, kubeClient)
if err != nil {
return fmt.Errorf("generate config: %v", err)
}
profile :=
pointer.NonEmptyOrDefault(vals.GetPathString("spec.profile"), "default")
- if !rootArgs.DryRun && !iArgs.SkipConfirmation {
+ if !rootArgs.DryRun && !iArgs.skipConfirmation {
prompt := fmt.Sprintf("You are currently selecting the %q
profile to install into the cluster. Do you want to proceed? (y/N)", profile)
if !OptionDeterminate(prompt, stdOut) {
p.Println("Canceled Completed.")
diff --git a/operator/cmd/cluster/uninstall.go
b/operator/cmd/cluster/uninstall.go
index 47cf9d86..f85f43da 100644
--- a/operator/cmd/cluster/uninstall.go
+++ b/operator/cmd/cluster/uninstall.go
@@ -2,6 +2,10 @@ package cluster
import (
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/render"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util/progress"
+ "github.com/apache/dubbo-kubernetes/pkg/kube"
"github.com/spf13/cobra"
)
@@ -40,10 +44,22 @@ func UninstallCmd(ctx cli.Context) *cobra.Command {
return uicmd
}
-func uninstall(
- cmd *cobra.Command,
- ctx cli.Context,
- rootArgs *RootArgs,
- uiArgs *uninstallArgs) error {
- return nil
+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
+ if err != nil {
+ return err
+ }
+ pl := progress.NewInfo()
+ setFlags := applyFlagAliases(uiArgs.sets, uiArgs.manifestPath)
+ files := []string{}
+ if uiArgs.files != "" {
+ files = append(files, uiArgs.files)
+ }
+ vals, err := render.MergeInputs(files, setFlags)
+ if err != nil {
+ return err
+ }
+ // todo
}
diff --git a/operator/pkg/uninstall/uninstall.go
b/operator/pkg/uninstall/uninstall.go
new file mode 100644
index 00000000..e76f8ff6
--- /dev/null
+++ b/operator/pkg/uninstall/uninstall.go
@@ -0,0 +1,55 @@
+package uninstall
+
+import (
+ "context"
+ "fmt"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
+ "github.com/apache/dubbo-kubernetes/pkg/kube"
+ "github.com/apache/dubbo-kubernetes/pkg/pointer"
+ kerrors "k8s.io/apimachinery/pkg/api/errors"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "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 DeleteObjectsList(c kube.CLIClient, dryRun bool, log clog.Logger,
objectsList []*unstructured.UnstructuredList) error {
+ var errs util.Errors
+ for _, ul := range objectsList {
+ for _, o := range ul.Items {
+ if err := DeleteResource(c, dryRun, log, &o); err !=
nil {
+ errs = append(errs, err)
+ }
+ }
+ }
+
+ return errs.ToErrors()
+}
+
+func DeleteResource(clt kube.CLIClient, dryRun bool, log clog.Logger, obj
*unstructured.Unstructured) error {
+ name := fmt.Sprintf("%v/%s.%s", obj.GroupVersionKind(), obj.GetName(),
obj.GetNamespace())
+ if dryRun {
+ log.LogAndPrintf("Not pruning object %s because of dry run.",
name)
+ return nil
+ }
+ c, err := clt.DynamicClientFor(obj.GroupVersionKind(), obj, "")
+ if err != nil {
+ return err
+ }
+
+ if err := c.Delete(context.TODO(), obj.GetName(),
metav1.DeleteOptions{PropagationPolicy:
pointer.Of(metav1.DeletePropagationForeground)}); err != nil {
+ if !kerrors.IsNotFound(err) {
+ return err
+ }
+ log.LogAndPrintf("object: %s is not being deleted because it no
longer exists", name)
+ return nil
+ }
+
+ log.LogAndPrintf(" Removed %s.", name)
+ return nil
+}