github.com/verrazzano/verrazzano@v1.7.0/pkg/k8sutil/yaml_util.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package k8sutil 5 6 import ( 7 "bytes" 8 "fmt" 9 10 "gopkg.in/yaml.v3" 11 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 12 ) 13 14 // Marshal a list of unstructured objects as YAML to a byte array 15 func Marshal(objs []unstructured.Unstructured) ([]byte, error) { 16 buffer := bytes.Buffer{} 17 sepLine := fmt.Sprintf("\n%s\n", sep) 18 for _, obj := range objs { 19 nextBytes, err := yaml.Marshal(obj.Object) 20 if err != nil { 21 return nil, err 22 } 23 buffer.Write(nextBytes) 24 buffer.WriteString(sepLine) 25 } 26 return buffer.Bytes(), nil 27 }