summaryrefslogtreecommitdiffstats
path: root/src/rsync/pkg/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/rsync/pkg/internal')
-rw-r--r--src/rsync/pkg/internal/utils.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/rsync/pkg/internal/utils.go b/src/rsync/pkg/internal/utils.go
index 59ff6df8..270edba5 100644
--- a/src/rsync/pkg/internal/utils.go
+++ b/src/rsync/pkg/internal/utils.go
@@ -23,8 +23,8 @@ import (
"k8s.io/client-go/kubernetes/scheme"
)
-// DecodeYAML reads a YAMl file to extract the Kubernetes object definition
-func DecodeYAML(path string, into runtime.Object) (runtime.Object, error) {
+// DecodeYAMLFile reads a YAMl file to extract the Kubernetes object definition
+func DecodeYAMLFile(path string, into runtime.Object) (runtime.Object, error) {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil, pkgerrors.New("File " + path + " not found")
@@ -47,6 +47,17 @@ func DecodeYAML(path string, into runtime.Object) (runtime.Object, error) {
return obj, nil
}
+// DecodeYAMLData reads a string to extract the Kubernetes object definition
+func DecodeYAMLData(data string, into runtime.Object) (runtime.Object, error) {
+ decode := scheme.Codecs.UniversalDeserializer().Decode
+ obj, _, err := decode([]byte(data), nil, into)
+ if err != nil {
+ return nil, pkgerrors.Wrap(err, "Deserialize YAML error")
+ }
+
+ return obj, nil
+}
+
//EnsureDirectory makes sure that the directories specified in the path exist
//If not, it will create them, if possible.
func EnsureDirectory(f string) error {