k8s

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteScaledObject

func DeleteScaledObject(ctx context.Context, name string, namespace string, cl client.Client) error

DeleteScaledObject deletes a scaled object with the given name

func EndpointsForService added in v0.2.0

func EndpointsForService(
	ctx context.Context,
	ns,
	serviceName,
	servicePort string,
	endpointsFn GetEndpointsFunc,
) ([]*url.URL, error)

func FakeEndpointsForURL added in v0.2.0

func FakeEndpointsForURL(
	u *url.URL,
	namespace,
	name string,
	num int,
) (*v1.Endpoints, error)

FakeEndpointsForURL creates and returns a new *v1.Endpoints with a single v1.EndpointSubset in it, which has num v1.EndpointAddresses in it. Each of those EndpointAddresses has a Hostname and IP both equal to u.Hostname()

func FakeEndpointsForURLs added in v0.2.0

func FakeEndpointsForURLs(
	urls []*url.URL,
	namespace,
	name string,
) (*v1.Endpoints, error)

FakeEndpointsForURLs creates and returns a new *v1.Endpoints with a single v1.EndpointSubset in it that has each url in the urls parameter in it.

func GetConfigMap added in v0.2.0

func GetConfigMap(
	ctx context.Context,
	cl client.Client,
	namespace string,
	name string,
) (*corev1.ConfigMap, error)

func Int32P added in v0.1.0

func Int32P(i int32) *int32

Int32P converts an int32 into an *int32. It's a convenience function for various values in Kubernetes API types

func Labels

func Labels(name string) map[string]string

func NewClientset

func NewClientset() (*kubernetes.Clientset, dynamic.Interface, error)

NewClientset gets a new Kubernetes clientset, or calls log.Fatal if it couldn't

func NewEmptyScaledObject added in v0.4.0

func NewEmptyScaledObject() *unstructured.Unstructured

func NewScaledObject

func NewScaledObject(
	namespace,
	name,
	deploymentName,
	scalerAddress,
	host string,
	minReplicas,
	maxReplicas int32,
	cooldownPeriod int32,
) (*unstructured.Unstructured, error)

NewScaledObject creates a new ScaledObject in memory

func ObjKey added in v0.2.0

func ObjKey(ns, name string) client.ObjectKey

ObjKey creates a new client.ObjectKey with the given name and namespace

func PatchConfigMap added in v0.2.0

func PatchConfigMap(
	ctx context.Context,
	logger logr.Logger,
	cl client.Writer,
	originalConfigMap *corev1.ConfigMap,
	patchConfigMap *corev1.ConfigMap,
) (*corev1.ConfigMap, error)

Types

type ConfigMapGetter added in v0.2.0

type ConfigMapGetter interface {
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*corev1.ConfigMap, error)
}

ConfigMapGetter is a pared down version of a ConfigMapInterface (found here: https://pkg.go.dev/k8s.io/client-go@v0.21.3/kubernetes/typed/core/v1#ConfigMapInterface).

Pass this whenever possible to functions that only need to get individual ConfigMaps from Kubernetes, and nothing else.

type ConfigMapGetterWatcher added in v0.2.0

type ConfigMapGetterWatcher interface {
	ConfigMapGetter
	ConfigMapWatcher
}

ConfigMapGetterWatcher is a pared down version of a ConfigMapInterface (found here: https://pkg.go.dev/k8s.io/client-go@v0.21.3/kubernetes/typed/core/v1#ConfigMapInterface).

Pass this whenever possible to functions that only need to watch for ConfigMaps from Kubernetes, and nothing else.

type ConfigMapWatcher added in v0.2.0

type ConfigMapWatcher interface {
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

ConfigMapWatcher is a pared down version of a ConfigMapInterface (found here: https://pkg.go.dev/k8s.io/client-go@v0.21.3/kubernetes/typed/core/v1#ConfigMapInterface).

Pass this whenever possible to functions that only need to watch for ConfigMaps from Kubernetes, and nothing else.

type DeploymentCache added in v0.1.0

type DeploymentCache interface {
	json.Marshaler
	// Get gets the a deployment with the given name
	// in the given namespace from the cache.
	//
	// If the deployment doesn't exist in the cache, it
	// will be requested from the backing store (most commonly
	// the Kubernetes API server)
	Get(namespace, name string) (appsv1.Deployment, error)
	// Watch opens a watch stream for the deployment with
	// the given name in the given namespace from the cache.
	//
	// If the deployment doesn't exist in the cache, it
	// will be requested from the backing store (most commonly
	// the Kubernetes API server)
	Watch(namespace, name string) (watch.Interface, error)
}

DeploymentCache is a simple cache of deployments. It allows callers to quickly get a given deployment in a given namespace, or watch for changes to a specific deployment, all without incurring the cost of issuing a network request to the Kubernetes API

type FakeConfigMapGetter added in v0.2.0

type FakeConfigMapGetter struct {
	ConfigMap *corev1.ConfigMap
	Err       error
}

func (FakeConfigMapGetter) Get added in v0.2.0

type FakeDeploymentCache added in v0.2.0

type FakeDeploymentCache struct {
	json.Marshaler
	// contains filtered or unexported fields
}

FakeDeploymentCache is a fake implementation of DeploymentCache, suitable for testing interceptor-level logic, without requiring any real Kubernetes client or API interaction

func NewFakeDeploymentCache added in v0.2.0

func NewFakeDeploymentCache() *FakeDeploymentCache

func (*FakeDeploymentCache) AddDeployment added in v0.3.0

func (f *FakeDeploymentCache) AddDeployment(depl appsv1.Deployment)

AddDeployment adds a deployment to the current in-memory cache without sending an event to any of the watchers

func (*FakeDeploymentCache) CurrentDeployments added in v0.3.0

func (f *FakeDeploymentCache) CurrentDeployments() map[string]appsv1.Deployment

CurrentDeployments returns a map of all the current deployments.

The key in the map is a combination of the namespace and name of the corresponding deployment, but the format of the key is not guaranteed

func (*FakeDeploymentCache) Get added in v0.2.0

func (*FakeDeploymentCache) GetWatcher added in v0.3.0

func (f *FakeDeploymentCache) GetWatcher(ns, name string) *watch.RaceFreeFakeWatcher

GetWatcher gets the watcher for the given namespace and name, or nil if there wasn't one registered.

Watchers are registered by the .Watch() method

func (*FakeDeploymentCache) MarshalJSON added in v0.2.0

func (f *FakeDeploymentCache) MarshalJSON() ([]byte, error)

func (*FakeDeploymentCache) Set added in v0.2.0

func (f *FakeDeploymentCache) Set(ns, name string, deployment appsv1.Deployment)

func (*FakeDeploymentCache) SetReplicas added in v0.2.0

func (f *FakeDeploymentCache) SetReplicas(ns, name string, num int32) error

func (*FakeDeploymentCache) SetWatcher added in v0.2.0

func (f *FakeDeploymentCache) SetWatcher(ns, name string) *watch.RaceFreeFakeWatcher

SetWatcher creates a new race-free fake watcher and sets it into the internal watchers map. After this call, a call to Watch() with the same namespace and name values will return a valid watcher

func (*FakeDeploymentCache) Watch added in v0.2.0

func (f *FakeDeploymentCache) Watch(ns, name string) (watch.Interface, error)

type FakeRuntimeClient added in v0.2.0

FakeRuntimeClient is a fake implementation of (k8s.io/controller-runtime/pkg/client).Client

func NewFakeRuntimeClient added in v0.2.0

func NewFakeRuntimeClient() *FakeRuntimeClient

func (*FakeRuntimeClient) SubResource added in v0.4.0

func (*FakeRuntimeClient) SubResource(subResource string) client.SubResourceClient

SubResource implements client.Client

type FakeRuntimeClientReader added in v0.2.0

type FakeRuntimeClientReader struct {
	GetCalls  []GetCall
	GetFunc   func() client.Object
	ListCalls []client.ObjectList
	ListFunc  func() client.ObjectList
}

FakeRuntimeClientReader is a fake implementation of (k8s.io/controller-runtime/pkg/client).ClientReader

func (*FakeRuntimeClientReader) Get added in v0.2.0

func (*FakeRuntimeClientReader) List added in v0.2.0

func (*FakeRuntimeClientReader) RESTMapper added in v0.2.0

func (f *FakeRuntimeClientReader) RESTMapper() meta.RESTMapper

RESTMapper implements the controller-runtime Client interface.

NOTE: this method is not implemented and always returns nil.

type FakeRuntimeClientWriter added in v0.2.0

type FakeRuntimeClientWriter struct {
	Creates      []client.Object
	Deletes      []client.Object
	Updates      []client.Object
	Patches      []client.Object
	DeleteAllOfs []client.Object
}

FakeRuntimeClientWriter is a fake implementation of (k8s.io/controller-runtime/pkg/client).ClientWriter

It stores all method calls in the respective struct fields. Instances of FakeRuntimeClientWriter are not concurrency-safe

func (*FakeRuntimeClientWriter) Create added in v0.2.0

func (f *FakeRuntimeClientWriter) Create(
	ctx context.Context,
	obj client.Object,
	opts ...client.CreateOption,
) error

func (*FakeRuntimeClientWriter) Delete added in v0.2.0

func (f *FakeRuntimeClientWriter) Delete(
	ctx context.Context,
	obj client.Object,
	opts ...client.DeleteOption,
) error

func (*FakeRuntimeClientWriter) DeleteAllOf added in v0.2.0

func (f *FakeRuntimeClientWriter) DeleteAllOf(
	ctx context.Context,
	obj client.Object,
	opts ...client.DeleteAllOfOption,
) error

func (*FakeRuntimeClientWriter) Patch added in v0.2.0

func (f *FakeRuntimeClientWriter) Patch(
	ctx context.Context,
	obj client.Object,
	patch client.Patch,
	opts ...client.PatchOption,
) error

func (*FakeRuntimeClientWriter) Update added in v0.2.0

func (f *FakeRuntimeClientWriter) Update(
	ctx context.Context,
	obj client.Object,
	opts ...client.UpdateOption,
) error

type FakeRuntimeStatusClient added in v0.2.0

type FakeRuntimeStatusClient struct {
}

FakeRuntimeStatusClient is a fake implementation of (k8s.io/controller-runtime/pkg/client).StatusClient

func (*FakeRuntimeStatusClient) Scheme added in v0.2.0

func (f *FakeRuntimeStatusClient) Scheme() *runtime.Scheme

Scheme implements the controller-runtime Client interface.

NOTE: this method is not implemented and always returns nil.

func (*FakeRuntimeStatusClient) Status added in v0.2.0

Status implements the controller-runtime StatusClient interface.

NOTE: this function isn't implemented and always returns nil.

type GetCall added in v0.2.0

type GetCall struct {
	Key client.ObjectKey
	Obj client.Object
}

type GetEndpointsFunc added in v0.2.0

type GetEndpointsFunc func(
	ctx context.Context,
	namespace,
	serviceName string,
) (*v1.Endpoints, error)

GetEndpointsFunc is a type that represents a function that can fetch endpoints

func EndpointsFuncForControllerClient added in v0.2.0

func EndpointsFuncForControllerClient(
	cl client.Client,
) GetEndpointsFunc

EndpointsFuncForControllerClient returns a new GetEndpointsFunc that uses the controller-runtime client.Client to fetch endpoints

func EndpointsFuncForK8sClientset added in v0.2.0

func EndpointsFuncForK8sClientset(
	cl *kubernetes.Clientset,
) GetEndpointsFunc

type InformerBackedDeploymentCache added in v0.3.0

type InformerBackedDeploymentCache struct {
	// contains filtered or unexported fields
}

func NewInformerBackedDeploymentCache added in v0.3.0

func NewInformerBackedDeploymentCache(
	lggr logr.Logger,
	cl kubernetes.Interface,
	defaultResync time.Duration,
) *InformerBackedDeploymentCache

func (*InformerBackedDeploymentCache) Get added in v0.3.0

func (*InformerBackedDeploymentCache) MarshalJSON added in v0.3.0

func (i *InformerBackedDeploymentCache) MarshalJSON() ([]byte, error)

func (*InformerBackedDeploymentCache) Start added in v0.3.0

func (*InformerBackedDeploymentCache) Watch added in v0.3.0

func (i *InformerBackedDeploymentCache) Watch(
	ns,
	name string,
) (watch.Interface, error)

type InformerConfigMapUpdater added in v0.3.0

type InformerConfigMapUpdater struct {
	// contains filtered or unexported fields
}

func NewInformerConfigMapUpdater added in v0.3.0

func NewInformerConfigMapUpdater(
	lggr logr.Logger,
	cl kubernetes.Interface,
	defaultResync time.Duration,
) *InformerConfigMapUpdater

func (*InformerConfigMapUpdater) Get added in v0.3.0

func (i *InformerConfigMapUpdater) Get(
	ns,
	name string,
) (corev1.ConfigMap, error)

func (*InformerConfigMapUpdater) MarshalJSON added in v0.3.0

func (i *InformerConfigMapUpdater) MarshalJSON() ([]byte, error)

func (*InformerConfigMapUpdater) Start added in v0.3.0

func (*InformerConfigMapUpdater) Watch added in v0.3.0

func (i *InformerConfigMapUpdater) Watch(
	ns,
	name string,
) (watch.Interface, error)

Jump to

Keyboard shortcuts

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