client

package
v1.26.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicHTTPClient

func BasicHTTPClient(t time.Duration) *http.Client

BasicHTTPClient returns http.Client configured with timeout

func InsecureHTTPClient

func InsecureHTTPClient(t time.Duration) *http.Client

InsecureHTTPClient returns http.Client configured with timeout and InsecureSkipVerify flag enabled

Types

type Composer

type Composer func(source interface{}, cacher *DiscoveryCacher, timeout time.Duration) (HTTPClient, error)

Composer implementors must convert the data from the cached entities to a Client.

type Decomposer

type Decomposer func(source HTTPClient) (interface{}, error)

Decomposer implementors must convert a HTTPClient into a data structure that can be Stored in the cache.

type Discoverer

type Discoverer interface {
	Discover(timeout time.Duration) (HTTPClient, error)
}

Discoverer allows discovering the endpoints from different services in the Kubernetes ecosystem.

type DiscoveryCacher

type DiscoveryCacher struct {
	// CachedDataPtr must be a pointer to an object where the data will be unmarshalled to
	CachedDataPtr interface{}
	// StorageKey is the key for the Storage Cache
	StorageKey string
	// Discoverer points to the wrapped Discovered used to resolve endpoints when they are not found in the cache
	Discoverer Discoverer
	// Storage for cached data
	Storage   storage.Storage
	TTL       time.Duration
	Logger    *logrus.Logger
	Compose   Composer
	Decompose Decomposer
}

DiscoveryCacher implements the Discoverer API to read endpoints from a cache storage. It also wraps another Discoverer and uses it to discover endpoints when the data is not found in the cache. This type is not thread-safe.

func (*DiscoveryCacher) Discover

func (d *DiscoveryCacher) Discover(timeout time.Duration) (HTTPClient, error)

Discover tries to retrieve a HTTPClient from the cache, and otherwise engage the discovery process from the wrapped Discoverer

type HTTPClient

type HTTPClient interface {
	Do(method, path string) (*http.Response, error)
	NodeIP() string
}

HTTPClient allows to connect to the discovered Kubernetes services

func WrappedClient

func WrappedClient(caClient HTTPClient) HTTPClient

WrappedClient is only aimed for testing. It allows extracting the wrapped client of a given cacheAwareClient.

type Kubernetes

type Kubernetes interface {
	// FindNode returns a Node reference containing the pod named as the argument, if any
	FindNode(name string) (*v1.Node, error)
	// FindPodsByLabel returns a PodList reference containing the pods matching the provided name/value label pair
	FindPodsByLabel(name, value string) (*v1.PodList, error)
	// FindPodByName returns a PodList reference that should contain the pod whose name matches with the name argument
	FindPodByName(name string) (*v1.PodList, error)
	// FindPodsByHostname returns a Podlist reference containing the pod or pods whose hostname matches the argument
	FindPodsByHostname(hostname string) (*v1.PodList, error)
	// FindServicesByLabel returns a ServiceList containing the services matching the provided name/value label pair
	// name/value pairs
	FindServicesByLabel(name, value string) (*v1.ServiceList, error)
	// ListServices returns a ServiceList containing all the services.
	ListServices() (*v1.ServiceList, error)
	// Config returns a config of API client
	Config() *rest.Config
	// SecureHTTPClient returns http.Client configured with timeout and CA Cert
	SecureHTTPClient(time.Duration) (*http.Client, error)
	// FindSecret returns the secret with the given name, if any
	FindSecret(name, namespace string) (*v1.Secret, error)
	// ServerVersion returns the kubernetes server version.
	ServerVersion() (*version.Info, error)
}

Kubernetes provides an interface to common Kubernetes API operations

func NewKubernetes

func NewKubernetes(tryLocalKubeConfig bool) (Kubernetes, error)

NewKubernetes instantiates a Kubernetes API client if tryLocalKubeConfig is true, this will try to load your kubeconfig from ~/.kube/config

type MockDiscoveredHTTPClient

type MockDiscoveredHTTPClient struct {
	mock.Mock
}

MockDiscoveredHTTPClient is a mock implementation of the HTTPClient interface

func (*MockDiscoveredHTTPClient) Do

func (m *MockDiscoveredHTTPClient) Do(method, path string) (*http.Response, error)

