workload

package
v1.4.4 Latest Latest
Warning

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

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

Documentation

Overview

Package workload holds logic for manipulating kubernetes workload data structs. Code in this package assumes that it is single-threaded, running on data structures only accessible to the current thread.

In addition, workload contains functions that help format safe names for kubernetes resources, following the rfc1035/rfc1123 label (DNS_LABEL) format.

Index

Constants

View Source
const (
	// DefaultProxyImage is the latest version of the proxy as of the release
	// of this operator. This is managed as a dependency. We update this constant
	// when the Cloud SQL Auth Proxy releases a new version.
	DefaultProxyImage = "gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.9.0"

	// DefaultFirstPort is the first port number chose for an instance listener by the
	// proxy.
	DefaultFirstPort int32 = 5000

	// DefaultHealthCheckPort is the used by the proxy to expose prometheus
	// and kubernetes health checks.
	DefaultHealthCheckPort int32 = 9801

	// DefaultAdminPort is the used by the proxy to expose the quitquitquit
	// and debug api endpoints
	DefaultAdminPort int32 = 9091
)

Constants for well known error codes and defaults. These are exposed on the package and documented here so that they appear in the godoc. These also need to be documented in the CRD

View Source
const ContainerPrefix = "csql-"

ContainerPrefix is the name prefix used on containers added to PodSpecs by this operator.

Variables

This section is empty.

Functions

func ContainerName

func ContainerName(r *cloudsqlapi.AuthProxyWorkload) string

ContainerName generates a valid name for a corev1.Container object that implements this cloudsql instance. Names must be 63 characters or fewer and adhere to the rfc1035/rfc1123 label (DNS_LABEL) format. r.ObjectMeta.Name already is required to be 63 characters or less because it is a name. Because we are prepending 'csql-' ContainerPrefix as a marker, the generated name with the prefix could be longer than 63 characters.

func PodAnnotation added in v0.3.0

func PodAnnotation(r *cloudsqlapi.AuthProxyWorkload, defaultProxyImage string) (string, string)

PodAnnotation returns the annotation (key, value) that should be added to pods that are configured with this AuthProxyWorkload resource. This takes into account whether the AuthProxyWorkload exists or was recently deleted. The defaultProxyImage is part of the annotation value.

func SafePrefixedName

func SafePrefixedName(prefix, instName string) string

SafePrefixedName adds a prefix to a name and shortens it while preserving its uniqueness so that it fits the 63 character limit imposed by kubernetes. Kubernetes names must follow the DNS Label format for all names. See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names

DO NOT CHANGE THIS ALGORITHM! The names generated by this function are used to match containers and volumes to configuration. If the names are generated differently between one version of the operator and the next, the operator will break. Existing workloads will not be correctly updated.

func VolumeName

func VolumeName(r *cloudsqlapi.AuthProxyWorkload, inst *cloudsqlapi.InstanceSpec, mountType string) string

VolumeName generates a unique, valid name for a volume based on the AuthProxyWorkload name and the Cloud SQL instance name.

Types

type ConfigError

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

ConfigError is an error with extra details about why an AuthProxyWorkload cannot be configured.

func (*ConfigError) DetailedErrors

func (e *ConfigError) DetailedErrors() []ConfigErrorDetail

func (*ConfigError) Error

func (e *ConfigError) Error() string

type ConfigErrorDetail

type ConfigErrorDetail struct {
	ErrorCode          string
	Description        string
	AuthProxyName      string
	AuthProxyNamespace string

	WorkloadKind      schema.GroupVersionKind
	WorkloadName      string
	WorkloadNamespace string
}

ConfigErrorDetail is an error that contains details about specific kinds of errors that caused a AuthProxyWorkload to fail when being configured on a workload.

func (*ConfigErrorDetail) Error

func (e *ConfigErrorDetail) Error() string

type CronJobWorkload

type CronJobWorkload struct {
	CronJob *batchv1.CronJob
}

func (*CronJobWorkload) Object

