k8s

package module
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: BSD-2-Clause Imports: 32 Imported by: 7

README

K8s

A Kubernetes utility library providing builder patterns and deployers for K8s resources.

Purpose

This library provides a fluent, type-safe builder interface for creating and deploying Kubernetes resources. It simplifies the creation of Deployments, Services, Ingresses, Jobs, CronJobs, StatefulSets, and ConfigMaps with built-in validation and error handling.

Installation

go get github.com/bborbe/k8s

Features

  • Builder Pattern: Fluent interface for constructing Kubernetes resources
  • Deployer Pattern: Unified deployment interface for managing K8s resources
  • Validation: Built-in validation using github.com/bborbe/validation
  • Type Safety: Strongly typed builders prevent common configuration errors
  • Testing Support: Includes Counterfeiter mocks for easy testing
  • Event Handling: Support for Kubernetes resource event handlers

Quick Start

Creating a Deployment
package main

import (
    "context"

    "github.com/bborbe/k8s"
    corev1 "k8s.io/api/core/v1"
)

func main() {
    ctx := context.Background()

    // Build a container
    container, err := k8s.NewContainerBuilder().
        SetName("my-app").
        SetImage("myregistry/my-app:latest").
        AddPort(corev1.ContainerPort{
            Name:          "http",
            ContainerPort: 8080,
            Protocol:      corev1.ProtocolTCP,
        }).
        Build(ctx)
    if err != nil {
        panic(err)
    }

    // Build a deployment
    deployment, err := k8s.NewDeploymentBuilder().
        SetName(k8s.Name("my-app")).
        SetComponent("backend").
        SetReplicas(3).
        SetContainers([]corev1.Container{*container}).
        Build(ctx)
    if err != nil {
        panic(err)
    }

    // Deploy using DeploymentDeployer
    // deployer := k8s.NewDeploymentDeployer(clientset)
    // err = deployer.Deploy(ctx, deployment)
}
Creating a Service
service, err := k8s.NewServiceBuilder().
    SetName(k8s.Name("my-app")).
    AddPort(corev1.ServicePort{
        Name:       "http",
        Port:       80,
        TargetPort: intstr.FromInt(8080),
        Protocol:   corev1.ProtocolTCP,
    }).
    Build(ctx)
Creating a CronJob
cronJob, err := k8s.NewCronJobBuilder().
    SetName(k8s.Name("backup-job")).
    SetSchedule(k8s.CronScheduleExpression("0 2 * * *")).
    SetContainers([]corev1.Container{*container}).
    Build(ctx)

Available Builders

  • DeploymentBuilder - Creates Kubernetes Deployments
  • ServiceBuilder - Creates Kubernetes Services
  • IngressBuilder - Creates Kubernetes Ingresses
  • JobBuilder - Creates Kubernetes Jobs
  • CronJobBuilder - Creates Kubernetes CronJobs
  • StatefulSetBuilder - Creates Kubernetes StatefulSets
  • ContainerBuilder - Creates container specifications
  • PodSpecBuilder - Creates pod specifications
  • ObjectMetaBuilder - Creates object metadata
  • EnvBuilder - Creates environment variable configurations

Available Deployers

  • DeploymentDeployer - Deploys and manages Deployments
  • ServiceDeployer - Deploys and manages Services
  • IngressDeployer - Deploys and manages Ingresses
  • JobDeployer - Deploys and manages Jobs
  • CronJobDeployer - Deploys and manages CronJobs
  • StatefulSetDeployer - Deploys and manages StatefulSets
  • ConfigMapDeployer - Deploys and manages ConfigMaps

Default Configurations

The library provides sensible defaults:

  • Deployments default to 1 replica
  • Image pull secrets default to "docker"
  • Prometheus annotations automatically added to pod templates
  • Rolling update strategy with maxUnavailable=1, maxSurge=1

Testing

The library uses Ginkgo v2 and Gomega for testing:

# Run all tests
make test

# Run tests with coverage
go test -cover ./...

# Generate mocks
make generate

Documentation

Full API documentation available at pkg.go.dev.

