k8s

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNamespaceIfNeed added in v0.1.2

func CreateNamespaceIfNeed(ctx context.Context, client kubernetes.Interface, namespace string, logger *slog.Logger) error

CreateNamespaceIfNeed creates the provided namespace if it does not exist.

func NewClient

func NewClient(kubeconfig *string, config Config) (kubernetes.Interface, error)

NewClient creates a new Kubernetes client and automatically detects in-cluster and out-of-cluster config.

func NewDynamicClient

func NewDynamicClient(kubeconfig *string, config Config) (dynamic.Interface, error)

NewDynamicClient creates a new dynamic Kubernetes client and automatically detects in-cluster and out-of-cluster config.

func WaitForJobPodsReady

func WaitForJobPodsReady(
	ctx context.Context,
	clientset kubernetes.Interface,
	namespace string,
	jobName string,
	timeout time.Duration,
) error

WaitForJobPodsReady waits for all pods associated with the given job to become ready.

func WatchJobPodLogs

func WatchJobPodLogs(ctx context.Context, clientset kubernetes.Interface, namespace, jobName string, out io.Writer) error

WatchJobPodLogs streams logs from all pods associated with the given job.

Types

type Config

type Config struct {
	QPS   float32
	Burst int
}

type DeleteFunc

type DeleteFunc func(ctx context.Context, client kubernetes.Interface, deleteOpts metav1.DeleteOptions, listOpts metav1.ListOptions, async bool) error

type ListFunc

type ListFunc func(ctx context.Context, client kubernetes.Interface, opts metav1.ListOptions) (empty bool, err error)

type Manager

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

Manager is used to manage Kubernetes resources.

func NewManager

func NewManager(client kubernetes.Interface, cfg *ManagerConfig) *Manager

func (*Manager) DeleteJobs

func (m *Manager) DeleteJobs(ctx context.Context, labelSelector string, async bool) error

DeleteJobs deletes Kubernetes Job resources having provided label. If async is set to false, this function will block until jobs are terminated or context exceeds deadline.

func (*Manager) DeleteNodes

func (m *Manager) DeleteNodes(ctx context.Context, labelSelector string, async bool) error

DeleteNodes deletes all Kubernetes Node resources having provided label. If async is set to false, this function will block until nodes are terminated or context exceeds deadline.

func (*Manager) DeletePods

func (m *Manager) DeletePods(ctx context.Context, labelSelector string, async bool) error

DeletePods deletes Kubernetes Pod resources having provided label. If async is set to false, this function will block until pods are terminated or context exceeds deadline.

func (*Manager) Metrics

func (m *Manager) Metrics() (nodeCreationMetrics, podCreationMetrics, jobCreationMetrics ratelimiter.Metrics)

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts the Manager and the pod & node creation rate limiters. It blocks until the Manager is stopped the context is cancelled or all rate limited executors have finished.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the Manager.

func (*Manager) WaitForJobsToTerminate

func (m *Manager) WaitForJobsToTerminate(ctx context.Context, client kubernetes.Interface, labelSelector string) error

WaitForJobsToTerminate waits for the jobs with the provided labelSelector to terminate.

func (*Manager) WaitForNodesToTerminate

func (m *Manager) WaitForNodesToTerminate(ctx context.Context, client kubernetes.Interface, labelSelector string) error

WaitForNodesToTerminate waits for the nodes with the provided labelSelector to terminate.

func (*Manager) WaitForPodsToTerminate

func (m *Manager) WaitForPodsToTerminate(ctx context.Context, client kubernetes.Interface, labelSelector string) error

WaitForPodsToTerminate waits for the pods with the provided labelSelector to terminate.

type ManagerConfig

type ManagerConfig struct {
	// Namespace is the namespace in which resources should be created.
	Namespace string
	// Logger is the logger that should be used by the Manager.
	Logger *slog.Logger
	// RandomEnvVars is used to determine whether random environment variables should be added to created Pods or Jobs.
	RandomEnvVars bool
	// PodRateLimiterConfig is the configuration for the rate limited PodCreator.
	PodRateLimiterConfig RateLimiterConfig
	// NodeRateLimiterConfig is the configuration for the rate limited NodeCreator.
	NodeRateLimiterConfig RateLimiterConfig
	// JobRateLimiterConfig is the configuration for the rate limited JobCreator.
	JobRateLimiterConfig RateLimiterConfig
}

ManagerConfig is used to configure a new Manager.

type RateLimiterConfig

type RateLimiterConfig struct {
	// Frequency is the frequency at which the rate limiter should be invoked.
	Frequency time.Duration
	// Requests is the number of requests that should be made per invocation.
	Requests int
	// Limit is the maximum number of items that should be processed
	Limit int
}

RateLimiterConfig is used to configure the rate limiter for a specific resource type.

Jump to

Keyboard shortcuts

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