diff --git a/pkg/git/git.go b/pkg/git/git.go index 0b46a33..f918f60 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -19,7 +19,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" "github.com/gosimple/slug" "github.com/pkg/errors" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/kustomize/api/types" ) @@ -107,7 +107,7 @@ func CreateTenantResources(connector connectors.Connector, tenant v1.Tenant, ten // TODO: This should not append the resources, tenant yaml files should be in // their own directories kustomization.Resources = append(kustomization.Resources, tenant.ID) - existingKustomization, err := yaml.Marshal(kustomization) + existingKustomization, err := utils.MarshalYAML(kustomization) if err != nil { return nil, err } diff --git a/pkg/utils/yaml.go b/pkg/utils/yaml.go new file mode 100644 index 0000000..f0a5bb6 --- /dev/null +++ b/pkg/utils/yaml.go @@ -0,0 +1,15 @@ +package utils + +import ( + "bytes" + "gopkg.in/yaml.v3" +) + +func MarshalYAML(obj any) ([]byte, error) { + var b bytes.Buffer + yamlEncoder := yaml.NewEncoder(&b) + // Use 2 space indentation to be consistent with yq + yamlEncoder.SetIndent(2) + err := yamlEncoder.Encode(obj) + return b.Bytes(), err +}