From c233336079a756af13208618d2cea71f7d9a5727 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 18 Apr 2018 09:24:16 -0700 Subject: [PATCH] ref(pkg/kube): simplify creating versioned objects --- pkg/kube/client.go | 19 +++---------------- pkg/kube/wait.go | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index d127b4a50..0684f4cc0 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -37,7 +37,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -186,7 +185,7 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) { //Get the relation pods objPods, err = c.getSelectRelationPod(info, objPods) if err != nil { - c.Log("Warning: get the relation pod is failed, err:%s", err.Error()) + c.Log("Warning: get the relation pod is failed, err:%s", err) } return nil @@ -485,7 +484,7 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object, return nil } - versioned, err := c.AsVersionedObject(target.Object) + versioned, err := target.Versioned() if runtime.IsNotRegisteredError(err) { return nil } @@ -606,18 +605,6 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err return err } -// AsVersionedObject converts a runtime.object to a versioned object. -func (c *Client) AsVersionedObject(obj runtime.Object) (runtime.Object, error) { - json, err := runtime.Encode(unstructured.UnstructuredJSONScheme, obj) - if err != nil { - return nil, err - } - versions := &runtime.VersionedObjects{} - decoder := unstructured.UnstructuredJSONScheme - err = runtime.DecodeInto(decoder, json, versions) - return versions.First(), err -} - // waitForJob is a helper that waits for a job to complete. // // This operates on an event returned from a watcher. @@ -712,7 +699,7 @@ func (c *Client) getSelectRelationPod(info *resource.Info, objPods map[string][] c.Log("get relation pod of object: %s/%s/%s", info.Namespace, info.Mapping.GroupVersionKind.Kind, info.Name) - versioned, err := c.AsVersionedObject(info.Object) + versioned, err := info.Versioned() if runtime.IsNotRegisteredError(err) { return objPods, nil } diff --git a/pkg/kube/wait.go b/pkg/kube/wait.go index 27ede15db..88f3c7d34 100644 --- a/pkg/kube/wait.go +++ b/pkg/kube/wait.go @@ -56,7 +56,7 @@ func (c *Client) waitForResources(timeout time.Duration, created Result) error { pvc := []v1.PersistentVolumeClaim{} deployments := []deployment{} for _, v := range created { - obj, err := c.AsVersionedObject(v.Object) + obj, err := v.Versioned() if err != nil && !runtime.IsNotRegisteredError(err) { return false, err }