Dependencies

  • k8s.io/client-go - Kubernetes client library
  • k8s.io/api - Kubernetes API types
  • github.com/bborbe/validation - Validation framework
  • github.com/bborbe/errors - Error handling with context
  • github.com/bborbe/collection - Collection utilities

License

BSD-style license. See LICENSE file for details.

Documentation

Overview

Package k8s provides builder patterns and deployers for Kubernetes resources.

This library offers a fluent, type-safe interface for creating and deploying Kubernetes resources including Deployments, Services, Ingresses, Jobs, CronJobs, StatefulSets, and ConfigMaps. All builders implement validation and error handling using the bborbe/validation and bborbe/errors libraries.

Quick Start

Create a Deployment with a container:

container, err := k8s.NewContainerBuilder().
    SetName("my-app").
    SetImage("myregistry/my-app:latest").
    Build(ctx)

deployment, err := k8s.NewDeploymentBuilder().
    SetName(k8s.Name("my-app")).
    SetReplicas(3).
    SetContainers([]corev1.Container{*container}).
    Build(ctx)

Builders

All builders follow a fluent interface pattern with method chaining:

  • DeploymentBuilder - Creates Kubernetes Deployments
  • ServiceBuilder - Creates Kubernetes Services
  • IngressBuilder - Creates Kubernetes Ingresses
  • JobBuilder - Creates Kubernetes Jobs
  • CronJobBuilder - Creates Kubernetes CronJobs
  • StatefulSetBuilder - Creates Kubernetes StatefulSets
  • ContainerBuilder - Creates container specifications
  • PodSpecBuilder - Creates pod specifications
  • ObjectMetaBuilder - Creates object metadata

Deployers

Each resource type has a corresponding deployer for managing lifecycle:

  • DeploymentDeployer - Deploys and manages Deployments
  • ServiceDeployer - Deploys and manages Services
  • IngressDeployer - Deploys and manages Ingresses
  • JobDeployer - Deploys and manages Jobs
  • CronJobDeployer - Deploys and manages CronJobs
  • StatefulSetDeployer - Deploys and manages StatefulSets
  • ConfigMapDeployer - Deploys and manages ConfigMaps

Default Configurations

The library provides sensible defaults:

  • Deployments default to 1 replica
  • Image pull secrets default to "docker"
  • Prometheus annotations automatically added to pod templates
  • Rolling update strategy with maxUnavailable=1, maxSurge=1

Index

Constants

This section is empty.

Variables

View Source
var ErrResultChannelClosed = stderrors.New("watch result channel closed")

ErrResultChannelClosed is returned when a Kubernetes watch result channel is closed. This typically occurs when the watch connection times out or is terminated by the server. It is a normal occurrence in long-running watches and should trigger a reconnection.

View Source
var ErrUnknownEventType = stderrors.New("unknown event type")

ErrUnknownEventType is returned when a Kubernetes watch receives an event type that is not recognized or handled by the watcher implementation.

View Source
var JobAlreadyExistsError = stderrors.New("job already exists")

Functions

func CreateConfig

func CreateConfig(kubeconfig string) (*k8s_rest.Config, error)

func IngressEqual

func IngressEqual(a, b v1.Ingress) bool

func NewResourceEventHandler

func NewResourceEventHandler[T Type](
	ctx context.Context,
	eventHandlerAlert EventHandler[T],
) cache.ResourceEventHandler

Types

type ApiextensionsInterface

type ApiextensionsInterface interface {
	apiextensions.Interface
}

func CreateApiextensionsClient

func CreateApiextensionsClient(kubeconfig string) (ApiextensionsInterface, error)

type AppsV1Interface

type AppsV1Interface interface {
	appsv1.AppsV1Interface
}

type BatchV1Interface

type BatchV1Interface interface {
	batchv1.BatchV1Interface
}

type ConfigMapDeployer

