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 276809a9 [operator] update merge inputs and base profile
276809a9 is described below

commit 276809a9a6af6485f3efe34e2e21ec229c240678
Author: mfordjody <[email protected]>
AuthorDate: Fri Dec 13 19:15:45 2024 +0800

    [operator] update merge inputs and base profile
---
 manifests/manifest.go           | 12 +++++++++--
 operator/pkg/render/manifest.go | 46 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/manifests/manifest.go b/manifests/manifest.go
index 3d457b5f..8ea61bce 100644
--- a/manifests/manifest.go
+++ b/manifests/manifest.go
@@ -17,7 +17,15 @@ package manifests
 
 import (
        "embed"
+       "io/fs"
+       "os"
 )
 
-//go:embed all:addons/* all:charts/* all:profiles/*
-var EmbedRootFS embed.FS
+var FS embed.FS
+
+func BuiltinDir(dir string) fs.FS {
+       if dir == "" {
+               return FS
+       }
+       return os.DirFS(dir)
+}
diff --git a/operator/pkg/render/manifest.go b/operator/pkg/render/manifest.go
index e60af13d..36122c3f 100644
--- a/operator/pkg/render/manifest.go
+++ b/operator/pkg/render/manifest.go
@@ -2,6 +2,7 @@ package render
 
 import (
        "fmt"
+       "github.com/apache/dubbo-kubernetes/manifests"
        "github.com/apache/dubbo-kubernetes/operator/cmd/validation"
        "github.com/apache/dubbo-kubernetes/operator/pkg/apis"
        "github.com/apache/dubbo-kubernetes/operator/pkg/component"
@@ -47,8 +48,51 @@ func MergeInputs(filenames []string, flags []string) 
([]values.Map, error) {
                }
                ConfigBase.MergeFrom(m)
        }
-       return nil, nil
+       if err := ConfigBase.SetSpecPaths(flags...); err != nil {
+               return nil, err
+       }
+       path := ConfigBase.GetPathString("")
+       profile := ConfigBase.GetPathString("spec.profile")
+       base, err := readProfile(path, profile)
+       if err != nil {
+               return base, err
+       }
+       base.MergeFrom(ConfigBase)
+       return base, nil
 }
+
+func readProfile(path, profile string) (values.Map, error) {
+       if profile == "" {
+               profile = "default"
+       }
+       base, err := readBuiltinProfile(path, "default")
+       if err != nil {
+               return nil, err
+       }
+       if profile == "default" {
+               return base, nil
+       }
+       p, err := readBuiltinProfile(path, profile)
+       if err != nil {
+               return nil, err
+       }
+       base.MergeFrom(p)
+       return base, nil
+}
+
+func readBuiltinProfile(path, profile string) (values.Map, error) {
+       fs := manifests.BuiltinDir(path)
+       file, err := fs.Open(fmt.Sprintf("profiles/%v.yaml", profile))
+       if err != nil {
+               return nil, err
+       }
+       pb, err := io.ReadAll(file)
+       if err != nil {
+               return nil, err
+       }
+       return values.MapFromYAML(pb)
+}
+
 func checkDops(s string) error {
        mfs, err := manifest.ParseMultiple(s)
        if err != nil {

Reply via email to