Skip to content
Permalink
Browse files

vendor a unstructured converter than can handle int64 => float64

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 65af9a19396cffdb57512f8eedff2cd4776f9e11
Showing with 830 additions and 21 deletions.
  1. +2 −12 internal/describer/customresource.go
  2. +7 −4 pkg/navigation/navigation.go
  3. +8 −5 pkg/store/get_as.go
  4. +813 −0 thirdparty/unstructured/converter.go
@@ -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"
@@ -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
@@ -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
@@ -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.
@@ -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)
@@ -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 {

0 comments on commit 65af9a1

Please sign in to comment.
You can’t perform that action at this time.