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 dae121c6 [operator] fix yaml map logic
dae121c6 is described below
commit dae121c6a116339b3a69a8554d00183bb4400137
Author: mfordjody <[email protected]>
AuthorDate: Sun Dec 15 16:05:22 2024 +0800
[operator] fix yaml map logic
---
dubboctl/main.go | 2 --
manifests/profiles/default.yaml | 15 ------------
manifests/profiles/demo.yaml | 15 ------------
operator/cmd/cluster/install.go | 17 +++++++------
operator/cmd/cluster/shared.go | 2 +-
operator/pkg/install/installer.go | 4 ++--
operator/pkg/manifest/manifest.go | 8 +++++--
operator/pkg/render/manifest.go | 31 ++++++++++--------------
operator/pkg/util/clog/clog.go | 50 +++++++++++++++++++--------------------
operator/pkg/values/map.go | 4 ++--
10 files changed, 59 insertions(+), 89 deletions(-)
diff --git a/dubboctl/main.go b/dubboctl/main.go
index ec5eb018..42b9b811 100644
--- a/dubboctl/main.go
+++ b/dubboctl/main.go
@@ -18,7 +18,6 @@
package main
import (
- "fmt"
"os"
)
@@ -29,7 +28,6 @@ import (
func main() {
rootCmd := cmd.GetRootCmd(os.Args[1:])
if err := rootCmd.Execute(); err != nil {
- fmt.Errorf("GetRootCmd Execute err:%v", err)
os.Exit(1)
}
}
diff --git a/manifests/profiles/default.yaml b/manifests/profiles/default.yaml
index 51af80e4..96d6699f 100644
--- a/manifests/profiles/default.yaml
+++ b/manifests/profiles/default.yaml
@@ -1,18 +1,3 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
apiVersion: install.dubbo.io/v1alpha1
kind: DubboOperator
metadata:
diff --git a/manifests/profiles/demo.yaml b/manifests/profiles/demo.yaml
index dfb7429a..4cde9ad5 100644
--- a/manifests/profiles/demo.yaml
+++ b/manifests/profiles/demo.yaml
@@ -1,18 +1,3 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
apiVersion: install.dubbo.io/v1alpha1
kind: DubboOperator
metadata:
diff --git a/operator/cmd/cluster/install.go b/operator/cmd/cluster/install.go
index cdc8241f..6b178aed 100644
--- a/operator/cmd/cluster/install.go
+++ b/operator/cmd/cluster/install.go
@@ -7,6 +7,7 @@ import (
"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/clog/log"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util/progress"
"github.com/apache/dubbo-kubernetes/pkg/art"
"github.com/apache/dubbo-kubernetes/pkg/kube"
"github.com/apache/dubbo-kubernetes/pkg/util/pointer"
@@ -87,17 +88,19 @@ func Install(kubeClient kube.CLIClient, rootArgs *RootArgs,
iArgs *installArgs,
}
profile :=
pointer.NonEmptyOrDefault(vals.GetPathString("spec.profile"), "default")
if !rootArgs.DryRun && !iArgs.SkipConfirmation {
- prompt := fmt.Sprintf("You are currently selecting the %q
profile to install into the cluster. %v Do you want to proceed? (y/N)",
profile, vals)
- if !OptionDeterminator(prompt, stdOut) {
- p.Println("Cancelled.")
+ 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.")
os.Exit(1)
}
}
i := install.Installer{
- DryRun: rootArgs.DryRun,
- SkipWait: false,
- Kube: kubeClient,
- Values: vals,
+ DryRun: rootArgs.DryRun,
+ SkipWait: false,
+ Kube: kubeClient,
+ Values: vals,
+ ProgressInfo: progress.NewInfo(),
+ Logger: cl,
}
if err := i.InstallManifests(manifests); err != nil {
return fmt.Errorf("failed to install manifests: %v", err)
diff --git a/operator/cmd/cluster/shared.go b/operator/cmd/cluster/shared.go
index 0969405d..2cde9b49 100644
--- a/operator/cmd/cluster/shared.go
+++ b/operator/cmd/cluster/shared.go
@@ -27,7 +27,7 @@ func (w writerPrinter) Println(s string) {
_, _ = fmt.Fprintln(w.writer, s)
}
-func OptionDeterminator(msg string, writer io.Writer) bool {
+func OptionDeterminate(msg string, writer io.Writer) bool {
for {
_, _ = fmt.Fprintf(writer, "%s ", msg)
var resp string
diff --git a/operator/pkg/install/installer.go
b/operator/pkg/install/installer.go
index 8ddb4ead..a3d70cba 100644
--- a/operator/pkg/install/installer.go
+++ b/operator/pkg/install/installer.go
@@ -5,11 +5,11 @@ import (
"fmt"
"github.com/apache/dubbo-kubernetes/operator/pkg/component"
"github.com/apache/dubbo-kubernetes/operator/pkg/manifest"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/util/clog"
"github.com/apache/dubbo-kubernetes/operator/pkg/util/dmultierr"
"github.com/apache/dubbo-kubernetes/operator/pkg/util/progress"
"github.com/apache/dubbo-kubernetes/operator/pkg/values"
"github.com/apache/dubbo-kubernetes/pkg/kube"
- "github.com/apache/dubbo-kubernetes/pkg/pointer"
"github.com/apache/dubbo-kubernetes/pkg/util/sets"
"github.com/apache/dubbo-kubernetes/pkg/util/slices"
"github.com/hashicorp/go-multierror"
@@ -24,6 +24,7 @@ type Installer struct {
Kube kube.CLIClient
Values values.Map
ProgressInfo *progress.Info
+ Logger clog.Logger
}
func (i Installer) install(manifests []manifest.ManifestSet) error {
@@ -111,7 +112,6 @@ func (i Installer) serverSideApply(obj manifest.Manifest)
error {
}
if _, err := dc.Patch(context.TODO(), obj.GetName(),
types.ApplyPatchType, []byte(obj.Content), metav1.PatchOptions{
DryRun: dryRun,
- Force: pointer.Of(true),
FieldManager: operatorFieldOwner,
}); err != nil {
return fmt.Errorf("failed to update resource with server-side
apply for obj %v: %v", objStr, err)
diff --git a/operator/pkg/manifest/manifest.go
b/operator/pkg/manifest/manifest.go
index bf757d07..af3c3fa8 100644
--- a/operator/pkg/manifest/manifest.go
+++ b/operator/pkg/manifest/manifest.go
@@ -3,6 +3,7 @@ package manifest
import (
"encoding/json"
"github.com/apache/dubbo-kubernetes/operator/pkg/component"
+ "github.com/apache/dubbo-kubernetes/operator/pkg/parts"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)
@@ -32,7 +33,10 @@ func FromJSON(j []byte) (Manifest, error) {
func FromYAML(y []byte) (Manifest, error) {
us := &unstructured.Unstructured{}
if err := yaml.Unmarshal(y, us); err != nil {
- return Manifest{}, err
+ return Manifest{
+ Unstructured: us,
+ Content: string(y),
+ }, err
}
return Manifest{Unstructured: us, Content: string(y)}, nil
}
@@ -54,5 +58,5 @@ func Parse(output []string) ([]Manifest, error) {
}
func ParseMultiple(output string) ([]Manifest, error) {
- return nil, nil
+ return Parse(parts.SplitString(output))
}
diff --git a/operator/pkg/render/manifest.go b/operator/pkg/render/manifest.go
index ccccab57..2da100a5 100644
--- a/operator/pkg/render/manifest.go
+++ b/operator/pkg/render/manifest.go
@@ -60,18 +60,23 @@ func MergeInputs(filenames []string, flags []string)
(values.Map, error) {
path := ConfigBase.GetPathString("")
profile := ConfigBase.GetPathString("spec.profile")
- value, _ := ConfigBase.GetPathMap("spec.values")
base, err := readProfile(path, profile)
if err != nil {
return base, err
}
base.MergeFrom(ConfigBase)
+ return base, nil
+}
- if value != nil {
- base.MergeFrom(values.Map{"spec": values.Map{"values": value}})
+func checkDops(s string) error {
+ mfs, err := manifest.ParseMultiple(s)
+ if err != nil {
+ return fmt.Errorf("unable to parse file: %v", err)
}
-
- return base, nil
+ if len(mfs) > 1 {
+ return fmt.Errorf("contains multiple DubboOperator CRs, only
one per file is supported")
+ }
+ return nil
}
func readProfile(path, profile string) (values.Map, error) {
@@ -106,27 +111,16 @@ func readBuiltinProfile(path, profile string)
(values.Map, error) {
return values.MapFromYAML(pb)
}
-func checkDops(s string) error {
- mfs, err := manifest.ParseMultiple(s)
- if err != nil {
- return fmt.Errorf("unable to parse file: %v", err)
- }
- if len(mfs) > 1 {
- return fmt.Errorf("contains multiple DubboOperator CRs, only
one per file is supported")
- }
- return nil
-}
-
func GenerateManifest(files []string, setFlags []string, logger clog.Logger,
client kube.Client) ([]manifest.ManifestSet, values.Map, error) {
- var chartWarnings util.Errors
merged, err := MergeInputs(files, setFlags)
if err != nil {
- return nil, nil, fmt.Errorf("merge inputs: %v", err)
+ return nil, nil, fmt.Errorf("merge inputs: %v %v", err)
}
if err := validateDubboOperator(merged, logger); err != nil {
return nil, nil, fmt.Errorf("validateDubboOperator err:%v", err)
}
+ var chartWarnings util.Errors
allManifests := map[component.Name]manifest.ManifestSet{}
for _, comp := range component.AllComponents {
specs, err := comp.Get(merged)
@@ -156,6 +150,7 @@ func GenerateManifest(files []string, setFlags []string,
logger clog.Logger, cli
}
}
}
+
if logger != nil {
for _, w := range chartWarnings {
logger.LogAndErrorf("%s %v", "❗", w)
diff --git a/operator/pkg/util/clog/clog.go b/operator/pkg/util/clog/clog.go
index f83c315e..89ff2107 100644
--- a/operator/pkg/util/clog/clog.go
+++ b/operator/pkg/util/clog/clog.go
@@ -13,6 +13,31 @@ type ConsoleLogger struct {
scope *log.Scope
}
+type Logger interface {
+ LogAndPrint(v ...any)
+ LogAndError(v ...any)
+ LogAndFatal(v ...any)
+ LogAndPrintf(format string, a ...any)
+ LogAndErrorf(format string, a ...any)
+ LogAndFatalf(format string, a ...any)
+}
+
+func NewConsoleLogger(stdOut, stdErr io.Writer, scope *log.Scope)
*ConsoleLogger {
+ s := scope
+ if s == nil {
+ s = log.RegisterScope(log.DefaultScopeName,
log.DefaultScopeName)
+ }
+ return &ConsoleLogger{
+ stdOut: stdOut,
+ stdErr: stdErr,
+ scope: s,
+ }
+}
+
+func NewDefaultLogger() *ConsoleLogger {
+ return NewConsoleLogger(os.Stdout, os.Stderr, nil)
+}
+
func (l *ConsoleLogger) LogAndPrint(v ...any) {
if len(v) == 0 {
return
@@ -49,31 +74,6 @@ func (l *ConsoleLogger) LogAndFatalf(format string, a
...any) {
os.Exit(-1)
}
-type Logger interface {
- LogAndPrint(v ...any)
- LogAndError(v ...any)
- LogAndFatal(v ...any)
- LogAndPrintf(format string, a ...any)
- LogAndErrorf(format string, a ...any)
- LogAndFatalf(format string, a ...any)
-}
-
-func NewDefaultLogger() *ConsoleLogger {
- return nil
-}
-
-func NewConsoleLogger(stdOut, stdErr io.Writer, scope *log.Scope)
*ConsoleLogger {
- s := scope
- if s == nil {
- s = log.RegisterScope(log.DefaultScopeName,
log.DefaultScopeName)
- }
- return &ConsoleLogger{
- stdOut: stdOut,
- stdErr: stdErr,
- scope: s,
- }
-}
-
func (l *ConsoleLogger) Print(s string) {
_, _ = l.stdOut.Write([]byte(s))
}
diff --git a/operator/pkg/values/map.go b/operator/pkg/values/map.go
index f5ecc7ab..a691e24e 100644
--- a/operator/pkg/values/map.go
+++ b/operator/pkg/values/map.go
@@ -22,7 +22,7 @@ func (m Map) JSON() string {
}
func (m Map) YAML() string {
- bytes, err := json.Marshal(m)
+ bytes, err := yaml.Marshal(m)
if err != nil {
panic(fmt.Sprintf("yaml Marshal: %v", err))
}
@@ -40,7 +40,7 @@ func MapFromJSON(input []byte) (Map, error) {
func MapFromYAML(input []byte) (Map, error) {
m := make(Map)
- err := json.Unmarshal(input, &m)
+ err := yaml.Unmarshal(input, &m)
if err != nil {
return nil, err
}