type ConfigMapDeployer interface {
	Get(ctx context.Context, namespace Namespace, name Name) (*v1.ConfigMap, error)
	Deploy(ctx context.Context, configmap v1.ConfigMap) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

func NewConfigMapDeployer

func NewConfigMapDeployer(
	clientset k8s_kubernetes.Interface,
) ConfigMapDeployer

type ConfigMapInterface

type ConfigMapInterface interface {
	corev1.ConfigMapInterface
}

type Container

type Container string

func (Container) String

func (c Container) String() string

type ContainerBuilder

type ContainerBuilder interface {
	HasBuildContainer
	validation.HasValidation
	SetEnv(env []corev1.EnvVar) ContainerBuilder
	SetEnvBuilder(envBuilder HasBuildEnv) ContainerBuilder
	SetImage(image string) ContainerBuilder
	SetName(name Name) ContainerBuilder
	SetCommand(command []string) ContainerBuilder
	SetArgs(args []string) ContainerBuilder
	SetPorts(ports []corev1.ContainerPort) ContainerBuilder
	SetVolumeMounts(volumeMounts []corev1.VolumeMount) ContainerBuilder
	AddVolumeMounts(volumeMounts ...corev1.VolumeMount) ContainerBuilder
	SetCpuLimit(cpuLimit string) ContainerBuilder
	SetCpuRequest(cpuRequest string) ContainerBuilder
	SetMemoryLimit(memoryLimit string) ContainerBuilder
	SetMemoryRequest(memoryRequest string) ContainerBuilder
	SetLivenessProbe(livenessProbe corev1.Probe) ContainerBuilder
	SetReadinessProbe(readinessProbe corev1.Probe) ContainerBuilder
	SetRestartPolicy(restartPolicy corev1.ContainerRestartPolicy) ContainerBuilder
}

func NewContainerBuilder

func NewContainerBuilder() ContainerBuilder

type Containers

type Containers []Container

func ParseContainers

func ParseContainers(values []string) Containers

func ParseContainersFromString

func ParseContainersFromString(value string) Containers

func (Containers) Contains

func (c Containers) Contains(container Container) bool

type ContainersBuilder

type ContainersBuilder interface {
	HasBuildContainers
	validation.HasValidation
	AddContainerBuilder(containersBuilder HasBuildContainer) ContainersBuilder
	SetContainerBuilders(containersBuilders []HasBuildContainer) ContainersBuilder
	SetContainers(containers []corev1.Container) ContainersBuilder
}

func NewContainersBuilder

func NewContainersBuilder() ContainersBuilder

type CoreV1Interface

type CoreV1Interface interface {
	corev1.CoreV1Interface
}

type CronJobBuilder

type CronJobBuilder interface {
	validation.HasValidation
	SetObjectMetaBuild(objectMetaBuilder HasBuildObjectMeta) CronJobBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) CronJobBuilder
	SetPodSpecBuilder(podSpecBuilder HasBuildPodSpec) CronJobBuilder
	SetPodSpec(podSpec corev1.PodSpec) CronJobBuilder
	AddVolumes(volumes ...corev1.Volume) CronJobBuilder
	AddVolumeMounts(volumeMounts ...corev1.VolumeMount) CronJobBuilder
	Build(ctx context.Context) (*batchv1.CronJob, error)
	SetVolumes(volumes []corev1.Volume) CronJobBuilder
	SetImage(image string) CronJobBuilder
	SetEnv(env []corev1.EnvVar) CronJobBuilder
	SetLoglevel(loglevel int) CronJobBuilder
	SetCronExpression(cronScheduleExpression CronScheduleExpression) CronJobBuilder
	SetParallelism(parallelism int32) CronJobBuilder
	SetBackoffLimit(backoffLimit int32) CronJobBuilder
	SetCompletions(completions int32) CronJobBuilder
}

func NewCronJobBuilder

func NewCronJobBuilder() CronJobBuilder

type CronJobDeployer

type CronJobDeployer interface {
	Deploy(ctx context.Context, cronjob batchv1.CronJob) error
	Undeploy(ctx context.Context, namespace string, name string) error
}

func NewCronJobDeployer

func NewCronJobDeployer(
	clientset k8s_kubernetes.Interface,
) CronJobDeployer

type CronJobInterface

type CronJobInterface interface {
	batchv1.CronJobInterface
}

type CronScheduleExpression

type CronScheduleExpression string

func (CronScheduleExpression) String

func (c CronScheduleExpression) String() string

func (CronScheduleExpression) Validate

func (c CronScheduleExpression) Validate(ctx context.Context) error

type Deployment

