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 ba70bce6 [dubboctl] remove profile command (#602)
ba70bce6 is described below
commit ba70bce68f4da0a69170ce025409140f18ea4a53
Author: Jian Zhong <[email protected]>
AuthorDate: Sun Feb 16 17:57:34 2025 +0800
[dubboctl] remove profile command (#602)
---
dubboctl/cmd/root.go | 4 -
operator/cmd/cluster/profile.go | 219 ----------------------------------------
operator/cmd/cluster/shared.go | 133 ------------------------
operator/pkg/tpath/tree.go | 182 ---------------------------------
operator/pkg/tpath/util.go | 37 -------
operator/pkg/util/path.go | 132 ------------------------
operator/pkg/util/reflect.go | 20 ----
operator/pkg/util/yaml.go | 75 --------------
8 files changed, 802 deletions(-)
diff --git a/dubboctl/cmd/root.go b/dubboctl/cmd/root.go
index 988ee74a..04340c78 100644
--- a/dubboctl/cmd/root.go
+++ b/dubboctl/cmd/root.go
@@ -132,10 +132,6 @@ func GetRootCmd(args []string) *cobra.Command {
rootCmd.AddCommand(repoCmd)
hideFlags(repoCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
- profileCmd := cluster.ProfileCmd(ctx)
- rootCmd.AddCommand(profileCmd)
- hideFlags(profileCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
-
imageCmd := ImageCmd(ctx, rootCmd, factory)
rootCmd.AddCommand(imageCmd)
hideFlags(imageCmd, cli.NamespaceFlag, cli.DubboNamespaceFlag,
cli.ChartFlag)
diff --git a/operator/cmd/cluster/profile.go b/operator/cmd/cluster/profile.go
deleted file mode 100644
index 397dbeb5..00000000
--- a/operator/cmd/cluster/profile.go
+++ /dev/null
@@ -1,219 +0,0 @@
-package cluster
-
-import (
- "encoding/json"
- "fmt"
- "github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
- "github.com/apache/dubbo-kubernetes/operator/pkg/helm"
- "github.com/apache/dubbo-kubernetes/operator/pkg/tpath"
- "github.com/apache/dubbo-kubernetes/operator/pkg/util"
- "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
- "github.com/ghodss/yaml"
- "github.com/spf13/cobra"
- "sort"
- "strings"
-)
-
-const (
- jsonOutput = "json"
- yamlOutput = "yaml"
- flagsOutput = "flags"
-)
-
-const (
- dubboOperatorTreeString = `
-apiVersion: install.dubbo.io/v1alpha1
-kind: DubboOperator
-`
-)
-
-const (
- DefaultProfileName = "default"
-)
-
-type profileListArgs struct {
- manifestsPath string
-}
-
-type profileDumpArgs struct {
- filenames []string
- configPath string
- outputFormat string
- manifestsPath string
-}
-
-func addProfileListFlags(cmd *cobra.Command, args *profileListArgs) {
- cmd.PersistentFlags().StringVarP(&args.manifestsPath, "manifests", "d",
"", "Specify a path to a directory of charts and profiles")
-}
-
-func addProfileDumpFlags(cmd *cobra.Command, args *profileDumpArgs) {
- cmd.PersistentFlags().StringSliceVarP(&args.filenames, "filenames",
"f", nil, "")
- cmd.PersistentFlags().StringVarP(&args.outputFormat, "output", "o",
yamlOutput,
- "Output format: one of json|yaml|flags")
- cmd.PersistentFlags().StringVarP(&args.manifestsPath, "manifests", "d",
"", "")
-}
-
-func ProfileCmd(ctx cli.Context) *cobra.Command {
- rootArgs := &RootArgs{}
- plArgs := &profileListArgs{}
- pdArgs := &profileDumpArgs{}
- plc := profileListCmd(rootArgs, plArgs)
- pdc := profileDumpCmd(rootArgs, pdArgs)
- pc := &cobra.Command{
- Use: "profile",
- Short: "Commands related to Dubbo configuration profiles",
- Long: "The profile command lists, dumps or diffs Dubbo
configuration profiles.",
- Example: " # Use a profile from the list\n" +
- " dubboctl profile list\n" +
- " dubboctl install --set profile=demo",
- }
- addProfileListFlags(plc, plArgs)
- addProfileDumpFlags(pdc, pdArgs)
- pc.AddCommand(plc)
- pc.AddCommand(pdc)
- AddFlags(pc, rootArgs)
- return pc
-}
-
-func profileListCmd(rootArgs *RootArgs, plArgs *profileListArgs)
*cobra.Command {
- return &cobra.Command{
- Use: "list [<profile>]",
- Short: "Lists available Dubbo configuration profiles",
- Long: "The list subcommand lists the available Dubbo
configuration profiles.",
- Args: cobra.ExactArgs(0),
- RunE: func(cmd *cobra.Command, args []string) error {
- return profileList(cmd, rootArgs, plArgs)
- },
- }
-}
-
-func profileDumpCmd(rootArgs *RootArgs, pdArgs *profileDumpArgs)
*cobra.Command {
- return &cobra.Command{
- Use: "dump [<profile>]",
- Short: "Dumps an Dubbo configuration profile",
- Long: "The dump subcommand describe the values in an Dubbo
configuration profile.",
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) > 1 {
- return fmt.Errorf("too many positional
arguments")
- }
- return nil
- },
- RunE: func(cmd *cobra.Command, args []string) error {
- l := clog.NewConsoleLogger(cmd.OutOrStdout(),
cmd.ErrOrStderr(), InstallerScope)
- return profileDump(args, rootArgs, pdArgs, l)
- },
- }
-}
-
-func profileList(cmd *cobra.Command, args *RootArgs, plArgs *profileListArgs)
error {
- profiles, err := helm.ListProfiles(plArgs.manifestsPath)
- if err != nil {
- return err
- }
-
- if len(profiles) == 0 {
- cmd.Println("No profiles available.")
- } else {
- cmd.Println("Dubbo configuration profiles:")
- sort.Strings(profiles)
- for _, profile := range profiles {
- cmd.Printf(" %s\n", profile)
- }
- }
- return nil
-}
-
-func profileDump(args []string, rootArgs *RootArgs, pdArgs *profileDumpArgs, l
clog.Logger) error {
- if len(args) == 1 && pdArgs.filenames != nil {
- return fmt.Errorf("cannot specify both profile name and
filename flag")
- }
-
- switch pdArgs.outputFormat {
- case jsonOutput, yamlOutput, flagsOutput:
- default:
- return fmt.Errorf("unknown output format: %v",
pdArgs.outputFormat)
- }
-
- setFlags := applyFlagAliases(make([]string, 0), pdArgs.manifestsPath)
- if len(args) == 1 {
- setFlags = append(setFlags, "profile="+args[0])
- }
-
- y, _, err := generateConfig(pdArgs.filenames, setFlags, l)
- if err != nil {
- return err
- }
- y, err = tpath.GetConfigSubtree(y, "spec")
- if err != nil {
- return err
- }
-
- if pdArgs.configPath == "" {
- if y, err = prependHeader(y); err != nil {
- return err
- }
- } else {
- if y, err = tpath.GetConfigSubtree(y, pdArgs.configPath); err
!= nil {
- return err
- }
- }
-
- switch pdArgs.outputFormat {
- case jsonOutput:
- j, err := yamlToPrettyJSON(y)
- if err != nil {
- return err
- }
- l.Print(j + "\n")
- case yamlOutput:
- l.Print(y + "\n")
- case flagsOutput:
- f, err := yamlToFlags(y)
- if err != nil {
- return err
- }
- l.Print(strings.Join(f, "\n") + "\n")
- }
-
- return nil
-}
-
-func prependHeader(yml string) (string, error) {
- out, err := tpath.AddSpecRoot(yml)
- if err != nil {
- return "", err
- }
- out2, err := util.OverlayYAML(dubboOperatorTreeString, out)
- if err != nil {
- return "", err
- }
- return out2, nil
-}
-
-func yamlToFlags(yml string) ([]string, error) {
- uglyJSON, err := yaml.YAMLToJSON([]byte(yml))
- if err != nil {
- return []string{}, err
- }
- var decoded map[string]interface{}
- if err := json.Unmarshal(uglyJSON, &decoded); err != nil {
- return []string{}, err
- }
- return nil, nil
-}
-
-func yamlToPrettyJSON(yml string) (string, error) {
- uglyJSON, err := yaml.YAMLToJSON([]byte(yml))
- if err != nil {
- return "", err
- }
- var decoded map[string]interface{}
- if err := json.Unmarshal(uglyJSON, &decoded); err != nil {
- return "", err
- }
- prettyJSON, err := json.MarshalIndent(decoded, "", " ")
- if err != nil {
- return "", err
- }
- return string(prettyJSON), nil
-}
diff --git a/operator/cmd/cluster/shared.go b/operator/cmd/cluster/shared.go
index 64b815df..2cde9b49 100644
--- a/operator/cmd/cluster/shared.go
+++ b/operator/cmd/cluster/shared.go
@@ -2,13 +2,7 @@ package cluster
import (
"fmt"
- dopv1alpha1 "github.com/apache/dubbo-kubernetes/operator/pkg/apis"
- "github.com/apache/dubbo-kubernetes/operator/pkg/helm"
- "github.com/apache/dubbo-kubernetes/operator/pkg/util"
- "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
"io"
- "io/ioutil"
- "os"
"strings"
)
@@ -53,130 +47,3 @@ func OptionDeterminate(msg string, writer io.Writer) bool {
func NewPrinterForWriter(w io.Writer) Printer {
return &writerPrinter{writer: w}
}
-
-func generateConfig(filenames []string, setFlags []string, l clog.Logger)
(string, *dopv1alpha1.DubboOperator, error) {
- if err := validateSetFlags(setFlags); err != nil {
- return "", nil, err
- }
-
- fy, profile, err := readYamlProfile(filenames, setFlags, l)
- if err != nil {
- return "", nil, err
- }
- return overlayYAMLStrings(profile, fy, setFlags, l)
-}
-
-func validateSetFlags(setFlags []string) error {
- for _, sf := range setFlags {
- pv := strings.Split(sf, "=")
- if len(pv) != 2 {
- return fmt.Errorf("set flag %s has incorrect format,
must be path=value", sf)
- }
- }
- return nil
-}
-
-func overlayYAMLStrings(profile string, fy string, setFlags []string, l
clog.Logger) (string, *dopv1alpha1.DubboOperator, error) {
- dopsString, dops, err := GenDOPFromProfile(profile, fy, setFlags,
false, l)
- if err != nil {
- return "", nil, err
- }
- return dopsString, dops, nil
-}
-
-func GenDOPFromProfile(profileOrPath, fileOverlayYAML string, setFlags
[]string, allowUnknownField bool, l clog.Logger) (string,
*dopv1alpha1.DubboOperator, error) {
- _, err := helm.GetProfileYAML("", profileOrPath)
- if err != nil {
- return "", nil, err
- }
- finalIOP, err := unmarshalDOP("", allowUnknownField, l)
- if err != nil {
- return "", nil, err
- }
-
- if finalIOP.Spec.Profile == "" {
- finalIOP.Spec.Profile = DefaultProfileName
- }
- return util.ToYAMLWithJSONPB(finalIOP), finalIOP, nil
-}
-
-func unmarshalDOP(dopsYAML string, allowUnknownField bool, l clog.Logger)
(*dopv1alpha1.DubboOperator, error) {
- dop := &dopv1alpha1.DubboOperator{}
- if err := util.UnmarshalWithJSONPB(dopsYAML, dop, allowUnknownField);
err != nil {
- return nil, fmt.Errorf("could not unmarshal merged YAML:
%s\n\nYAML:\n%s", err, dopsYAML)
- }
- return dop, nil
-}
-
-func readYamlProfile(filenames []string, setFlags []string, l clog.Logger)
(string, string, error) {
- profile := DefaultProfileName
- fy, fp, err := ParseYAMLfilenames(filenames, l)
- if err != nil {
- return "", "", err
- }
- if fp != "" {
- profile = fp
- }
- psf := getValueForSetFlag(setFlags, "profile")
- if psf != "" {
- profile = psf
- }
- return fy, profile, nil
-}
-
-func ParseYAMLfilenames(filenames []string, l clog.Logger) (overlayYAML
string, profile string, err error) {
- if filenames == nil {
- return "", "", nil
- }
- y, err := ReadLayeredYAMLs(filenames)
- if err != nil {
- return "", "", err
- }
- return y, profile, nil
-}
-
-func ReadLayeredYAMLs(filenames []string) (string, error) {
- return readLayeredYAMLs(filenames, os.Stdin)
-}
-
-func readLayeredYAMLs(filenames []string, stdinReader io.Reader) (string,
error) {
- var ly string
- var stdin bool
- for _, fn := range filenames {
- var _ []byte
- var err error
- if fn == "-" {
- if stdin {
- continue
- }
- stdin = true
- _, err = ioutil.ReadAll(stdinReader)
- } else {
- _, err = ioutil.ReadFile(strings.TrimSpace(fn))
- }
- if err != nil {
- return "", err
- }
- }
- return ly, nil
-}
-
-func getValueForSetFlag(setFlags []string, path string) string {
- ret := ""
- for _, sf := range setFlags {
- p, v := getPV(sf)
- if p == path {
- ret = v
- }
- }
- return ret
-}
-
-func getPV(setFlag string) (path string, value string) {
- pv := strings.Split(setFlag, "=")
- if len(pv) != 2 {
- return setFlag, ""
- }
- path, value = strings.TrimSpace(pv[0]), strings.TrimSpace(pv[1])
- return
-}
diff --git a/operator/pkg/tpath/tree.go b/operator/pkg/tpath/tree.go
deleted file mode 100644
index 14f87c42..00000000
--- a/operator/pkg/tpath/tree.go
+++ /dev/null
@@ -1,182 +0,0 @@
-package tpath
-
-import (
- "fmt"
- "github.com/apache/dubbo-kubernetes/operator/pkg/util"
- "reflect"
- "regexp"
-)
-
-type PathContext struct {
- Parent *PathContext
- KeyToChild interface{}
- Node interface{}
-}
-
-func GetPathContext(root interface{}, path util.Path, createMissing bool)
(*PathContext, bool, error) {
- return getPathContext(&PathContext{Node: root}, path, path,
createMissing)
-}
-
-func getPathContext(nc *PathContext, fullPath, remainPath util.Path,
createMissing bool) (*PathContext, bool, error) {
- if len(remainPath) == 0 {
- return nc, true, nil
- }
- pe := remainPath[0]
-
- if nc.Node == nil {
- if !createMissing {
- return nil, false, fmt.Errorf("node %s is zero", pe)
- }
- if util.IsNPathElement(pe) || util.IsKVPathElement(pe) {
- nc.Node = []interface{}{}
- } else {
- nc.Node = make(map[string]interface{})
- }
- }
-
- v := reflect.ValueOf(nc.Node)
- if v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface {
- v = v.Elem()
- }
- ncNode := v.Interface()
-
- if lst, ok := ncNode.([]interface{}); ok {
- if util.IsNPathElement(pe) {
- idx, err := util.PathN(pe)
- if err != nil {
- return nil, false, fmt.Errorf("path %s, index
%s: %s", fullPath, pe, err)
- }
- var foundNode interface{}
- if idx >= len(lst) || idx < 0 {
- if !createMissing {
- return nil, false, fmt.Errorf("index %d
exceeds list length %d at path %s", idx, len(lst), remainPath)
- }
- idx = len(lst)
- foundNode = make(map[string]interface{})
- } else {
- foundNode = lst[idx]
- }
- nn := &PathContext{
- Parent: nc,
- Node: foundNode,
- }
- nc.KeyToChild = idx
- return getPathContext(nn, fullPath, remainPath[1:],
createMissing)
- }
- for idx, le := range lst {
- if lm, ok := le.(map[interface{}]interface{}); ok {
- k, v, err := util.PathKV(pe)
- if err != nil {
- return nil, false, fmt.Errorf("path %s:
%s", fullPath, err)
- }
- if stringsEqual(lm[k], v) {
- nn := &PathContext{
- Parent: nc,
- Node: lm,
- }
- nc.KeyToChild = idx
- nn.KeyToChild = k
- if len(remainPath) == 1 {
- return nn, true, nil
- }
- return getPathContext(nn, fullPath,
remainPath[1:], createMissing)
- }
- continue
- }
- // repeat of the block above for the case where tree
unmarshals to map[string]interface{}. There doesn't
- // seem to be a way to merge this case into the above
block.
- if lm, ok := le.(map[string]interface{}); ok {
- k, v, err := util.PathKV(pe)
- if err != nil {
- return nil, false, fmt.Errorf("path %s:
%s", fullPath, err)
- }
- if stringsEqual(lm[k], v) {
- nn := &PathContext{
- Parent: nc,
- Node: lm,
- }
- nc.KeyToChild = idx
- nn.KeyToChild = k
- if len(remainPath) == 1 {
- return nn, true, nil
- }
- return getPathContext(nn, fullPath,
remainPath[1:], createMissing)
- }
- continue
- }
- v, err := util.PathV(pe)
- if err != nil {
- return nil, false, fmt.Errorf("path %s: %s",
fullPath, err)
- }
- if matchesRegex(v, le) {
- nn := &PathContext{
- Parent: nc,
- Node: le,
- }
- nc.KeyToChild = idx
- return getPathContext(nn, fullPath,
remainPath[1:], createMissing)
- }
- }
- return nil, false, fmt.Errorf("path %s: element %s not found",
fullPath, pe)
- }
-
- if util.IsMap(ncNode) {
- var nn interface{}
- if m, ok := ncNode.(map[interface{}]interface{}); ok {
- nn, ok = m[pe]
- if !ok {
- if createMissing || len(remainPath) == 1 {
- m[pe] =
make(map[interface{}]interface{})
- nn = m[pe]
- } else {
- return nil, false, fmt.Errorf("path not
found at element %s in path %s", pe, fullPath)
- }
- }
- }
- if reflect.ValueOf(ncNode).IsNil() {
- ncNode = make(map[string]interface{})
- nc.Node = ncNode
- }
- if m, ok := ncNode.(map[string]interface{}); ok {
- nn, ok = m[pe]
- if !ok {
- if createMissing || len(remainPath) == 1 {
- nextElementNPath := len(remainPath) > 1
&& util.IsNPathElement(remainPath[1])
- if nextElementNPath {
- m[pe] = make([]interface{}, 0)
- } else {
- m[pe] =
make(map[string]interface{})
- }
- nn = m[pe]
- } else {
- return nil, false, fmt.Errorf("path not
found at element %s in path %s", pe, fullPath)
- }
- }
- }
-
- npc := &PathContext{
- Parent: nc,
- Node: nn,
- }
- if util.IsSlice(nn) {
- npc.Node = &nn
- }
- nc.KeyToChild = pe
- return getPathContext(npc, fullPath, remainPath[1:],
createMissing)
- }
-
- return nil, false, fmt.Errorf("leaf type %T in non-leaf Node %s",
nc.Node, remainPath)
-}
-
-func stringsEqual(a, b interface{}) bool {
- return fmt.Sprint(a) == fmt.Sprint(b)
-}
-
-func matchesRegex(pattern, str interface{}) bool {
- match, err := regexp.MatchString(fmt.Sprint(pattern), fmt.Sprint(str))
- if err != nil {
- fmt.Errorf("bad regex expression %s", fmt.Sprint(pattern))
- return false
- }
- return match
-}
diff --git a/operator/pkg/tpath/util.go b/operator/pkg/tpath/util.go
deleted file mode 100644
index 2569e5dd..00000000
--- a/operator/pkg/tpath/util.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package tpath
-
-import (
- "github.com/apache/dubbo-kubernetes/operator/pkg/util"
- yaml2 "github.com/ghodss/yaml"
- "gopkg.in/yaml.v3"
-)
-
-func AddSpecRoot(tree string) (string, error) {
- t, nt := make(map[string]interface{}), make(map[string]interface{})
- if err := yaml.Unmarshal([]byte(tree), &t); err != nil {
- return "", err
- }
- nt["spec"] = t
- out, err := yaml.Marshal(nt)
- if err != nil {
- return "", err
- }
- return string(out), nil
-}
-
-func GetConfigSubtree(manifest, path string) (string, error) {
- root := make(map[string]interface{})
- if err := yaml2.Unmarshal([]byte(manifest), &root); err != nil {
- return "", err
- }
-
- nc, _, err := GetPathContext(root, util.PathFromString(path), false)
- if err != nil {
- return "", err
- }
- out, err := yaml2.Marshal(nc.Node)
- if err != nil {
- return "", err
- }
- return string(out), nil
-}
diff --git a/operator/pkg/util/path.go b/operator/pkg/util/path.go
deleted file mode 100644
index ea3b885e..00000000
--- a/operator/pkg/util/path.go
+++ /dev/null
@@ -1,132 +0,0 @@
-package util
-
-import (
- "fmt"
- "path/filepath"
- "regexp"
- "strconv"
- "strings"
-)
-
-const (
- PathSeparator = "."
- pathSeparatorRune = '.'
- kvSeparatorRune = ':'
- InsertIndex = -1
- EscapedPathSeparator = "\\" + PathSeparator
-)
-
-type Path []string
-
-func PathFromString(path string) Path {
- path = filepath.Clean(path)
- path = strings.TrimPrefix(path, PathSeparator)
- path = strings.TrimSuffix(path, PathSeparator)
- pv := splitEscaped(path, pathSeparatorRune)
- var r []string
- for _, str := range pv {
- if str != "" {
- str = strings.ReplaceAll(str, EscapedPathSeparator,
PathSeparator)
- nBracket := strings.IndexRune(str, '[')
- if nBracket > 0 {
- r = append(r, str[:nBracket], str[nBracket:])
- } else {
- r = append(r, str)
- }
- }
- }
- return r
-}
-
-func splitEscaped(s string, r rune) []string {
- var prev rune
- if len(s) == 0 {
- return []string{}
- }
- prevIdx := 0
- var out []string
- for i, c := range s {
- if c == r && (i == 0 || (i > 0 && prev != '\\')) {
- out = append(out, s[prevIdx:i])
- prevIdx = i + 1
- }
- prev = c
- }
- out = append(out, s[prevIdx:])
- return out
-}
-
-func IsNPathElement(pe string) bool {
- pe, ok := RemoveBrackets(pe)
- if !ok {
- return false
- }
-
- n, err := strconv.Atoi(pe)
- return err == nil && n >= InsertIndex
-}
-
-func RemoveBrackets(pe string) (string, bool) {
- if !strings.HasPrefix(pe, "[") || !strings.HasSuffix(pe, "]") {
- return "", false
- }
- return pe[1 : len(pe)-1], true
-}
-
-func IsKVPathElement(pe string) bool {
- pe, ok := RemoveBrackets(pe)
- if !ok {
- return false
- }
-
- kv := splitEscaped(pe, kvSeparatorRune)
- if len(kv) != 2 || len(kv[0]) == 0 || len(kv[1]) == 0 {
- return false
- }
- return IsValidPathElement(kv[0])
-}
-
-func IsValidPathElement(pe string) bool {
- return ValidKeyRegex.MatchString(pe)
-}
-
-var ValidKeyRegex = regexp.MustCompile("^[a-zA-Z0-9_-]*$")
-
-func PathN(pe string) (int, error) {
- if !IsNPathElement(pe) {
- return -1, fmt.Errorf("%s is not a valid index path element",
pe)
- }
- v, _ := RemoveBrackets(pe)
- return strconv.Atoi(v)
-}
-
-func PathKV(pe string) (k, v string, err error) {
- if !IsKVPathElement(pe) {
- return "", "", fmt.Errorf("%s is not a valid key:value path
element", pe)
- }
- pe, _ = RemoveBrackets(pe)
- kv := splitEscaped(pe, kvSeparatorRune)
- return kv[0], kv[1], nil
-}
-
-func PathV(pe string) (string, error) {
- if IsVPathElement(pe) {
- v, _ := RemoveBrackets(pe)
- return v[1:], nil
- }
-
- v, _ := RemoveBrackets(pe)
- if len(v) > 0 {
- return v, nil
- }
- return "", fmt.Errorf("%s is not a valid value path element", pe)
-}
-
-func IsVPathElement(pe string) bool {
- pe, ok := RemoveBrackets(pe)
- if !ok {
- return false
- }
-
- return len(pe) > 1 && pe[0] == ':'
-}
diff --git a/operator/pkg/util/reflect.go b/operator/pkg/util/reflect.go
deleted file mode 100644
index ae7a599b..00000000
--- a/operator/pkg/util/reflect.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package util
-
-import (
- "reflect"
-)
-
-func kindOf(value interface{}) reflect.Kind {
- if value == nil {
- return reflect.Invalid
- }
- return reflect.TypeOf(value).Kind()
-}
-
-func IsSlice(value interface{}) bool {
- return kindOf(value) == reflect.Slice
-}
-
-func IsMap(value interface{}) bool {
- return kindOf(value) == reflect.Map
-}
diff --git a/operator/pkg/util/yaml.go b/operator/pkg/util/yaml.go
deleted file mode 100644
index 682a16a3..00000000
--- a/operator/pkg/util/yaml.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package util
-
-import (
- "bytes"
- "fmt"
- jsonpatch "github.com/evanphx/json-patch"
- yaml2 "github.com/ghodss/yaml"
- "github.com/gogo/protobuf/jsonpb"
- "github.com/gogo/protobuf/proto"
- "sigs.k8s.io/yaml"
- "strings"
-)
-
-func UnmarshalWithJSONPB(y string, out proto.Message, allowUnknownField bool)
error {
- if y == "" {
- return nil
- }
- jb, err := yaml.YAMLToJSON([]byte(y))
- if err != nil {
- return err
- }
- u := jsonpb.Unmarshaler{AllowUnknownFields: allowUnknownField}
- err = u.Unmarshal(bytes.NewReader(jb), out)
- if err != nil {
- return err
- }
- return nil
-}
-
-func ToYAMLWithJSONPB(val proto.Message) string {
- m := jsonpb.Marshaler{EnumsAsInts: true}
- js, err := m.MarshalToString(val)
- if err != nil {
- return err.Error()
- }
- yb, err := yaml.JSONToYAML([]byte(js))
- if err != nil {
- return err.Error()
- }
- return string(yb)
-}
-
-func OverlayYAML(base, overlay string) (string, error) {
- if strings.TrimSpace(base) == "" {
- return overlay, nil
- }
- if strings.TrimSpace(overlay) == "" {
- return base, nil
- }
- bj, err := yaml2.YAMLToJSON([]byte(base))
- if err != nil {
- return "", fmt.Errorf("yamlToJSON error in base: %s\n%s", err,
bj)
- }
- oj, err := yaml2.YAMLToJSON([]byte(overlay))
- if err != nil {
- return "", fmt.Errorf("yamlToJSON error in overlay: %s\n%s",
err, oj)
- }
- if base == "" {
- bj = []byte("{}")
- }
- if overlay == "" {
- oj = []byte("{}")
- }
-
- merged, err := jsonpatch.MergePatch(bj, oj)
- if err != nil {
- return "", fmt.Errorf("json merge error (%s) for base object:
\n%s\n override object: \n%s", err, bj, oj)
- }
- my, err := yaml2.JSONToYAML(merged)
- if err != nil {
- return "", fmt.Errorf("jsonToYAML error (%s) for merged object:
\n%s", err, merged)
- }
-
- return string(my), nil
-}