func (d *CronJobWorkload) Object() client.Object

func (*CronJobWorkload) PodSpec

func (d *CronJobWorkload) PodSpec() corev1.PodSpec

func (*CronJobWorkload) PodTemplateAnnotations

func (d *CronJobWorkload) PodTemplateAnnotations() map[string]string

type DaemonSetWorkload

type DaemonSetWorkload struct {
	DaemonSet *appsv1.DaemonSet
}

func (*DaemonSetWorkload) Object

func (d *DaemonSetWorkload) Object() client.Object

func (*DaemonSetWorkload) PodSpec

func (d *DaemonSetWorkload) PodSpec() corev1.PodSpec

func (*DaemonSetWorkload) PodTemplateAnnotations

func (d *DaemonSetWorkload) PodTemplateAnnotations() map[string]string

func (*DaemonSetWorkload) SetPodSpec

func (d *DaemonSetWorkload) SetPodSpec(spec corev1.PodSpec)

func (*DaemonSetWorkload) SetPodTemplateAnnotations

func (d *DaemonSetWorkload) SetPodTemplateAnnotations(v map[string]string)

type DeploymentWorkload

type DeploymentWorkload struct {
	Deployment *appsv1.Deployment
}

func (*DeploymentWorkload) Object

func (d *DeploymentWorkload) Object() client.Object

func (*DeploymentWorkload) PodSpec

func (d *DeploymentWorkload) PodSpec() corev1.PodSpec

func (*DeploymentWorkload) PodTemplateAnnotations

func (d *DeploymentWorkload) PodTemplateAnnotations() map[string]string

func (*DeploymentWorkload) SetPodSpec

func (d *DeploymentWorkload) SetPodSpec(spec corev1.PodSpec)

func (*DeploymentWorkload) SetPodTemplateAnnotations

func (d *DeploymentWorkload) SetPodTemplateAnnotations(v map[string]string)

type JobWorkload

type JobWorkload struct {
	Job *batchv1.Job
}

func (*JobWorkload) Object

func (d *JobWorkload) Object() client.Object

func (*JobWorkload) PodSpec

func (d *JobWorkload) PodSpec() corev1.PodSpec

func (*JobWorkload) PodTemplateAnnotations

func (d *JobWorkload) PodTemplateAnnotations() map[string]string

type PodWorkload

type PodWorkload struct {
	Pod *corev1.Pod
}

func (*PodWorkload) Object

func (d *PodWorkload) Object() client.Object

func (*PodWorkload) PodSpec

func (d *PodWorkload) PodSpec() corev1.PodSpec

func (*PodWorkload) PodTemplateAnnotations

func (d *PodWorkload) PodTemplateAnnotations() map[string]string

func (*PodWorkload) SetPodSpec

func (d *PodWorkload) SetPodSpec(spec corev1.PodSpec)

func (*PodWorkload) SetPodTemplateAnnotations

func (d *PodWorkload) SetPodTemplateAnnotations(v map[string]string)

type ReplicaSetWorkload

type ReplicaSetWorkload struct {
	ReplicaSet *appsv1.ReplicaSet
}

func (*ReplicaSetWorkload) Object

func (d *ReplicaSetWorkload) Object() client.Object

func (*ReplicaSetWorkload) PodSpec

func (d *ReplicaSetWorkload) PodSpec() corev1.PodSpec

func (*ReplicaSetWorkload) PodTemplateAnnotations

func (d *ReplicaSetWorkload) PodTemplateAnnotations() map[string]string

func (*ReplicaSetWorkload) SetPodSpec

func (d *ReplicaSetWorkload) SetPodSpec(spec corev1.PodSpec)

func (*ReplicaSetWorkload) SetPodTemplateAnnotations

func (d *ReplicaSetWorkload) SetPodTemplateAnnotations(v map[string]string)

type StatefulSetWorkload

type StatefulSetWorkload struct {
	StatefulSet *appsv1.StatefulSet
}