type Deployment string

func (Deployment) String

func (d Deployment) String() string

type DeploymentBuilder

type DeploymentBuilder interface {
	HasBuildDeployment
	validation.HasValidation
	SetObjectMetaBuilder(objectMetaBuilder HasBuildObjectMeta) DeploymentBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) DeploymentBuilder
	SetContainersBuilder(hasBuildContainers HasBuildContainers) DeploymentBuilder
	SetContainers(containers []corev1.Container) DeploymentBuilder
	SetName(name Name) DeploymentBuilder
	SetReplicas(replicas int32) DeploymentBuilder
	SetComponent(component string) DeploymentBuilder
	SetServiceAccountName(serviceAccountName string) DeploymentBuilder
	AddVolumes(volumes ...corev1.Volume) DeploymentBuilder
	SetVolumes(volumes []corev1.Volume) DeploymentBuilder
	SetAffinity(affinity corev1.Affinity) DeploymentBuilder
	AddImagePullSecrets(imagePullSecrets ...string) DeploymentBuilder
	SetImagePullSecrets(imagePullSecrets []string) DeploymentBuilder
}

DeploymentBuilder provides a fluent interface for building Kubernetes Deployments. Use NewDeploymentBuilder to create a new instance with sensible defaults.

func NewDeploymentBuilder

func NewDeploymentBuilder() DeploymentBuilder

NewDeploymentBuilder creates a new DeploymentBuilder with default values:

  • replicas: 1
  • imagePullSecrets: ["docker"]

type DeploymentDeployer

type DeploymentDeployer interface {
	Deploy(ctx context.Context, deployment appsv1.Deployment) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

DeploymentDeployer manages Kubernetes Deployment resources. It handles creation, updates, and deletion of Deployments in a Kubernetes cluster.

func NewDeploymentDeployer

func NewDeploymentDeployer(
	clientset k8s_kubernetes.Interface,
) DeploymentDeployer

NewDeploymentDeployer creates a new DeploymentDeployer with the given Kubernetes clientset.

type DeploymentInterface

type DeploymentInterface interface {
	appsv1.DeploymentInterface
}

type Deployments

type Deployments []Deployment

func ParseDeployments

func ParseDeployments(values []string) Deployments

func ParseDeploymentsFromString

func ParseDeploymentsFromString(value string) Deployments

func (Deployments) Contains

func (c Deployments) Contains(deployment Deployment) bool

type EnvBuilder

type EnvBuilder interface {
	HasBuildEnv
	Add(name, value string) EnvBuilder
	AddSecret(name, secret, key string) EnvBuilder
	AddFieldRef(name string, apiVersion string, fieldPath string) EnvBuilder
}

func NewEnvBuilder

func NewEnvBuilder() EnvBuilder

type EventHandler

type EventHandler[T Type] interface {
	OnAdd(ctx context.Context, obj T) error
	OnUpdate(ctx context.Context, oldObj, newObj T) error
	OnDelete(ctx context.Context, obj T) error
	Provider[T]
}

func NewEventHandler

func NewEventHandler[T Type]() EventHandler[T]

type HasBuildContainer

type HasBuildContainer interface {
	Build(ctx context.Context) (*corev1.Container, error)
}

type HasBuildContainerFunc

type HasBuildContainerFunc func(ctx context.Context) (*corev1.Container, error)

func (HasBuildContainerFunc) Build

type HasBuildContainers

type HasBuildContainers interface {
	Build(ctx context.Context) ([]corev1.Container, error)
}

type HasBuildContainersFunc

type HasBuildContainersFunc func(ctx context.Context) ([]corev1.Container, error)

func (HasBuildContainersFunc) Build

type HasBuildDeployment

type HasBuildDeployment interface {
	Build(ctx context.Context) (*appsv1.Deployment, error)
}

HasBuildDeployment is an interface for types that can build a Kubernetes Deployment.

type HasBuildDeploymentFunc

type HasBuildDeploymentFunc func(ctx context.Context) (*appsv1.Deployment, error)

HasBuildDeploymentFunc is a function type that implements HasBuildDeployment.

func (HasBuildDeploymentFunc) Build

Build executes the function to build a Deployment.

type HasBuildEnv

type HasBuildEnv interface {
	Build(ctx context.Context) ([]corev1.EnvVar, error)
}

type HasBuildEnvFunc

type HasBuildEnvFunc func(ctx context.Context) ([]corev1.EnvVar, error)

func (HasBuildEnvFunc) Build

func (f HasBuildEnvFunc) Build(ctx context.Context) ([]corev1.EnvVar, error)

type HasBuildIngress

type HasBuildIngress interface {
	Build(ctx context.Context) (*v1.Ingress, error)
}

type HasBuildIngressFunc

type HasBuildIngressFunc func(ctx context.Context) (*v1.Ingress, error)

func (HasBuildIngressFunc) Build

type HasBuildJob

type HasBuildJob interface {
	Build(ctx context.Context) (*batchv1.Job, error)
}

type HasBuildJobFunc

type HasBuildJobFunc func(ctx context.Context) (*batchv1.Job, error)

func (HasBuildJobFunc) Build

func (f HasBuildJobFunc) Build(ctx context.Context) (*batchv1.Job, error)

type HasBuildObjectMeta

type HasBuildObjectMeta interface {
	Build(ctx context.Context) (*metav1.ObjectMeta, error)
}

type HasBuildObjectMetaFunc

type HasBuildObjectMetaFunc func(ctx context.Context) (*metav1.ObjectMeta, error)

func (HasBuildObjectMetaFunc) Build

type HasBuildPodSpec

type HasBuildPodSpec interface {
	Build(ctx context.Context) (*corev1.PodSpec, error)
}

type HasBuildPodSpecFunc

type HasBuildPodSpecFunc func(ctx context.Context) (*corev1.PodSpec, error)

func (HasBuildPodSpecFunc) Build

type HasBuildService

type HasBuildService interface {
	Build(ctx context.Context) (*corev1.Service, error)
}

HasBuildService is an interface for types that can build a Kubernetes Service.

type HasBuildServiceFunc

type HasBuildServiceFunc func(ctx context.Context) (*corev1.Service, error)

HasBuildServiceFunc is a function type that implements HasBuildService.

func (HasBuildServiceFunc) Build

Build executes the function to build a Service.

type HasBuildStatefulSet

type HasBuildStatefulSet interface {
	Build(ctx context.Context) (*appsv1.StatefulSet, error)
}

type HasBuildStatefulSetFunc

type HasBuildStatefulSetFunc func(ctx context.Context) (*appsv1.StatefulSet, error)

func (HasBuildStatefulSetFunc) Build

type Identifier

type Identifier string

func (Identifier) String

func (f Identifier) String() string

type IngressBuilder

type IngressBuilder interface {
	HasBuildIngress
	validation.HasValidation
	SetObjectMetaBuilder(objectMetaBuilder HasBuildObjectMeta) IngressBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) IngressBuilder
	SetHost(host string) IngressBuilder
	SetServiceName(serviceName Name) IngressBuilder
	SetPath(path string) IngressBuilder
	SetIngressClassName(ingressClassName string) IngressBuilder
}

func NewIngressBuilder

func NewIngressBuilder() IngressBuilder

type IngressDeployer

type IngressDeployer interface {
	Deploy(ctx context.Context, ingress v1.Ingress) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

func NewIngressDeployer

func NewIngressDeployer(
	clientset k8s_kubernetes.Interface,
) IngressDeployer

type IngressInterface

type IngressInterface interface {
	networkv1.IngressInterface
}

type Interface

type Interface interface {
	kubernetes.Interface
}

func CreateClientset

func CreateClientset(kubeconfig string) (Interface, error)

type JobBuilder

type JobBuilder interface {
	HasBuildJob
	validation.HasValidation
	SetObjectMetaBuild(objectMetaBuilder HasBuildObjectMeta) JobBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) JobBuilder
	SetPodSpecBuilder(podSpecBuilder HasBuildPodSpec) JobBuilder
	SetPodSpec(podSpec corev1.PodSpec) JobBuilder
	SetBackoffLimit(backoffLimit int32) JobBuilder
	SetComponent(component string) JobBuilder
	SetCompletions(completions int32) JobBuilder
	AddLabel(key, value string) JobBuilder
	SetLabels(labels map[string]string) JobBuilder
	SetApp(app string) JobBuilder
	SetParallelism(parallelism int32) JobBuilder
	SetTTLSecondsAfterFinished(ttlSecondsAfterFinished int32) JobBuilder
	SetCompletionMode(completionMode batchv1.CompletionMode) JobBuilder
	SetPodReplacementPolicy(podReplacementPolicy batchv1.PodReplacementPolicy) JobBuilder
}

