You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2024/12/02 10:04:39 UTC

(dubbo-kubernetes) branch master updated: [operator] Parsing the manifests file (#520)

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 8dc835c3 [operator] Parsing the manifests file (#520)
8dc835c3 is described below

commit 8dc835c39e9d885c79778e473de24630485b9948
Author: mfordjody <11...@qq.com>
AuthorDate: Mon Dec 2 18:04:35 2024 +0800

    [operator] Parsing the manifests file (#520)
---
 operator/manifest/manifest.go | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/operator/manifest/manifest.go b/operator/manifest/manifest.go
index 58027288..bf757d07 100644
--- a/operator/manifest/manifest.go
+++ b/operator/manifest/manifest.go
@@ -1,8 +1,10 @@
 package manifest
 
 import (
+	"encoding/json"
 	"github.com/apache/dubbo-kubernetes/operator/pkg/component"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"sigs.k8s.io/yaml"
 )
 
 type Manifest struct {
@@ -14,3 +16,43 @@ type ManifestSet struct {
 	Components component.Name
 	Manifests  []Manifest
 }
+
+func FromJSON(j []byte) (Manifest, error) {
+	us := &unstructured.Unstructured{}
+	if err := json.Unmarshal(j, us); err != nil {
+		return Manifest{}, err
+	}
+	y, err := yaml.Marshal(us)
+	if err != nil {
+		return Manifest{}, err
+	}
+	return Manifest{Unstructured: us, Content: string(y)}, nil
+}
+
+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)}, nil
+}
+
+func Parse(output []string) ([]Manifest, error) {
+	result := make([]Manifest, 0, len(output))
+	for _, m := range output {
+		mf, err := FromYAML([]byte(m))
+		if err != nil {
+			return nil, err
+		}
+		if mf.GetObjectKind().GroupVersionKind().Kind == "" {
+			continue
+		}
+		result = append(result, mf)
+	}
+	return result, nil
+
+}
+
+func ParseMultiple(output string) ([]Manifest, error) {
+	return nil, nil
+}