Merge pull request #29187 from soltysh/multiversion_kubectl

Automatic merge from submit-queue

Create client from API version passed in config or use default

When creating a client read the `GroupVersion` value passed in the `restclient.Config`. If the passed `GroupVersion` does not match current group or is not enabled fallback to default `GroupVersion` for that group.

This PR should allow accessing `ScheduledJob` properly in `batch/v2alpha1`.

@smarterclayton @deads2k @caesarxuchao @lavalamp ptal
This commit is contained in:
k8s-merge-robot
2016-08-02 06:10:26 -07:00
committed by GitHub
10 changed files with 54 additions and 228 deletions

View File

@@ -17,8 +17,6 @@ limitations under the License.
package unversioned
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/restclient"
)
@@ -93,7 +91,7 @@ func (c *ExtensionsClient) StorageClasses() StorageClassInterface {
// incompatible ways at any time.
func NewExtensions(c *restclient.Config) (*ExtensionsClient, error) {
config := *c
if err := setExtensionsDefaults(&config); err != nil {
if err := setGroupDefaults(extensions.GroupName, &config); err != nil {
return nil, err
}
client, err := restclient.RESTClientFor(&config)
@@ -114,23 +112,3 @@ func NewExtensionsOrDie(c *restclient.Config) *ExtensionsClient {
}
return client
}
func setExtensionsDefaults(config *restclient.Config) error {
// if experimental group is not registered, return an error
g, err := registered.Group(extensions.GroupName)
if err != nil {
return err
}
config.APIPath = defaultAPIPath
if config.UserAgent == "" {
config.UserAgent = restclient.DefaultKubernetesUserAgent()
}
// TODO: Unconditionally set the config.Version, until we fix the config.
//if config.Version == "" {
copyGroupVersion := g.GroupVersion
config.GroupVersion = &copyGroupVersion
//}
config.NegotiatedSerializer = api.Codecs
return nil
}