func NewJobBuilder

func NewJobBuilder() JobBuilder

type JobDeployer

type JobDeployer interface {
	Deploy(ctx context.Context, job batchv1.Job) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

func NewJobDeployer

func NewJobDeployer(
	clientset kubernetes.Interface,
) JobDeployer

type JobInterface

type JobInterface interface {
	batchv1.JobInterface
}

type Name

type Name string

func BuildName

func BuildName(names ...string) Name

BuildName from the given string. Replace all illegal characters with underscore

func NameFromPod

func NameFromPod(pod corev1.Pod) Name

NameFromPod return the name of the pod with -0 or hash

func (Name) Add

func (n Name) Add(name string) Name

func (Name) Bytes

func (n Name) Bytes() []byte

func (Name) Ptr

func (n Name) Ptr() *Name

func (Name) String

func (n Name) String() string

func (Name) Validate

func (n Name) Validate(ctx context.Context) error

type Namespace

type Namespace string

func (Namespace) String

func (f Namespace) String() string

type NetworkingV1Interface

type NetworkingV1Interface interface {
	networkv1.NetworkingV1Interface
}

type ObjectMetaBuilder

type ObjectMetaBuilder interface {
	HasBuildObjectMeta
	validation.HasValidation
	AddLabel(key, value string) ObjectMetaBuilder
	SetLabels(labels map[string]string) ObjectMetaBuilder
	AddAnnotation(key, value string) ObjectMetaBuilder
	SetAnnotations(annotations map[string]string) ObjectMetaBuilder
	SetGenerateName(generateName string) ObjectMetaBuilder
	SetName(name Name) ObjectMetaBuilder
	SetNamespace(namespace Namespace) ObjectMetaBuilder
	SetComponent(component string) ObjectMetaBuilder
	SetFinalizers(finalizers []string) ObjectMetaBuilder
}

func NewObjectMetaBuilder

func NewObjectMetaBuilder() ObjectMetaBuilder

type PodEventProcessor added in v1.11.0

type PodEventProcessor interface {
	OnUpdate(ctx context.Context, pod corev1.Pod) error
	OnDelete(ctx context.Context, pod corev1.Pod) error
}

func NewPodEventProcessorSkipError added in v1.11.0

func NewPodEventProcessorSkipError(
	podEventProcessor PodEventProcessor,
) PodEventProcessor

func PodEventProcessorFunc added in v1.11.0

func PodEventProcessorFunc(
	onUpdate func(ctx context.Context, pod corev1.Pod) error,
	onDelete func(ctx context.Context, pod corev1.Pod) error,
) PodEventProcessor

type PodInterface added in v1.11.0

type PodInterface interface {
	corev1.PodInterface
}

type PodSpecBuilder

type PodSpecBuilder interface {
	HasBuildPodSpec
	validation.HasValidation
	SetContainersBuilder(hasBuildContainers HasBuildContainers) PodSpecBuilder
	SetContainers(containers []corev1.Container) PodSpecBuilder
	SetAffinity(affinity corev1.Affinity) PodSpecBuilder
	SetImagePullSecrets(imagePullSecrets []string) PodSpecBuilder
	SetRestartPolicy(restartPolicy corev1.RestartPolicy) PodSpecBuilder
	SetVolumes(volumes []corev1.Volume) PodSpecBuilder
	SetPriorityClassName(priorityClassName string) PodSpecBuilder
}

func NewPodSpecBuilder

func NewPodSpecBuilder() PodSpecBuilder

type PodWatcher added in v1.11.0

type PodWatcher interface {
	Watch(ctx context.Context) error
}

func NewPodWatcher added in v1.11.0

func NewPodWatcher(
	clientset kubernetes.Interface,
	podManager PodEventProcessor,
	namespace Namespace,
) PodWatcher

NewPodWatcher creates a Kubernetes Pod watcher that monitors Pod resources in the specified namespace. It invokes callbacks on the provided PodEventProcessor for Add/Modify/Delete events. This watcher returns when the watch connection closes. Use NewPodWatcherRetry for automatic retries.

func NewPodWatcherRetry added in v1.11.0

func NewPodWatcherRetry(
	podWatcher PodWatcher,
	waiter libtime.WaiterDuration,
	duration libtime.Duration,
) PodWatcher

NewPodWatcherRetry wraps a PodWatcher with automatic retry logic. If the underlying watcher returns an error that is not context cancellation or deadline exceeded, it will wait for the specified duration and retry. Context cancellation or deadline exceeded errors are returned immediately.

type Provider

type Provider[T Type] interface {
	Get(ctx context.Context) ([]T, error)
}

type SecretEventProcessor added in v1.10.0

type SecretEventProcessor interface {
	OnUpdate(ctx context.Context, secret corev1.Secret) error
	OnDelete(ctx context.Context, secret corev1.Secret) error
}

func NewSecretEventProcessorSkipError added in v1.10.0

func NewSecretEventProcessorSkipError(
	secretEventProcessor SecretEventProcessor,
) SecretEventProcessor

func SecretEventProcessorFunc added in v1.10.0

func SecretEventProcessorFunc(
	onUpdate func(ctx context.Context, secret corev1.Secret) error,
	onDelete func(ctx context.Context, secret corev1.Secret) error,
) SecretEventProcessor

type SecretInterface added in v1.10.0

type SecretInterface interface {
	corev1.SecretInterface
}

type SecretWatcher added in v1.10.0

type SecretWatcher interface {
	Watch(ctx context.Context) error
}

func NewSecretWatcher added in v1.10.0

func NewSecretWatcher(
	clientset kubernetes.Interface,
	secretManager SecretEventProcessor,
	namespace Namespace,
) SecretWatcher

NewSecretWatcher creates a Kubernetes Secret watcher that monitors Secret resources in the specified namespace. It invokes callbacks on the provided SecretEventProcessor for Add/Modify/Delete events. This watcher returns when the watch connection closes. Use NewSecretWatcherRetry for automatic retries.

func NewSecretWatcherRetry added in v1.10.0

func NewSecretWatcherRetry(
	secretWatcher SecretWatcher,
	waiter libtime.WaiterDuration,
	duration libtime.Duration,
) SecretWatcher

NewSecretWatcherRetry wraps a SecretWatcher with automatic retry logic. If the underlying watcher returns an error that is not context cancellation or deadline exceeded, it will wait for the specified duration and retry. Context cancellation or deadline exceeded errors are returned immediately.

type ServiceBuilder

type ServiceBuilder interface {
	HasBuildService
	validation.HasValidation
	SetObjectMetaBuilder(objectMetaBuilder HasBuildObjectMeta) ServiceBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) ServiceBuilder
	SetName(name Name) ServiceBuilder
	SetServicePortName(servicePortName string) ServiceBuilder
	SetServicePortNumber(servicePortNumber int32) ServiceBuilder
}

