mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-03 18:26:59 +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)
|
||||
}
|
||||
|
||||
// objectTypeCache is a cache of typed.ParseableTypes
|
||||
type objectTypeCache interface {
|
||||
objectTypeForGVK(gvk schema.GroupVersionKind) (*typed.ParseableType, error)
|
||||
}
|
||||
//// objectTypeCache is a cache of typed.ParseableTypes
|
||||
//type objectTypeCache interface {
|
||||
// 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)
|
||||
// Useful during the proof-of-concept stage until we agree on a caching solution.
|
||||
type nonCachingObjectTypeCache struct {
|
||||
type objectTypeCache struct {
|
||||
// TODO: lock this?
|
||||
discoveryClient discovery.DiscoveryInterface
|
||||
gvkParser *fieldmanager.GvkParser
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// cache hit
|
||||
@ -67,14 +67,14 @@ func (c *nonCachingObjectTypeCache) objectTypeForGVK(gvk schema.GroupVersionKind
|
||||
}
|
||||
|
||||
type extractor struct {
|
||||
cache objectTypeCache
|
||||
cache *objectTypeCache
|
||||
}
|
||||
|
||||
// NewUnstructuredExtractor creates the extractor with which you can extract the applied configuration
|
||||
// for a given manager from an unstructured object.
|
||||
func NewUnstructuredExtractor(dc discovery.DiscoveryInterface) UnstructuredExtractor {
|
||||
return &extractor{
|
||||
cache: &nonCachingObjectTypeCache{
|
||||
cache: &objectTypeCache{
|
||||
discoveryClient: dc,
|
||||
},
|
||||
}
|
||||
|
@ -149,6 +149,10 @@ func (d *memCacheClient) OpenAPISchema() (*openapi_v2.Document, error) {
|
||||
return d.delegate.OpenAPISchema()
|
||||
}
|
||||
|
||||
func (d *memCacheClient) HasOpenAPISchemaChanged() bool {
|
||||
return d.delegate.HasOpenAPISchemaChanged()
|
||||
}
|
||||
|
||||
func (d *memCacheClient) Fresh() bool {
|
||||
d.lock.RLock()
|
||||
defer d.lock.RUnlock()
|
||||
|
@ -153,6 +153,10 @@ func (c *FakeDiscovery) OpenAPISchema() (*openapi_v2.Document, error) {
|
||||
return &openapi_v2.Document{}, nil
|
||||
}
|
||||
|
||||
func (c *FakeDiscovery) HasOpenAPISchemaChanged() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate with API server
|
||||
// by this client implementation.
|
||||
func (c *FakeDiscovery) RESTClient() restclient.Interface {
|
||||
|
Loading…
Reference in New Issue
Block a user