mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-04 18:56:21 +00:00
rename cache, add to integration test
Kubernetes-commit: 604db6eb2ada446e78152685943253455b5ec888
This commit is contained in:
parent
4389b4f36a
commit
f316b7b5f5
@ -19,22 +19,22 @@ type UnstructuredExtractor interface {
|
|||||||
ExtractUnstructuredStatus(object *unstructured.Unstructured, fieldManager string) (*unstructured.Unstructured, error)
|
ExtractUnstructuredStatus(object *unstructured.Unstructured, fieldManager string) (*unstructured.Unstructured, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// objectTypeCache is a cache of typed.ParseableTypes
|
//// objectTypeCache is a cache of typed.ParseableTypes
|
||||||
type objectTypeCache interface {
|
//type objectTypeCache interface {
|
||||||
objectTypeForGVK(gvk schema.GroupVersionKind) (*typed.ParseableType, error)
|
// objectTypeForGVK(gvk schema.GroupVersionKind) (*typed.ParseableType, error)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// nonCachingObjectTypeCache is a objectTypeCache that does no caching
|
// objectTypeCache is a objectTypeCache that does no caching
|
||||||
// (i.e. it downloads the OpenAPISchema every time)
|
// (i.e. it downloads the OpenAPISchema every time)
|
||||||
// Useful during the proof-of-concept stage until we agree on a caching solution.
|
// Useful during the proof-of-concept stage until we agree on a caching solution.
|
||||||
type nonCachingObjectTypeCache struct {
|
type objectTypeCache struct {
|
||||||
// TODO: lock this?
|
// TODO: lock this?
|
||||||
discoveryClient discovery.DiscoveryInterface
|
discoveryClient discovery.DiscoveryInterface
|
||||||
gvkParser *fieldmanager.GvkParser
|
gvkParser *fieldmanager.GvkParser
|
||||||
}
|
}
|
||||||
|
|
||||||
// objectTypeForGVK retrieves the typed.ParseableType for a given gvk from the cache
|
// objectTypeForGVK retrieves the typed.ParseableType for a given gvk from the cache
|
||||||
func (c *nonCachingObjectTypeCache) objectTypeForGVK(gvk schema.GroupVersionKind) (*typed.ParseableType, error) {
|
func (c *objectTypeCache) objectTypeForGVK(gvk schema.GroupVersionKind) (*typed.ParseableType, error) {
|
||||||
|
|
||||||
if !c.discoveryClient.HasOpenAPISchemaChanged() && c.gvkParser != nil {
|
if !c.discoveryClient.HasOpenAPISchemaChanged() && c.gvkParser != nil {
|
||||||
// cache hit
|
// cache hit
|
||||||
@ -67,14 +67,14 @@ func (c *nonCachingObjectTypeCache) objectTypeForGVK(gvk schema.GroupVersionKind
|
|||||||
}
|
}
|
||||||
|
|
||||||
type extractor struct {
|
type extractor struct {
|
||||||
cache objectTypeCache
|
cache *objectTypeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnstructuredExtractor creates the extractor with which you can extract the applied configuration
|
// NewUnstructuredExtractor creates the extractor with which you can extract the applied configuration
|
||||||
// for a given manager from an unstructured object.
|
// for a given manager from an unstructured object.
|
||||||
func NewUnstructuredExtractor(dc discovery.DiscoveryInterface) UnstructuredExtractor {
|
func NewUnstructuredExtractor(dc discovery.DiscoveryInterface) UnstructuredExtractor {
|
||||||
return &extractor{
|
return &extractor{
|
||||||
cache: &nonCachingObjectTypeCache{
|
cache: &objectTypeCache{
|
||||||
discoveryClient: dc,
|
discoveryClient: dc,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,10 @@ func (d *memCacheClient) OpenAPISchema() (*openapi_v2.Document, error) {
|
|||||||
return d.delegate.OpenAPISchema()
|
return d.delegate.OpenAPISchema()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *memCacheClient) HasOpenAPISchemaChanged() bool {
|
||||||
|
return d.delegate.HasOpenAPISchemaChanged()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *memCacheClient) Fresh() bool {
|
func (d *memCacheClient) Fresh() bool {
|
||||||
d.lock.RLock()
|
d.lock.RLock()
|
||||||
defer d.lock.RUnlock()
|
defer d.lock.RUnlock()
|
||||||
|
@ -153,6 +153,10 @@ func (c *FakeDiscovery) OpenAPISchema() (*openapi_v2.Document, error) {
|
|||||||
return &openapi_v2.Document{}, nil
|
return &openapi_v2.Document{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FakeDiscovery) HasOpenAPISchemaChanged() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// RESTClient returns a RESTClient that is used to communicate with API server
|
// RESTClient returns a RESTClient that is used to communicate with API server
|
||||||
// by this client implementation.
|
// by this client implementation.
|
||||||
func (c *FakeDiscovery) RESTClient() restclient.Interface {
|
func (c *FakeDiscovery) RESTClient() restclient.Interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user