Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

vendor a unstructured converter than can handle int64 => float64 #145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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