-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unmarshal with k8s.io/apimachinery/pkg/util/yaml
- apimachinery yaml.Unmarshal fixes number types to int64 and float64 - Fix inaccurate error message in mutator - Move YamlStringer to object pkg for reuse by other pkgs - Fix jsonpath tests parsing y as a bool - Fix kstatus example_test.go to actually be a test
- Loading branch information
Showing
7 changed files
with
91 additions
and
85 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
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
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,35 @@ | ||
// Copyright 2020 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package object | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/kubectl/pkg/scheme" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
var codec = scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) | ||
|
||
// YamlStringer delays YAML marshalling for logging until String() is called. | ||
type YamlStringer struct { | ||
O runtime.Object | ||
} | ||
|
||
// String marshals the wrapped object to a YAML string. If serializing errors, | ||
// the error string will be returned instead. This is primarily for use with | ||
// verbose logging. | ||
func (ys YamlStringer) String() string { | ||
jsonBytes, err := runtime.Encode(unstructured.NewJSONFallbackEncoder(codec), ys.O) | ||
if err != nil { | ||
return fmt.Sprintf("<<failed to serialize as json: %s>>", err) | ||
} | ||
yamlBytes, err := yaml.JSONToYAML(jsonBytes) | ||
if err != nil { | ||
return fmt.Sprintf("<<failed to convert from json to yaml: %s>>", err) | ||
} | ||
return string(yamlBytes) | ||
} |
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