ref(pkg/kube): simplify creating versioned objects

pull/3945/head
Adam Reese 7 years ago
parent a78aff8d39
commit c233336079
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -37,7 +37,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 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/fields"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
@ -186,7 +185,7 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
//Get the relation pods //Get the relation pods
objPods, err = c.getSelectRelationPod(info, objPods) objPods, err = c.getSelectRelationPod(info, objPods)
if err != nil { 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 return nil
@ -485,7 +484,7 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
return nil return nil
} }
versioned, err := c.AsVersionedObject(target.Object) versioned, err := target.Versioned()
if runtime.IsNotRegisteredError(err) { if runtime.IsNotRegisteredError(err) {
return nil return nil
} }
@ -606,18 +605,6 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
return 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. // waitForJob is a helper that waits for a job to complete.
// //
// This operates on an event returned from a watcher. // 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) 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) { if runtime.IsNotRegisteredError(err) {
return objPods, nil return objPods, nil
} }

@ -56,7 +56,7 @@ func (c *Client) waitForResources(timeout time.Duration, created Result) error {
pvc := []v1.PersistentVolumeClaim{} pvc := []v1.PersistentVolumeClaim{}
deployments := []deployment{} deployments := []deployment{}
for _, v := range created { for _, v := range created {
obj, err := c.AsVersionedObject(v.Object) obj, err := v.Versioned()
if err != nil && !runtime.IsNotRegisteredError(err) { if err != nil && !runtime.IsNotRegisteredError(err) {
return false, err return false, err
} }

Loading…
Cancel
Save