Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Fix ignite-spawn's formatting when performing cleanup on VM metadata #336

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pkg/util/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/weaveworks/ignite/pkg/apis/ignite/scheme"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/strategicpatch"
)
Expand Down Expand Up @@ -51,7 +52,12 @@ func Apply(original, patch []byte, gvk schema.GroupVersionKind) ([]byte, error)
return nil, err
}

return strategicpatch.StrategicMergePatch(original, patch, emptyobj)
b, err := strategicpatch.StrategicMergePatch(original, patch, emptyobj)
if err != nil {
return nil, err
}

return serializerEncode(b)
}

func ApplyOnFile(filePath string, patch []byte, gvk schema.GroupVersionKind) error {
Expand All @@ -67,3 +73,15 @@ func ApplyOnFile(filePath string, patch []byte, gvk schema.GroupVersionKind) err

return ioutil.WriteFile(filePath, newContent, 0644)
}

// StrategicMergePatch returns an unindented, unorganized JSON byte slice,
// this helper takes that as an input and returns the same JSON re-encoded
// with the serializer so it conforms to a runtime.Object
func serializerEncode(input []byte) (result []byte, err error) {
var obj runtime.Object
if obj, err = serializer.Decode(input, true); err == nil {
result, err = serializer.EncodeJSON(obj)
}

return
}