ServiceBuilder provides a fluent interface for building Kubernetes Services. Use NewServiceBuilder to create a new instance with sensible defaults.

func NewServiceBuilder

func NewServiceBuilder() ServiceBuilder

NewServiceBuilder creates a new ServiceBuilder with default values:

  • servicePortName: "http"
  • servicePortNumber: 9090

type ServiceDeployer

type ServiceDeployer interface {
	Deploy(ctx context.Context, service v1.Service) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

func NewServiceDeployer

func NewServiceDeployer(
	clientset k8s_kubernetes.Interface,
) ServiceDeployer

type ServiceEventProcessor added in v1.9.1

type ServiceEventProcessor interface {
	OnUpdate(ctx context.Context, service corev1.Service) error
	OnDelete(ctx context.Context, service corev1.Service) error
}

func NewServiceEventProcessorSkipError added in v1.9.2

func NewServiceEventProcessorSkipError(
	serviceEventProcessor ServiceEventProcessor,
) ServiceEventProcessor

func ServiceEventProcessorFunc added in v1.9.1

func ServiceEventProcessorFunc(
	onUpdate func(ctx context.Context, service corev1.Service) error,
	onDelete func(ctx context.Context, service corev1.Service) error,
) ServiceEventProcessor

type ServiceInterface

type ServiceInterface interface {
	corev1.ServiceInterface
}

type ServiceWatcher added in v1.9.1

type ServiceWatcher interface {
	Watch(ctx context.Context) error
}

func NewServiceWatcher added in v1.9.1

func NewServiceWatcher(
	clientset kubernetes.Interface,
	serviceManager ServiceEventProcessor,
	namespace Namespace,
) ServiceWatcher

NewServiceWatcher creates a Kubernetes Service watcher that monitors Service resources in the specified namespace. It invokes callbacks on the provided ServiceEventProcessor for Add/Modify/Delete events. This watcher returns when the watch connection closes. Use NewServiceWatcherRetry for automatic retries.

func NewServiceWatcherRetry added in v1.10.0

func NewServiceWatcherRetry(
	serviceWatcher ServiceWatcher,
	waiter libtime.WaiterDuration,
	duration libtime.Duration,
) ServiceWatcher

NewServiceWatcherRetry wraps a ServiceWatcher with automatic retry logic. If the underlying watcher returns an error that is not context cancellation or deadline exceeded, it will wait for the specified duration and retry. Context cancellation or deadline exceeded errors are returned immediately.

type StatefulSet

type StatefulSet string

StatefulSet represents a Kubernetes StatefulSet name.

func (StatefulSet) String

func (s StatefulSet) String() string

String returns the string representation of the StatefulSet name.

type StatefulSetBuilder

type StatefulSetBuilder interface {
	HasBuildStatefulSet
	validation.HasValidation
	SetObjectMetaBuilder(objectMetaBuilder HasBuildObjectMeta) StatefulSetBuilder
	SetObjectMeta(objectMeta metav1.ObjectMeta) StatefulSetBuilder
	SetContainersBuilder(hasBuildContainers HasBuildContainers) StatefulSetBuilder
	SetContainers(containers []corev1.Container) StatefulSetBuilder
	AddLabel(key, value string) StatefulSetBuilder
	SetName(name Name) StatefulSetBuilder
	SetReplicas(replicas int32) StatefulSetBuilder
	SetDatadirSize(size string) StatefulSetBuilder
	SetStorageClass(storageClass string) StatefulSetBuilder
	AddVolumes(volumes ...corev1.Volume) StatefulSetBuilder
	SetAffinity(affinity corev1.Affinity) StatefulSetBuilder
	AddImagePullSecrets(imagePullSecrets ...string) StatefulSetBuilder
	SetImagePullSecrets(imagePullSecrets []string) StatefulSetBuilder
}

func NewStatefulSetBuilder

func NewStatefulSetBuilder() StatefulSetBuilder

type StatefulSetDeployer

type StatefulSetDeployer interface {
	Deploy(ctx context.Context, statefulSet appsv1.StatefulSet) error
	Undeploy(ctx context.Context, namespace Namespace, name Name) error
}

func NewStatefulSetDeployer

func NewStatefulSetDeployer(
	clientset k8s_kubernetes.Interface,
) StatefulSetDeployer

type StatefulSetInterface

type StatefulSetInterface interface {
	appsv1.StatefulSetInterface
}

type StatefulSets

type StatefulSets []StatefulSet

StatefulSets is a collection of StatefulSet names.

func ParseStatefulSets

func ParseStatefulSets(values []string) StatefulSets

ParseStatefulSets converts a slice of strings into StatefulSets.

func ParseStatefulSetsFromString

func ParseStatefulSetsFromString(value string) StatefulSets

ParseStatefulSetsFromString parses a comma-separated string into StatefulSets.

func (StatefulSets) Contains

func (c StatefulSets) Contains(statefulSet StatefulSet) bool

Contains returns true if the collection contains the specified statefulSet.

type Type

type Type interface {
	Equal(other Type) bool
	Identifier() Identifier
	validation.HasValidation
	fmt.Stringer
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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