add fetching into discovery client for OpenAPI v3

reflect latest struct changes

use correct discovery openapi test data layout

make the OpenAPIv3 interface less blue

field grouping

add copyrights

implement cached discovery client

add cached discovery tests

address review feedback

Kubernetes-commit: 075866b3e3ea029c243d82d8d6eb99e96d9c49d3
This commit is contained in:
Alexander Zielenski
2022-03-22 10:40:56 -07:00
committed by Kubernetes Publisher
parent 92adc4de69
commit 018cf8ace6
18 changed files with 680 additions and 11 deletions

View File

@@ -33,6 +33,8 @@ import (
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/openapi"
cachedopenapi "k8s.io/client-go/openapi/cached"
restclient "k8s.io/client-go/rest"
)
@@ -56,6 +58,9 @@ type CachedDiscoveryClient struct {
invalidated bool
// fresh is true if all used cache files were ours
fresh bool
///
openapiClient openapi.Client
}
var _ discovery.CachedDiscoveryInterface = &CachedDiscoveryClient{}
@@ -233,6 +238,21 @@ func (d *CachedDiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) {
return d.delegate.OpenAPISchema()
}
// OpenAPIV3 retrieves and parses the OpenAPIV3 specs exposed by the server
func (d *CachedDiscoveryClient) OpenAPIV3() openapi.Client {
// Must take lock since Invalidate call may modify openapiClient
d.mutex.Lock()
defer d.mutex.Unlock()
if d.openapiClient == nil {
// Delegate is discovery client created with special HTTP client which
// respects E-Tag cache responses to serve cache from disk.
d.openapiClient = cachedopenapi.NewClient(d.delegate.OpenAPIV3())
}
return d.openapiClient
}
// Fresh is supposed to tell the caller whether or not to retry if the cache
// fails to find something (false = retry, true = no need to retry).
func (d *CachedDiscoveryClient) Fresh() bool {
@@ -250,6 +270,7 @@ func (d *CachedDiscoveryClient) Invalidate() {
d.ourFiles = map[string]struct{}{}
d.fresh = true
d.invalidated = true
d.openapiClient = nil
}
// NewCachedDiscoveryClientForConfig creates a new DiscoveryClient for the given config, and wraps