Moved memory-cached and disk-cached discovery to their own packages

Kubernetes-commit: 6666049898f93932655fef24f807bc4d6e439fc6
This commit is contained in:
Chao Xu 2018-12-19 13:32:56 -08:00 committed by Kubernetes Publisher
parent 25de10860f
commit 9e44a08cb1
6 changed files with 17 additions and 15 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package discovery package disk
import ( import (
"errors" "errors"
@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/version" "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
) )
@ -38,7 +39,7 @@ import (
// CachedDiscoveryClient implements the functions that discovery server-supported API groups, // CachedDiscoveryClient implements the functions that discovery server-supported API groups,
// versions and resources. // versions and resources.
type CachedDiscoveryClient struct { type CachedDiscoveryClient struct {
delegate DiscoveryInterface delegate discovery.DiscoveryInterface
// cacheDirectory is the directory where discovery docs are held. It must be unique per host:port combination to work well. // cacheDirectory is the directory where discovery docs are held. It must be unique per host:port combination to work well.
cacheDirectory string cacheDirectory string
@ -57,7 +58,7 @@ type CachedDiscoveryClient struct {
fresh bool fresh bool
} }
var _ CachedDiscoveryInterface = &CachedDiscoveryClient{} var _ discovery.CachedDiscoveryInterface = &CachedDiscoveryClient{}
// ServerResourcesForGroupVersion returns the supported resources for a group and version. // ServerResourcesForGroupVersion returns the supported resources for a group and version.
func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) { func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) {
@ -92,13 +93,13 @@ func (d *CachedDiscoveryClient) ServerResourcesForGroupVersion(groupVersion stri
// ServerResources returns the supported resources for all groups and versions. // ServerResources returns the supported resources for all groups and versions.
// Deprecated: use ServerGroupsAndResources instead. // Deprecated: use ServerGroupsAndResources instead.
func (d *CachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) { func (d *CachedDiscoveryClient) ServerResources() ([]*metav1.APIResourceList, error) {
_, rs, err := ServerGroupsAndResources(d) _, rs, err := discovery.ServerGroupsAndResources(d)
return rs, err return rs, err
} }
// ServerGroupsAndResources returns the supported groups and resources for all groups and versions. // ServerGroupsAndResources returns the supported groups and resources for all groups and versions.
func (d *CachedDiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) { func (d *CachedDiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) {
return ServerGroupsAndResources(d) return discovery.ServerGroupsAndResources(d)
} }
// ServerGroups returns the supported groups, with information like supported versions and the // ServerGroups returns the supported groups, with information like supported versions and the
@ -220,13 +221,13 @@ func (d *CachedDiscoveryClient) RESTClient() restclient.Interface {
// ServerPreferredResources returns the supported resources with the version preferred by the // ServerPreferredResources returns the supported resources with the version preferred by the
// server. // server.
func (d *CachedDiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) { func (d *CachedDiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error) {
return ServerPreferredResources(d) return discovery.ServerPreferredResources(d)
} }
// ServerPreferredNamespacedResources returns the supported namespaced resources with the // ServerPreferredNamespacedResources returns the supported namespaced resources with the
// version preferred by the server. // version preferred by the server.
func (d *CachedDiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error) { func (d *CachedDiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error) {
return ServerPreferredNamespacedResources(d) return discovery.ServerPreferredNamespacedResources(d)
} }
// ServerVersion retrieves and parses the server's version (git version). // ServerVersion retrieves and parses the server's version (git version).
@ -279,7 +280,7 @@ func NewCachedDiscoveryClientForConfig(config *restclient.Config, discoveryCache
}) })
} }
discoveryClient, err := NewDiscoveryClientForConfig(config) discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -288,7 +289,7 @@ func NewCachedDiscoveryClientForConfig(config *restclient.Config, discoveryCache
} }
// NewCachedDiscoveryClient creates a new DiscoveryClient. cacheDirectory is the directory where discovery docs are held. It must be unique per host:port combination to work well. // NewCachedDiscoveryClient creates a new DiscoveryClient. cacheDirectory is the directory where discovery docs are held. It must be unique per host:port combination to work well.
func newCachedDiscoveryClient(delegate DiscoveryInterface, cacheDirectory string, ttl time.Duration) *CachedDiscoveryClient { func newCachedDiscoveryClient(delegate discovery.DiscoveryInterface, cacheDirectory string, ttl time.Duration) *CachedDiscoveryClient {
return &CachedDiscoveryClient{ return &CachedDiscoveryClient{
delegate: delegate, delegate: delegate,
cacheDirectory: cacheDirectory, cacheDirectory: cacheDirectory,

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package discovery package disk
import ( import (
"io/ioutil" "io/ioutil"
@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/version" "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
) )
@ -104,7 +105,7 @@ type fakeDiscoveryClient struct {
serverResourcesHandler func() ([]*metav1.APIResourceList, error) serverResourcesHandler func() ([]*metav1.APIResourceList, error)
} }
var _ DiscoveryInterface = &fakeDiscoveryClient{} var _ discovery.DiscoveryInterface = &fakeDiscoveryClient{}
func (c *fakeDiscoveryClient) RESTClient() restclient.Interface { func (c *fakeDiscoveryClient) RESTClient() restclient.Interface {
return &fake.RESTClient{} return &fake.RESTClient{}

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package discovery package disk
import ( import (
"net/http" "net/http"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package discovery package disk
import ( import (
"bytes" "bytes"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package cached package memory
import ( import (
"errors" "errors"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package cached package memory
import ( import (
"errors" "errors"