stop senseless negotiation

pull/6/head
deads2k 2017-02-13 10:03:04 -05:00
parent e80afed777
commit e063ca3e82
2 changed files with 21 additions and 5 deletions

View File

@ -48,6 +48,9 @@ type ClientCache struct {
fedClientSets map[schema.GroupVersion]fedclientset.Interface
configs map[schema.GroupVersion]*restclient.Config
// noVersionConfig provides a cached config for the case of no required version specified
noVersionConfig *restclient.Config
matchVersion bool
defaultConfigLock sync.Mutex
@ -104,8 +107,10 @@ func (c *ClientCache) ClientConfigForVersion(requiredVersion *schema.GroupVersio
// before looking up from the cache
if requiredVersion != nil {
if config, ok := c.configs[*requiredVersion]; ok {
return config, nil
return copyConfig(config), nil
}
} else if c.noVersionConfig != nil {
return copyConfig(c.noVersionConfig), nil
}
negotiatedVersion, err := discovery.NegotiateVersion(discoveryClient, requiredVersion, api.Registry.EnabledVersions())
@ -118,15 +123,23 @@ func (c *ClientCache) ClientConfigForVersion(requiredVersion *schema.GroupVersio
oldclient.SetKubernetesDefaults(&config)
if requiredVersion != nil {
c.configs[*requiredVersion] = &config
c.configs[*requiredVersion] = copyConfig(&config)
} else {
c.noVersionConfig = copyConfig(&config)
}
// `version` does not necessarily equal `config.Version`. However, we know that we call this method again with
// `config.Version`, we should get the config we've just built.
configCopy := config
c.configs[*config.GroupVersion] = &configCopy
c.configs[*config.GroupVersion] = copyConfig(&config)
return &config, nil
return copyConfig(&config), nil
}
func copyConfig(in *restclient.Config) *restclient.Config {
configCopy := *in
copyGroupVersion := *configCopy.GroupVersion
configCopy.GroupVersion = &copyGroupVersion
return &configCopy
}
// ClientSetForVersion initializes or reuses a clientset for the specified version, or returns an

View File

@ -49,6 +49,9 @@ func MatchesServerVersion(clientVersion apimachineryversion.Info, client Discove
// preference.
// - If version is provided and the server does not support it,
// return an error.
// TODO negotiation should be reserved for cases where we need a version for a given group. In those cases, it should return an ordered list of
// server preferences. From that list, a separate function can match from an ordered list of client versions.
// This is not what the function has ever done before, but it makes more logical sense.
func NegotiateVersion(client DiscoveryInterface, requiredGV *schema.GroupVersion, clientRegisteredGVs []schema.GroupVersion) (*schema.GroupVersion, error) {
clientVersions := sets.String{}
for _, gv := range clientRegisteredGVs {