Merge pull request #324 from paivagustavo/cached_discovery_client

use cached discovery client in more places.
mine
Fernand Galiana 2019-10-04 10:05:48 -06:00 committed by GitHub
commit 7a613255d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 241 additions and 52 deletions

View File

@ -8,6 +8,7 @@ import (
pegomock "github.com/petergtz/pegomock"
v1 "k8s.io/api/core/v1"
version "k8s.io/apimachinery/pkg/version"
disk "k8s.io/client-go/discovery/cached/disk"
dynamic "k8s.io/client-go/dynamic"
kubernetes "k8s.io/client-go/kubernetes"
rest "k8s.io/client-go/rest"
@ -31,6 +32,25 @@ func NewMockConnection(options ...pegomock.Option) *MockConnection {
func (mock *MockConnection) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockConnection) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockConnection) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
}
params := []pegomock.Param{}
result := pegomock.GetGenericMockFrom(mock).Invoke("CachedDiscovery", params, []reflect.Type{reflect.TypeOf((**disk.CachedDiscoveryClient)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
var ret0 *disk.CachedDiscoveryClient
var ret1 error
if len(result) != 0 {
if result[0] != nil {
ret0 = result[0].(*disk.CachedDiscoveryClient)
}
if result[1] != nil {
ret1 = result[1].(error)
}
}
return ret0, ret1
}
func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) (bool, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
@ -382,6 +402,23 @@ type VerifierMockConnection struct {
timeout time.Duration
}
func (verifier *VerifierMockConnection) CachedDiscovery() *MockConnection_CachedDiscovery_OngoingVerification {
params := []pegomock.Param{}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CachedDiscovery", params, verifier.timeout)
return &MockConnection_CachedDiscovery_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
}
type MockConnection_CachedDiscovery_OngoingVerification struct {
mock *MockConnection
methodInvocations []pegomock.MethodInvocation
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetCapturedArguments() {
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetAllCapturedArguments() {
}
func (verifier *VerifierMockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) *MockConnection_CanIAccess_OngoingVerification {
params := []pegomock.Param{_param0, _param1, _param2}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout)

View File

@ -2,8 +2,12 @@ package k8s
import (
"fmt"
"path/filepath"
"strings"
"sync"
"time"
"k8s.io/client-go/discovery/cached/disk"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
@ -44,6 +48,7 @@ type (
DialOrDie() kubernetes.Interface
SwitchContextOrDie(ctx string)
NSDialOrDie() dynamic.NamespaceableResourceInterface
CachedDiscovery() (*disk.CachedDiscoveryClient, error)
RestConfigOrDie() *restclient.Config
MXDial() (*versioned.Clientset, error)
DynDialOrDie() dynamic.Interface
@ -72,6 +77,7 @@ type (
APIClient struct {
k8sClient
cachedDiscovery *disk.CachedDiscoveryClient
config *Config
useMetricServer bool
log zerolog.Logger
@ -149,7 +155,12 @@ func (a *APIClient) CurrentNamespaceName() (string, error) {
// ServerVersion returns the current server version info.
func (a *APIClient) ServerVersion() (*version.Info, error) {
return a.DialOrDie().Discovery().ServerVersion()
discovery, err := a.CachedDiscovery()
if err != nil {
return nil, err
}
return discovery.ServerVersion()
}
// FetchNodes returns all available nodes.
@ -181,7 +192,12 @@ func (a *APIClient) NodePods(node string) (*v1.PodList, error) {
// IsNamespaced check on server if given resource is namespaced
func (a *APIClient) IsNamespaced(res string) bool {
list, _ := a.DialOrDie().Discovery().ServerPreferredResources()
discovery, err := a.CachedDiscovery()
if err != nil {
return false
}
list, _ := discovery.ServerPreferredResources()
for _, l := range list {
for _, r := range l.APIResources {
if r.Name == res {
@ -194,7 +210,12 @@ func (a *APIClient) IsNamespaced(res string) bool {
// SupportsResource checks for resource supported version against the server.
func (a *APIClient) SupportsResource(group string) bool {
list, err := a.DialOrDie().Discovery().ServerPreferredResources()
discovery, err := a.CachedDiscovery()
if err != nil {
return false
}
list, err := discovery.ServerPreferredResources()
if err != nil {
log.Error().Err(err).Msg("Unable to dial api server")
return false
@ -240,6 +261,23 @@ func (a *APIClient) RestConfigOrDie() *restclient.Config {
return cfg
}
func (a *APIClient) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
a.mx.Lock()
defer a.mx.Unlock()
if a.cachedDiscovery != nil {
return a.cachedDiscovery, nil
}
rc := a.RestConfigOrDie()
httpCacheDir := filepath.Join(mustHomeDir(), ".kube", "http-cache")
discCacheDir := filepath.Join(mustHomeDir(), ".kube", "cache", "discovery", toHostDir(rc.Host))
var err error
a.cachedDiscovery, err = disk.NewCachedDiscoveryClientForConfig(rc, discCacheDir, httpCacheDir, 10*time.Minute)
return a.cachedDiscovery, err
}
// DynDialOrDie returns a handle to a dynamic interface.
func (a *APIClient) DynDialOrDie() dynamic.Interface {
if a.dClient != nil {
@ -310,7 +348,12 @@ func (a *APIClient) reset() {
}
func (a *APIClient) supportsMxServer() bool {
apiGroups, err := a.DialOrDie().Discovery().ServerGroups()
discovery, err := a.CachedDiscovery()
if err != nil {
return false
}
apiGroups, err := discovery.ServerGroups()
if err != nil {
return false
}
@ -341,7 +384,12 @@ func checkMetricsVersion(grp metav1.APIGroup) bool {
// SupportsRes checks latest supported version.
func (a *APIClient) SupportsRes(group string, versions []string) (string, bool, error) {
apiGroups, err := a.DialOrDie().Discovery().ServerGroups()
discovery, err := a.CachedDiscovery()
if err != nil {
return "", false, err
}
apiGroups, err := discovery.ServerGroups()
if err != nil {
return "", false, err
}

View File

@ -3,14 +3,11 @@ package k8s
import (
"fmt"
"os/user"
"path/filepath"
"regexp"
"strings"
"time"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery/cached/disk"
"k8s.io/client-go/restmapper"
)
@ -27,12 +24,7 @@ type RestMapper struct {
// ToRESTMapper map resources to kind, and map kind and version to interfaces for manipulating K8s objects.
func (r *RestMapper) ToRESTMapper() (meta.RESTMapper, error) {
rc := r.RestConfigOrDie()
httpCacheDir := filepath.Join(mustHomeDir(), ".kube", "http-cache")
discCacheDir := filepath.Join(mustHomeDir(), ".kube", "cache", "discovery", toHostDir(rc.Host))
disc, err := disk.NewCachedDiscoveryClientForConfig(rc, discCacheDir, httpCacheDir, 10*time.Minute)
disc, err := r.CachedDiscovery()
if err != nil {
return nil, err
}

View File

@ -8,6 +8,7 @@ import (
pegomock "github.com/petergtz/pegomock"
v1 "k8s.io/api/core/v1"
version "k8s.io/apimachinery/pkg/version"
disk "k8s.io/client-go/discovery/cached/disk"
dynamic "k8s.io/client-go/dynamic"
kubernetes "k8s.io/client-go/kubernetes"
rest "k8s.io/client-go/rest"
@ -31,6 +32,25 @@ func NewMockClusterMeta(options ...pegomock.Option) *MockClusterMeta {
func (mock *MockClusterMeta) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockClusterMeta) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockClusterMeta) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockClusterMeta().")
}
params := []pegomock.Param{}
result := pegomock.GetGenericMockFrom(mock).Invoke("CachedDiscovery", params, []reflect.Type{reflect.TypeOf((**disk.CachedDiscoveryClient)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
var ret0 *disk.CachedDiscoveryClient
var ret1 error
if len(result) != 0 {
if result[0] != nil {
ret0 = result[0].(*disk.CachedDiscoveryClient)
}
if result[1] != nil {
ret1 = result[1].(error)
}
}
return ret0, ret1
}
func (mock *MockClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 []string) (bool, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockClusterMeta().")
@ -465,6 +485,23 @@ type VerifierMockClusterMeta struct {
timeout time.Duration
}
func (verifier *VerifierMockClusterMeta) CachedDiscovery() *MockClusterMeta_CachedDiscovery_OngoingVerification {
params := []pegomock.Param{}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CachedDiscovery", params, verifier.timeout)
return &MockClusterMeta_CachedDiscovery_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
}
type MockClusterMeta_CachedDiscovery_OngoingVerification struct {
mock *MockClusterMeta
methodInvocations []pegomock.MethodInvocation
}
func (c *MockClusterMeta_CachedDiscovery_OngoingVerification) GetCapturedArguments() {
}
func (c *MockClusterMeta_CachedDiscovery_OngoingVerification) GetAllCapturedArguments() {
}
func (verifier *VerifierMockClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 []string) *MockClusterMeta_CanIAccess_OngoingVerification {
params := []pegomock.Param{_param0, _param1, _param2}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout)
@ -484,15 +521,15 @@ func (c *MockClusterMeta_CanIAccess_OngoingVerification) GetCapturedArguments()
func (c *MockClusterMeta_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 [][]string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
_param1 = make([]string, len(params[1]))
_param1 = make([]string, len(c.methodInvocations))
for u, param := range params[1] {
_param1[u] = param.(string)
}
_param2 = make([][]string, len(params[2]))
_param2 = make([][]string, len(c.methodInvocations))
for u, param := range params[2] {
_param2[u] = param.([]string)
}
@ -536,7 +573,7 @@ func (c *MockClusterMeta_CheckNSAccess_OngoingVerification) GetCapturedArguments
func (c *MockClusterMeta_CheckNSAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -716,7 +753,7 @@ func (c *MockClusterMeta_IsNamespaced_OngoingVerification) GetCapturedArguments(
func (c *MockClusterMeta_IsNamespaced_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -777,7 +814,7 @@ func (c *MockClusterMeta_NodePods_OngoingVerification) GetCapturedArguments() st
func (c *MockClusterMeta_NodePods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -838,11 +875,11 @@ func (c *MockClusterMeta_SupportsRes_OngoingVerification) GetCapturedArguments()
func (c *MockClusterMeta_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
_param1 = make([][]string, len(params[1]))
_param1 = make([][]string, len(c.methodInvocations))
for u, param := range params[1] {
_param1[u] = param.([]string)
}
@ -869,7 +906,7 @@ func (c *MockClusterMeta_SupportsResource_OngoingVerification) GetCapturedArgume
func (c *MockClusterMeta_SupportsResource_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -896,7 +933,7 @@ func (c *MockClusterMeta_SwitchContextOrDie_OngoingVerification) GetCapturedArgu
func (c *MockClusterMeta_SwitchContextOrDie_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}

View File

@ -8,6 +8,7 @@ import (
pegomock "github.com/petergtz/pegomock"
v1 "k8s.io/api/core/v1"
version "k8s.io/apimachinery/pkg/version"
disk "k8s.io/client-go/discovery/cached/disk"
dynamic "k8s.io/client-go/dynamic"
kubernetes "k8s.io/client-go/kubernetes"
rest "k8s.io/client-go/rest"
@ -31,6 +32,25 @@ func NewMockConnection(options ...pegomock.Option) *MockConnection {
func (mock *MockConnection) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockConnection) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockConnection) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
}
params := []pegomock.Param{}
result := pegomock.GetGenericMockFrom(mock).Invoke("CachedDiscovery", params, []reflect.Type{reflect.TypeOf((**disk.CachedDiscoveryClient)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
var ret0 *disk.CachedDiscoveryClient
var ret1 error
if len(result) != 0 {
if result[0] != nil {
ret0 = result[0].(*disk.CachedDiscoveryClient)
}
if result[1] != nil {
ret1 = result[1].(error)
}
}
return ret0, ret1
}
func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) (bool, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
@ -382,6 +402,23 @@ type VerifierMockConnection struct {
timeout time.Duration
}
func (verifier *VerifierMockConnection) CachedDiscovery() *MockConnection_CachedDiscovery_OngoingVerification {
params := []pegomock.Param{}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CachedDiscovery", params, verifier.timeout)
return &MockConnection_CachedDiscovery_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
}
type MockConnection_CachedDiscovery_OngoingVerification struct {
mock *MockConnection
methodInvocations []pegomock.MethodInvocation
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetCapturedArguments() {
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetAllCapturedArguments() {
}
func (verifier *VerifierMockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) *MockConnection_CanIAccess_OngoingVerification {
params := []pegomock.Param{_param0, _param1, _param2}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout)
@ -401,15 +438,15 @@ func (c *MockConnection_CanIAccess_OngoingVerification) GetCapturedArguments() (
func (c *MockConnection_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 [][]string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
_param1 = make([]string, len(params[1]))
_param1 = make([]string, len(c.methodInvocations))
for u, param := range params[1] {
_param1[u] = param.(string)
}
_param2 = make([][]string, len(params[2]))
_param2 = make([][]string, len(c.methodInvocations))
for u, param := range params[2] {
_param2[u] = param.([]string)
}
@ -453,7 +490,7 @@ func (c *MockConnection_CheckNSAccess_OngoingVerification) GetCapturedArguments(
func (c *MockConnection_CheckNSAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -582,7 +619,7 @@ func (c *MockConnection_IsNamespaced_OngoingVerification) GetCapturedArguments()
func (c *MockConnection_IsNamespaced_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -643,7 +680,7 @@ func (c *MockConnection_NodePods_OngoingVerification) GetCapturedArguments() str
func (c *MockConnection_NodePods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -704,11 +741,11 @@ func (c *MockConnection_SupportsRes_OngoingVerification) GetCapturedArguments()
func (c *MockConnection_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
_param1 = make([][]string, len(params[1]))
_param1 = make([][]string, len(c.methodInvocations))
for u, param := range params[1] {
_param1[u] = param.([]string)
}
@ -735,7 +772,7 @@ func (c *MockConnection_SupportsResource_OngoingVerification) GetCapturedArgumen
func (c *MockConnection_SupportsResource_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}
@ -762,7 +799,7 @@ func (c *MockConnection_SwitchContextOrDie_OngoingVerification) GetCapturedArgum
func (c *MockConnection_SwitchContextOrDie_OngoingVerification) GetAllCapturedArguments() (_param0 []string) {
params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
if len(params) > 0 {
_param0 = make([]string, len(params[0]))
_param0 = make([]string, len(c.methodInvocations))
for u, param := range params[0] {
_param0[u] = param.(string)
}

View File

@ -33,13 +33,6 @@ type (
viewers map[string]viewer
)
func aliasCmds(c k8s.Connection, vv viewers) {
resourceViews(c, vv)
if c != nil {
allCRDs(c, vv)
}
}
func listFunc(l resource.List) viewFn {
return func(title, gvr string, app *appView, list resource.List) resourceViewer {
return newResourceView(title, gvr, app, l)
@ -127,7 +120,13 @@ func load(c k8s.Connection, vv viewers) {
if err := aliases.Load(); err != nil {
log.Error().Err(err).Msg("No custom aliases defined in config")
}
rr, _ := c.DialOrDie().Discovery().ServerPreferredResources()
discovery, err := c.CachedDiscovery()
if err != nil {
log.Error().Err(err).Msgf("Error to get discovery client")
return
}
rr, _ := discovery.ServerPreferredResources()
for _, r := range rr {
for _, res := range r.APIResources {
gvr := k8s.ToGVR(r.GroupVersion, res.Name)

View File

@ -4,31 +4,53 @@
package watch
import (
"github.com/derailed/k9s/internal/k8s"
"github.com/petergtz/pegomock"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/discovery/cached/disk"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/metrics/pkg/client/clientset/versioned"
"reflect"
"time"
k8s "github.com/derailed/k9s/internal/k8s"
pegomock "github.com/petergtz/pegomock"
v1 "k8s.io/api/core/v1"
version "k8s.io/apimachinery/pkg/version"
dynamic "k8s.io/client-go/dynamic"
kubernetes "k8s.io/client-go/kubernetes"
rest "k8s.io/client-go/rest"
versioned "k8s.io/metrics/pkg/client/clientset/versioned"
)
type MockConnection struct {
fail func(message string, callerSkip ...int)
}
func NewMockConnection() *MockConnection {
func NewMockConnection(options ...pegomock.Option) *MockConnection {
mock := &MockConnection{}
for _, option := range options {
option.Apply(mock)
}
return mock
}
func (mock *MockConnection) SetFailHandler(fh pegomock.FailHandler) { mock.fail = fh }
func (mock *MockConnection) FailHandler() pegomock.FailHandler { return mock.fail }
func (mock *MockConnection) CachedDiscovery() (*disk.CachedDiscoveryClient, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
}
params := []pegomock.Param{}
result := pegomock.GetGenericMockFrom(mock).Invoke("CachedDiscovery", params, []reflect.Type{reflect.TypeOf((**disk.CachedDiscoveryClient)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()})
var ret0 *disk.CachedDiscoveryClient
var ret1 error
if len(result) != 0 {
if result[0] != nil {
ret0 = result[0].(*disk.CachedDiscoveryClient)
}
if result[1] != nil {
ret1 = result[1].(error)
}
}
return ret0, ret1
}
func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) (bool, error) {
if mock == nil {
panic("mock must not be nil. Use myMock := NewMockConnection().")
@ -380,6 +402,23 @@ type VerifierMockConnection struct {
timeout time.Duration
}
func (verifier *VerifierMockConnection) CachedDiscovery() *MockConnection_CachedDiscovery_OngoingVerification {
params := []pegomock.Param{}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CachedDiscovery", params, verifier.timeout)
return &MockConnection_CachedDiscovery_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
}
type MockConnection_CachedDiscovery_OngoingVerification struct {
mock *MockConnection
methodInvocations []pegomock.MethodInvocation
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetCapturedArguments() {
}
func (c *MockConnection_CachedDiscovery_OngoingVerification) GetAllCapturedArguments() {
}
func (verifier *VerifierMockConnection) CanIAccess(_param0 string, _param1 string, _param2 []string) *MockConnection_CanIAccess_OngoingVerification {
params := []pegomock.Param{_param0, _param1, _param2}
methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout)