Skip to content

Commit

Permalink
Merge pull request kubernetes#58293 from deads2k/cli-18-fail
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fail earlier on discovery failures

When discovery fails, the object mapper and typer are incomplete.  This change reflects that and returns errors instead of nils.

@juanvallejo
  • Loading branch information
Kubernetes Submit Queue authored Jan 17, 2018
2 parents d72631b + 49f12fa commit c67a5e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 8 additions & 4 deletions pkg/kubectl/cmd/util/factory_object_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,25 @@ func NewObjectMappingFactory(clientAccessFactory ClientAccessFactory) ObjectMapp
// the built in mapper if necessary. It supports unstructured objects either way, since
// the underlying Scheme supports Unstructured. The mapper will return converters that can
// convert versioned types to unstructured and back.
// It can return an error and the best effort unstructured mapper and typer.
func (f *ring1Factory) objectLoader() (meta.RESTMapper, runtime.ObjectTyper, error) {
discoveryClient, err := f.clientAccessFactory.DiscoveryClient()
if err != nil {
glog.V(3).Infof("Unable to get a discovery client to find server resources, falling back to hardcoded types: %v", err)
return legacyscheme.Registry.RESTMapper(), legacyscheme.Scheme, nil
unstructuredMapper := discovery.NewRESTMapper(nil, meta.InterfacesForUnstructured)
unstructuredTyper := discovery.NewUnstructuredObjectTyper(nil)
return unstructuredMapper, unstructuredTyper, err
}

groupResources, err := discovery.GetAPIGroupResources(discoveryClient)
if err != nil && !discoveryClient.Fresh() {
discoveryClient.Invalidate()
groupResources, err = discovery.GetAPIGroupResources(discoveryClient)
}
// even if we can't get all the results, we're better off continuing with what we can than not presenting
// anything. This mirrors old behavior that used to fallback to a hardcoded list of API types compiled
// into kubernetes.
if err != nil {
glog.V(3).Infof("Unable to retrieve API resources, falling back to hardcoded types: %v", err)
return legacyscheme.Registry.RESTMapper(), legacyscheme.Scheme, nil
glog.V(1).Infof("Unable to retrieve all API resources, continuing with partial results: %v", err)
}

// allow conversion between typed and unstructured objects
Expand Down
3 changes: 0 additions & 3 deletions test/integration/etcd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go_test(
"//cmd/kube-apiserver/app/options:go_default_library",
"//pkg/api/legacyscheme:go_default_library",
"//pkg/apis/core:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/master:go_default_library",
"//test/integration/framework:go_default_library",
"//vendor/github.com/coreos/etcd/clientv3:go_default_library",
Expand All @@ -40,8 +39,6 @@ go_test(
"//vendor/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
"//vendor/k8s.io/client-go/util/flowcontrol:go_default_library",
],
)
Expand Down
7 changes: 1 addition & 6 deletions test/integration/etcd/etcd_storage_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ import (
"k8s.io/apiserver/pkg/storage/storagebackend"
clientset "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/kubernetes/cmd/kube-apiserver/app"
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
"k8s.io/kubernetes/pkg/api/legacyscheme"
kapi "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/test/integration/framework"

// install all APIs
Expand Down Expand Up @@ -798,9 +795,7 @@ func startRealMasterOrDie(t *testing.T, certDir string) (*allClient, clientv3.KV
t.Fatal(err)
}

mapper, _ := util.NewFactory(clientcmd.NewDefaultClientConfig(*clientcmdapi.NewConfig(), &clientcmd.ConfigOverrides{})).Object()

return client, kvClient, mapper
return client, kvClient, legacyscheme.Registry.RESTMapper()
}

func dumpEtcdKVOnFailure(t *testing.T, kvClient clientv3.KV) {
Expand Down

0 comments on commit c67a5e4

Please sign in to comment.