Skip to content

Commit

Permalink
vendor a unstructured converter than can handle int64 => float64
Browse files Browse the repository at this point in the history
The default unstructured converter can't convert int64 to float64. This change vendors a version that adds that functionality.

#143
  • Loading branch information
bryanl committed Aug 9, 2019
1 parent 1cf12cc commit 65af9a1
Show file tree
Hide file tree
Showing 4 changed files with 830 additions and 21 deletions.
14 changes: 2 additions & 12 deletions internal/describer/customresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/pkg/errors"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"

"github.com/vmware/octant/internal/log"
"github.com/vmware/octant/internal/module"
Expand All @@ -36,17 +35,8 @@ func CustomResourceDefinitionNames(ctx context.Context, o store.Store) ([]string

var list []string

logger := log.From(ctx)

for _, object := range rawList.Items {
crd := &apiextv1beta1.CustomResourceDefinition{}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, crd); err != nil {
logger.Errorf("%v", errors.Wrapf(errors.Wrapf(err, "crd conversion failed"), object.GetName()))
continue
}

list = append(list, crd.Name)
list = append(list, object.GetName())
}

return list, nil
Expand All @@ -61,7 +51,7 @@ func CustomResourceDefinition(ctx context.Context, name string, o store.Store) (

crd := &apiextv1beta1.CustomResourceDefinition{}
if err := store.GetAs(ctx, o, key, crd); err != nil {
return nil, errors.Wrap(err, "get CRD from object store")
return nil, errors.Wrap(err, "get object as custom resource definition from store")
}

return crd, nil
Expand Down
11 changes: 7 additions & 4 deletions pkg/navigation/navigation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/vmware/octant/internal/log"
"github.com/vmware/octant/pkg/icon"
"github.com/vmware/octant/pkg/store"
octantunstructured "github.com/vmware/octant/thirdparty/unstructured"
)

// Option is an option for configuring navigation.
Expand Down Expand Up @@ -117,12 +117,15 @@ func CustomResourceDefinitions(ctx context.Context, o store.Store) ([]*apiextv1b

logger := log.From(ctx)

list := []*apiextv1beta1.CustomResourceDefinition{}
var list []*apiextv1beta1.CustomResourceDefinition
for i := range rawList.Items {
crd := &apiextv1beta1.CustomResourceDefinition{}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(rawList.Items[i].Object, crd); err != nil {
logger.Errorf("%v", errors.Wrapf(errors.Wrapf(err, "crd conversion failed"), rawList.Items[i].GetName()))
// NOTE: (bryanl) vendored converter can't convert from int64 to float64. Watching
// https://github.com/kubernetes-sigs/yaml/pull/14 to see when it gets pulled into
// a release so Octant can switch back.
if err := octantunstructured.DefaultUnstructuredConverter.FromUnstructured(rawList.Items[i].Object, crd); err != nil {
logger.Errorf("%v", errors.Wrapf(errors.Wrapf(err, "converting unstructured object to custom resource definition"), rawList.Items[i].GetName()))
continue
}
list = append(list, crd)
Expand Down
13 changes: 8 additions & 5 deletions pkg/store/get_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ import (
"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/runtime"

octantunstructured "github.com/vmware/octant/thirdparty/unstructured"
)

// GetAs gets an object from the object store by key.
func GetAs(ctx context.Context, o Store, key Key, as interface{}) error {
u, err := o.Get(ctx, key)
if err != nil {
return errors.Wrap(err, "get object from objectstore")
return errors.Wrap(err, "get object from object store")
}

if u == nil {
return nil
}

err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, as)
if err != nil {
return err
// NOTE: (bryanl) vendored converter can't convert from int64 to float64. Watching
// https://github.com/kubernetes-sigs/yaml/pull/14 to see when it gets pulled into
// a release so Octant can switch back.
if err := octantunstructured.DefaultUnstructuredConverter.FromUnstructured(u.Object, as); err != nil {
return errors.Wrap(err, "unable to convert object to unstructured")
}

if err := copyObjectMeta(as, u); err != nil {
Expand Down
Loading

0 comments on commit 65af9a1

Please sign in to comment.