-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 { | ||
*unstructured.Unstructured | ||
Content string | ||
} | ||
|
||
type ManifestSet struct { | ||
Comps component.Name | ||
Manifests []Manifest | ||
} | ||
|
||
func FromJSON(j []byte) (Manifest, error) { | ||
us := &unstructured.Unstructured{} | ||
if err := json.Unmarshal(j, us); err != nil { | ||
return Manifest{}, err | ||
} | ||
yml, err := yaml.Marshal(us) | ||
if err != nil { | ||
return Manifest{}, err | ||
} | ||
return Manifest{ | ||
Unstructured: us, | ||
Content: string(yml), | ||
}, 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 Parse() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package render | ||
|
||
import ( | ||
"github.com/apache/dubbo-kubernetes/operator/pkg/util/clog" | ||
) | ||
|
||
func () { | ||
|
||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package yml | ||
|
||
import ( | ||
"bufio" | ||
"strings" | ||
) | ||
|
||
func SplitString(yamlText string) []string { | ||
out := make([]string, 0) | ||
scanner := bufio.NewScanner(strings.NewReader(yamlText)) | ||
parts := []string{} | ||
active := strings.Builder{} | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if strings.HasPrefix(line, "---") { | ||
parts = append(parts, active.String()) | ||
active = strings.Builder{} | ||
} else { | ||
active.WriteString(line) | ||
active.WriteString("\n") | ||
} | ||
} | ||
if active.Len() > 0 { | ||
parts = append(parts, active.String()) | ||
} | ||
for _, part := range parts { | ||
part := strings.TrimSpace(part) | ||
if len(part) > 0 { | ||
out = append(out, part) | ||
} | ||
} | ||
return out | ||
} |