mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
stop senseless negotiation
This commit is contained in:
parent
e80afed777
commit
e063ca3e82
@ -48,6 +48,9 @@ type ClientCache struct {
|
|||||||
fedClientSets map[schema.GroupVersion]fedclientset.Interface
|
fedClientSets map[schema.GroupVersion]fedclientset.Interface
|
||||||
configs map[schema.GroupVersion]*restclient.Config
|
configs map[schema.GroupVersion]*restclient.Config
|
||||||
|
|
||||||
|
// noVersionConfig provides a cached config for the case of no required version specified
|
||||||
|
noVersionConfig *restclient.Config
|
||||||
|
|
||||||
matchVersion bool
|
matchVersion bool
|
||||||
|
|
||||||
defaultConfigLock sync.Mutex
|
defaultConfigLock sync.Mutex
|
||||||
@ -104,8 +107,10 @@ func (c *ClientCache) ClientConfigForVersion(requiredVersion *schema.GroupVersio
|
|||||||
// before looking up from the cache
|
// before looking up from the cache
|
||||||
if requiredVersion != nil {
|
if requiredVersion != nil {
|
||||||
if config, ok := c.configs[*requiredVersion]; ok {
|
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())
|
negotiatedVersion, err := discovery.NegotiateVersion(discoveryClient, requiredVersion, api.Registry.EnabledVersions())
|
||||||
@ -118,15 +123,23 @@ func (c *ClientCache) ClientConfigForVersion(requiredVersion *schema.GroupVersio
|
|||||||
oldclient.SetKubernetesDefaults(&config)
|
oldclient.SetKubernetesDefaults(&config)
|
||||||
|
|
||||||
if requiredVersion != nil {
|
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
|
// `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.
|
// `config.Version`, we should get the config we've just built.
|
||||||
configCopy := config
|
c.configs[*config.GroupVersion] = copyConfig(&config)
|
||||||
c.configs[*config.GroupVersion] = &configCopy
|
|
||||||
|
|
||||||
return &config, nil
|
return copyConfig(&config), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyConfig(in *restclient.Config) *restclient.Config {
|
||||||
|
configCopy := *in
|
||||||
|
copyGroupVersion := *configCopy.GroupVersion
|
||||||
|
configCopy.GroupVersion = ©GroupVersion
|
||||||
|
return &configCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientSetForVersion initializes or reuses a clientset for the specified version, or returns an
|
// ClientSetForVersion initializes or reuses a clientset for the specified version, or returns an
|
||||||
|
@ -49,6 +49,9 @@ func MatchesServerVersion(clientVersion apimachineryversion.Info, client Discove
|
|||||||
// preference.
|
// preference.
|
||||||
// - If version is provided and the server does not support it,
|
// - If version is provided and the server does not support it,
|
||||||
// return an error.
|
// 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) {
|
func NegotiateVersion(client DiscoveryInterface, requiredGV *schema.GroupVersion, clientRegisteredGVs []schema.GroupVersion) (*schema.GroupVersion, error) {
|
||||||
clientVersions := sets.String{}
|
clientVersions := sets.String{}
|
||||||
for _, gv := range clientRegisteredGVs {
|
for _, gv := range clientRegisteredGVs {
|
||||||
|
Loading…
Reference in New Issue
Block a user