Do provides a mock implementation for HTTPClient interface

func (*MockDiscoveredHTTPClient) NodeIP

func (m *MockDiscoveredHTTPClient) NodeIP() string

NodeIP provides a mock implementation for HTTPClient interface

type MockDiscoverer

type MockDiscoverer struct {
	mock.Mock
}

MockDiscoverer is a mock implementation of the Discoverer interface

func (*MockDiscoverer) Discover

func (m *MockDiscoverer) Discover(timeout time.Duration) (HTTPClient, error)

Discover provides a mock implementation for Discoverer interface

type MockedKubernetes

type MockedKubernetes struct {
	mock.Mock
}

MockedKubernetes is a Mock for the Kubernetes interface to be used only in tests

func (*MockedKubernetes) Config

func (m *MockedKubernetes) Config() *rest.Config

Config mocks Kubernetes Config

func (*MockedKubernetes) FindNode

func (m *MockedKubernetes) FindNode(name string) (*v1.Node, error)

FindNode mocks Kubernetes FindNode

func (*MockedKubernetes) FindPodByName

func (m *MockedKubernetes) FindPodByName(name string) (*v1.PodList, error)

FindPodByName mocks Kubernetes FindPodByName

func (*MockedKubernetes) FindPodsByHostname

func (m *MockedKubernetes) FindPodsByHostname(hostname string) (*v1.PodList, error)

FindPodsByHostname mocks Kubernetes FindPodsByHostname

func (*MockedKubernetes) FindPodsByLabel

func (m *MockedKubernetes) FindPodsByLabel(name, value string) (*v1.PodList, error)

FindPodsByLabel mocks Kubernetes FindPodsByLabel

func (*MockedKubernetes) FindSecret

func (m *MockedKubernetes) FindSecret(name, namespace string) (*v1.Secret, error)

FindSecret mocks Kubernetes FindSecret

func (*MockedKubernetes) FindServicesByLabel

func (m *MockedKubernetes) FindServicesByLabel(name, value string) (*v1.ServiceList, error)

FindServicesByLabel mocks Kubernetes FindServicesByLabel

func (*MockedKubernetes) ListServices

func (m *MockedKubernetes) ListServices() (*v1.ServiceList, error)

ListServices mocks Kubernetes ListServices

func (*MockedKubernetes) SecureHTTPClient

func (m *MockedKubernetes) SecureHTTPClient(timeout time.Duration) (*http.Client, error)

SecureHTTPClient mocks Kubernetes SecureHTTPClient

func (*MockedKubernetes) ServerVersion

func (m *MockedKubernetes) ServerVersion() (*version.Info, error)

ServerVersion mocks Kubernetes ServerVersion

type MultiComposer

type MultiComposer func(source interface{}, cacher *MultiDiscoveryCacher, timeout time.Duration) ([]HTTPClient, error)

MultiComposer implementors must convert the cached data to a []HTTPClient.

type MultiDecomposer

type MultiDecomposer func(sources []HTTPClient) (interface{}, error)

MultiDecomposer implementors must convert a HTTPClient into a data structure that can be Stored in the cache.

type MultiDiscoverer

type MultiDiscoverer interface {
	Discover(timeout time.Duration) ([]HTTPClient, error)
}

MultiDiscoverer allows for discovery processes that return more than a single HTTP client. For example, in one node we might query more than one KSM instance, so we need two clients.

type MultiDiscoveryCacher

type MultiDiscoveryCacher struct {
	Discoverer    MultiDiscoverer
	CachedDataPtr interface{}
	StorageKey    string
	Storage       storage.Storage
	TTL           time.Duration
	Logger        *logrus.Logger
	Compose       MultiComposer
	Decompose     MultiDecomposer
}

MultiDiscoveryCacher is a wrapper for MultiDiscoverer implementations that can cache the results into some storages. It implements the MultiDiscoverer interface. This type is not threadsafe.

func (*MultiDiscoveryCacher) Discover

func (d *MultiDiscoveryCacher) Discover(timeout time.Duration) ([]HTTPClient, error)

Discover runs the underlying discovery and caches its result. If there is a non-expired discover cache in the storage, it will be loaded. If the cache is not present or has expired, it will be written. If the cache read fails, the underlying discovery will still run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL