k8s

package
v0.0.0-...-89c8abe Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Clutch relies on cluster information throughout the application.

Previously we relied on the `clusterName` field on objectmeta https://github.com/kubernetes/apimachinery/blob/2456ebdaba229616fab2161a615148884b46644b/pkg/apis/meta/v1/types.go#L266-L270 This has since be deprecated as of https://github.com/kubernetes/kubernetes/commit/331525670b772eb8956b7f5204078c51c00aaef3 and there was no replacement to this objectmeta field.

To replace this we utilize our own label to denote which cluster the object belongs to, these helper functions are used to standardize the getting and setting of this field.

Index

Constants

View Source
const Name = "clutch.service.k8s"

Variables

This section is empty.

Functions

func ApplyClusterLabels

func ApplyClusterLabels(cluster string, obj runtime.Object) error

func ApplyListOptions

func ApplyListOptions(listOpts *k8sapiv1.ListOptions) (metav1.ListOptions, error)

TODO (mcutalo): make this generic when adding additional `List` functionality for all k8s resources and support field selectors

func ApplyRestClientConfig

func ApplyRestClientConfig(restConfig *rest.Config, restClientConfig *k8sconfigv1.RestClientConfig) error

func ConvertError

func ConvertError(e error) error

ConvertError takes an embedded K8s error and converts it to an error w/ embedded GRPC status containing all of the same information.

func GenerateStrategicPatch

func GenerateStrategicPatch(original, modified runtime.Object, dataStruct interface{}) ([]byte, error)

GenerateStrategicPatch will return a patch that yields the modified object when applied to the original object, or an error if either of the two objects is invalid.

func GetKubeClusterName

func GetKubeClusterName(obj any) string

func New

func New(cfg *any.Any, logger *zap.Logger, scope tally.Scope) (service.Service, error)

func NewLightweightInformer

func NewLightweightInformer(
	lw cache.ListerWatcher,
	objType runtime.Object,
	h cache.ResourceEventHandler,
	recieveUpdates bool,
	clusterName string,
) cache.Controller

func ProtoForCronJob

func ProtoForCronJob(cluster string, k8scronJob *v1.CronJob) *k8sapiv1.CronJob

func ProtoForDeployment

func ProtoForDeployment(cluster string, deployment *appsv1.Deployment) *k8sapiv1.Deployment

func ProtoForDeploymentSpec

func ProtoForDeploymentSpec(deploymentSpec appsv1.DeploymentSpec) *k8sapiv1.Deployment_DeploymentSpec

func ProtoForDeploymentStatus

func ProtoForDeploymentStatus(deploymentStatus appsv1.DeploymentStatus) *k8sapiv1.Deployment_DeploymentStatus

func ProtoForEvent

func ProtoForEvent(cluster string, k8sEvent *corev1.Event) *k8sapiv1.Event

func ProtoForHPA

func ProtoForHPA(cluster string, autoscaler *autoscalingv1.HorizontalPodAutoscaler) *k8sapiv1.HPA

func ProtoForNamespace

func ProtoForNamespace(cluster string, k8snamespace *corev1.Namespace) *k8sapiv1.Namespace

func ProtoForNode

func ProtoForNode(cluster string, k8snode *corev1.Node) *k8sapiv1.Node

func ProtoForService

func ProtoForService(cluster string, k8sservice *corev1.Service) *k8sapiv1.Service

func ProtoForStatefulSet

func ProtoForStatefulSet(cluster string, statefulSet *appsv1.StatefulSet) *k8sapiv1.StatefulSet

ProtoForStatefulSet maps a Kubernetes Stateful Set object to a k8sapiv1 object

Types

type ClientsetManager

type ClientsetManager interface {
	Clientsets(ctx context.Context) (map[string]ContextClientset, error)
	GetK8sClientset(ctx context.Context, clientset, cluster, namespace string) (ContextClientset, error)
}

type ContextClientset

type ContextClientset interface {
	k8s.Interface
	Metrics() k8s_metrics.Interface
	Namespace() string
	Cluster() string
}

func NewContextClientset

func NewContextClientset(namespace string, cluster string, clientset k8s.Interface) ContextClientset

func NewContextClientsetWithMetrics

func NewContextClientsetWithMetrics(namespace string, cluster string, clientset k8s.Interface, metrics k8s_metrics.Interface) ContextClientset

type ExpectedObjectMetaFieldsCheckError

type ExpectedObjectMetaFieldsCheckError struct {
	// List of annotations whose values were not as expected
	MismatchedAnnotations []*mismatchedAnnotation
}

func (*ExpectedObjectMetaFieldsCheckError) Error

type Service

type Service interface {
	// All names of clientsets.
	Clientsets(ctx context.Context) ([]string, error)
	GetK8sClientset(ctx context.Context, clientset string) (ContextClientset, error)

	// Pod management functions.
	DescribePod(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.Pod, error)
	DeletePod(ctx context.Context, clientset, cluster, namespace, name string) error
	ListPods(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.Pod, error)
	UpdatePod(ctx context.Context, clientset, cluster, namespace, name string, expected_object_meta_fields *k8sapiv1.ExpectedObjectMetaFields, object_meta_fields *k8sapiv1.ObjectMetaFields, remove_object_meta_fields *k8sapiv1.RemoveObjectMetaFields) error
	GetPodLogs(ctx context.Context, clientset, cluster, namespace, name string, opts *k8sapiv1.PodLogsOptions) (*k8sapiv1.GetPodLogsResponse, error)

	// HPA management functions.
	DescribeHPA(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.HPA, error)
	ResizeHPA(ctx context.Context, clientset, cluster, namespace, name string, sizing *k8sapiv1.ResizeHPARequest_Sizing) error
	DeleteHPA(ctx context.Context, clientset, cluster, namespace, name string) error

	// Deployment management functions.
	DescribeDeployment(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.Deployment, error)
	ListDeployments(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.Deployment, error)
	UpdateDeployment(ctx context.Context, clientset, cluster, namespace, name string, fields *k8sapiv1.UpdateDeploymentRequest_Fields) error
	DeleteDeployment(ctx context.Context, clientset, cluster, namespace, name string) error

	// Service management functions.
	DescribeService(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.Service, error)
	ListServices(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.Service, error)
	DeleteService(ctx context.Context, clientset, cluster, namespace, name string) error

	// StatefulSet management functions.
	DescribeStatefulSet(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.StatefulSet, error)
	ListStatefulSets(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.StatefulSet, error)
	UpdateStatefulSet(ctx context.Context, clientset, cluster, namespace, name string, fields *k8sapiv1.UpdateStatefulSetRequest_Fields) error
	DeleteStatefulSet(ctx context.Context, clientset, cluster, namespace, name string) error

	// CronJob management functions.
	DescribeCronJob(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.CronJob, error)
	ListCronJobs(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.CronJob, error)
	DeleteCronJob(ctx context.Context, clientset, cluster, namespace, name string) error

	// ConfigMap management functions.
	DescribeConfigMap(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.ConfigMap, error)
	DeleteConfigMap(ctx context.Context, clientset, cluster, namespace, name string) error
	ListConfigMaps(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.ConfigMap, error)

	// Job management functions.
	DescribeJob(ctx context.Context, clientset, cluster, namespace, name string) (*k8sapiv1.Job, error)
	DeleteJob(ctx context.Context, clientset, cluster, namespace, name string) error
	ListJobs(ctx context.Context, clientset, cluster, namespace string, listOptions *k8sapiv1.ListOptions) ([]*k8sapiv1.Job, error)
	CreateJob(ctx context.Context, clientset, cluster, namespace string, job *batchv1.Job) (*k8sapiv1.Job, error)

	// Namespace management functions.
	DescribeNamespace(ctx context.Context, clientset, cluster, name string) (*k8sapiv1.Namespace, error)

	// Event management functions.
	ListEvents(ctx context.Context, clientset, cluster, namespace, object string, kind k8sapiv1.ObjectKind) ([]*k8sapiv1.Event, error)

	// Node management functions.
	DescribeNode(ctx context.Context, clientset, cluster, name string) (*k8sapiv1.Node, error)
	UpdateNode(ctx context.Context, clientset, cluster, name string, unschedulable bool) error

	ListNamespaceEvents(ctx context.Context, clientset, cluster, namespace string, types []k8sapiv1.EventType) ([]*k8sapiv1.Event, error)
}

func NewWithClientsetManager

func NewWithClientsetManager(manager ClientsetManager, logger *zap.Logger, scope tally.Scope) (Service, error)

Jump to

Keyboard shortcuts

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