func (*StatefulSetWorkload) Object

func (d *StatefulSetWorkload) Object() client.Object

func (*StatefulSetWorkload) PodSpec

func (d *StatefulSetWorkload) PodSpec() corev1.PodSpec

func (*StatefulSetWorkload) PodTemplateAnnotations

func (d *StatefulSetWorkload) PodTemplateAnnotations() map[string]string

func (*StatefulSetWorkload) SetPodSpec

func (d *StatefulSetWorkload) SetPodSpec(spec corev1.PodSpec)

func (*StatefulSetWorkload) SetPodTemplateAnnotations

func (d *StatefulSetWorkload) SetPodTemplateAnnotations(v map[string]string)

type Updater

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

Updater holds global state used while reconciling workloads.

func NewUpdater

func NewUpdater(userAgent string, defaultProxyImage string) *Updater

NewUpdater creates a new instance of Updater with a supplier that loads the default proxy impage from the public docker registry

func (*Updater) CheckWorkloadContainers added in v1.0.0

func (u *Updater) CheckWorkloadContainers(wl *PodWorkload, matches []*cloudsqlapi.AuthProxyWorkload) error

CheckWorkloadContainers determines if a pod is configured incorrectly and therefore needs to be deleted. Pods must be (1) missing one or more proxy sidecar containers and (2) have a terminated container.

func (*Updater) ConfigureWorkload

func (u *Updater) ConfigureWorkload(wl *PodWorkload, matches []*cloudsqlapi.AuthProxyWorkload) error

ConfigureWorkload applies the proxy containers from all of the instances listed in matchingAuthProxyWorkloads to the workload

func (*Updater) FindMatchingAuthProxyWorkloads

func (u *Updater) FindMatchingAuthProxyWorkloads(pl *cloudsqlapi.AuthProxyWorkloadList, wl *PodWorkload, owners []Workload) []*cloudsqlapi.AuthProxyWorkload

ConfigurePodProxies finds all AuthProxyWorkload resources matching this workload and then updates the workload's containers. This does not save the updated workload.

func (*Updater) PodAnnotation added in v0.4.0

func (u *Updater) PodAnnotation(r *cloudsqlapi.AuthProxyWorkload) (string, string)

PodAnnotation returns the annotation (key, value) that should be added to pods that are configured with this AuthProxyWorkload resource. This takes into account whether the AuthProxyWorkload exists or was recently deleted.

type WithMutablePodTemplate

type WithMutablePodTemplate interface {
	SetPodSpec(spec corev1.PodSpec)
	SetPodTemplateAnnotations(map[string]string)
}

WithMutablePodTemplate interface applies only to workload types where the pod template can be changed.

type Workload

type Workload interface {
	PodSpec() corev1.PodSpec
	PodTemplateAnnotations() map[string]string
	Object() client.Object
}

Workload is a standard interface to access the pod definition for the 7 major kinds of interfaces: Deployment, Pod, StatefulSet, ReplicaSet, DaemonSet, Job, and Cronjob. These methods are used by the ModifierStore to update the contents of the workload's pod template (or the pod itself) so that it will contain necessary configuration and other details before it starts, or if the configuration changes.

func WorkloadForKind

func WorkloadForKind(kind string) (Workload, error)

WorkloadForKind returns a workload for a particular Kind

type WorkloadList

type WorkloadList interface {
	// List returns a pointer to the ObjectList ready to be passed to client.List()
	List() client.ObjectList
	// Workloads transforms the contents of the List into a slice of Workloads
	Workloads() []Workload
}

WorkloadList is a standard way to access the lists of the 7 major kinds of interfaces: DeploymentList, DaemonSetList, PodList, ReplicaSetList, StatefulSetList, JobList, and CronJobList.

func WorkloadListForKind

func WorkloadListForKind(kind string) (WorkloadList, error)

WorkloadListForKind returns a new WorkloadList initialized for a particular kubernetes Kind.

Jump to

Keyboard shortcuts

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