You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/api/kubernetes/cli/resource.go

28 lines
468 B

package cli
import (
"bytes"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
)
func GenerateYAML(obj runtime.Object) (string, error) {
serializer := json.NewSerializerWithOptions(
json.DefaultMetaFactory, nil, nil,
json.SerializerOptions{
Yaml: true,
Pretty: true,
Strict: true,
},
)
b := new(bytes.Buffer)
err := serializer.Encode(obj, b)
if err != nil {
return "", err
}
return b.String(), nil
}