controller

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequeueOnRefreshTimeout       = time.Second
	LoadReplicaStateTimeout       = 10 * time.Second
	TLSFileMode             int32 = 0444
)

Variables

View Source
var (
	// DefaultLivenessProbeSettings defines default settings for Kubernetes liveness probes.
	//nolint: mnd // Magic numbers are used as constants.
	DefaultLivenessProbeSettings = corev1.Probe{
		InitialDelaySeconds: 60,
		TimeoutSeconds:      10,
		PeriodSeconds:       5,
		FailureThreshold:    10,
	}

	// DefaultReadinessProbeSettings defines default settings for Kubernetes liveness probes.
	//nolint: mnd // Magic numbers are used as constants.
	DefaultReadinessProbeSettings = corev1.Probe{
		InitialDelaySeconds: 5,
		TimeoutSeconds:      10,
		PeriodSeconds:       1,
		SuccessThreshold:    5,
		FailureThreshold:    10,
	}
)

Functions

func CheckPodError

func CheckPodError(ctx context.Context, log util.Logger, client client.Client, sts *appsv1.StatefulSet) (bool, error)

CheckPodError checks if the pod of the given StatefulSet have permanent errors preventing it from starting.

func ProjectVolumes

func ProjectVolumes(volumes []corev1.Volume, volumeMounts []corev1.VolumeMount) ([]corev1.Volume, []corev1.VolumeMount, error)

ProjectVolumes replaces volumes with the same mount path with a single projected volume.

Types

type LoggerConfig

type LoggerConfig struct {
	Console    bool   `yaml:"console"`
	Level      string `yaml:"level"`
	Formatting struct {
		Type string `yaml:"type"`
	} `yaml:"formatting,omitempty"`
	// File logging settings
	Log      string `yaml:"log,omitempty"`
	ErrorLog string `yaml:"errorlog,omitempty"`
	Size     string `yaml:"size,omitempty"`
	Count    int64  `yaml:"count,omitempty"`
}

LoggerConfig represents the logger configuration in YAML format.

func GenerateLoggerConfig

func GenerateLoggerConfig(spec v1.LoggerConfig, basePath string, service string) LoggerConfig

GenerateLoggerConfig generates a LoggerConfig from the given LoggerConfig spec.

type OpenSSLConfig

type OpenSSLConfig struct {
	Server OpenSSLParams `yaml:"server,omitempty"`
	Client OpenSSLParams `yaml:"client,omitempty"`
}

OpenSSLConfig represents the server OpenSSL configuration in YAML format.

type OpenSSLParams

type OpenSSLParams struct {
	CertificateFile     string `yaml:"certificateFile"`
	PrivateKeyFile      string `yaml:"privateKeyFile"`
	CAConfig            string `yaml:"caConfig"`
	VerificationMode    string `yaml:"verificationMode"`
	DisableProtocols    string `yaml:"disableProtocols"`
	PreferServerCiphers bool   `yaml:"preferServerCiphers"`
}

OpenSSLParams represents OpenSSL parameters in YAML format.

type PrometheusConfig

type PrometheusConfig struct {
	Endpoint            string `yaml:"endpoint"`
	Port                uint16 `yaml:"port"`
	Metrics             bool   `yaml:"metrics"`
	Events              bool   `yaml:"events"`
	AsynchronousMetrics bool   `yaml:"asynchronous_metrics"`
}

PrometheusConfig represents the Prometheus configuration in YAML format.

func DefaultPrometheusConfig

func DefaultPrometheusConfig(port uint16) PrometheusConfig

DefaultPrometheusConfig returns the default Prometheus configuration for the given port.

type ReplicaUpdateInput added in v0.0.3

type ReplicaUpdateInput struct {
	ExistingSTS           *appsv1.StatefulSet
	DesiredConfigMap      *corev1.ConfigMap
	DesiredSTS            *appsv1.StatefulSet
	HasError              bool
	ConfigurationRevision string
	StatefulSetRevision   string
	BreakingSTSVersion    semver.Version
	DataVolumeClaimSpec   *corev1.PersistentVolumeClaimSpec
}

ReplicaUpdateInput contains the parameters needed to reconcile a StatefulSet for a replica.

type ReplicaUpdateStage

type ReplicaUpdateStage int

ReplicaUpdateStage represents the stage of updating a ClickHouse replica. Used in reconciliation process.

const (
	StageUpToDate ReplicaUpdateStage = iota
	StageHasDiff
	StageNotReadyUpToDate
	StageUpdating
	StageError
	StageNotExists
)

func (ReplicaUpdateStage) String

func (s ReplicaUpdateStage) String() string

type ResourceReconcilerBase

type ResourceReconcilerBase[
	ClusterStatus any,
	Cluster clusterObject[ClusterStatus],
	ReplicaID replicaID,
	ReplicaState any,
] struct {
	Cluster Cluster
	// Should be populated by reconcileActiveReplicaStatus.
	ReplicaState map[ReplicaID]ReplicaState
	// contains filtered or unexported fields
}

ResourceReconcilerBase provides a base class for cluster reconcilers. It is expected to be embedded in specific reconcilers that hold reconciliation logic and state. It contains common methods for managing Cluster status and resources.

func NewReconcilerBase

func NewReconcilerBase[
	ClusterStatus any,
	Cluster clusterObject[ClusterStatus],
	ReplicaID replicaID,
	ReplicaState any,
](ctrl controller, cluster Cluster) ResourceReconcilerBase[ClusterStatus, Cluster, ReplicaID, ReplicaState]

NewReconcilerBase creates a new ResourceReconcilerBase instance.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) Create

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) Create(ctx context.Context, resource client.Object, action v1.EventAction) error

Create creates the given Kubernetes resource and emits events on failure.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) Delete

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) Delete(ctx context.Context, resource client.Object, action v1.EventAction) error

Delete deletes the given Kubernetes resource and emits events on failure.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) NewCondition

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) NewCondition(
	condType v1.ConditionType,
	status metav1.ConditionStatus,
	reason v1.ConditionReason,
	message string,
) metav1.Condition

NewCondition creates a new condition with the given parameters.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileConfigMap

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileConfigMap(
	ctx context.Context,
	log util.Logger,
	configMap *corev1.ConfigMap,
	action v1.EventAction,
) (bool, error)

ReconcileConfigMap reconciles a Kubernetes ConfigMap resource.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcilePodDisruptionBudget

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcilePodDisruptionBudget(
	ctx context.Context,
	log util.Logger,
	pdb *policyv1.PodDisruptionBudget,
	action v1.EventAction,
) (bool, error)

ReconcilePodDisruptionBudget reconciles a Kubernetes PodDisruptionBudget resource.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileReplicaResources added in v0.0.3

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileReplicaResources(
	ctx context.Context,
	log util.Logger,
	replicaID ReplicaID,
	input ReplicaUpdateInput,
) (*ctrlruntime.Result, error)

ReconcileReplicaResources reconciles a replica's ConfigMap, StatefulSet and PVC. Handling Pod restarts on config changes.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileService

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) ReconcileService(
	ctx context.Context,
	log util.Logger,
	service *corev1.Service,
	action v1.EventAction,
) (bool, error)

ReconcileService reconciles a Kubernetes Service resource.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) Replica

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) Replica(id ReplicaID) S

Replica returns the state of the replica with the given ID.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) SetCondition

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) SetCondition(log util.Logger, cond metav1.Condition) bool

SetCondition sets a single condition in the CRD status conditions.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) SetConditions

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) SetConditions(
	log util.Logger,
	conditions []metav1.Condition,
) bool

SetConditions sets the given conditions in the CRD status conditions.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) SetReplica

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) SetReplica(id ReplicaID, state S) bool

SetReplica sets the state of the replica with the given ID.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) Update

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) Update(ctx context.Context, resource client.Object, action v1.EventAction) error

Update updates the given Kubernetes resource and emits events on failure.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdatePVC

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdatePVC(
	ctx context.Context,
	log util.Logger,
	id ReplicaID,
	volumeSpec corev1.PersistentVolumeClaimSpec,
	action v1.EventAction,
) error

UpdatePVC updates the PersistentVolumeClaim for the given replica ID if it exists and differs from the provided spec.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdateUpgradeCondition added in v0.0.3

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdateUpgradeCondition(
	ctx context.Context,
	log controllerutil.Logger,
	probe VersionProbeResult,
	upgradeChannel string,
) error

UpdateUpgradeCondition checks for available upgrades and sets the VersionUpgraded condition.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdateVersionSyncCondition added in v0.0.3

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpdateVersionSyncCondition(
	ctx context.Context,
	log controllerutil.Logger,
	probe VersionProbeResult,
	replicaVersions map[string]string,
	isUpdating bool,
) error

UpdateVersionSyncCondition sets the VersionInSync condition based on the probe result and replica versions.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertCondition

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertCondition(
	ctx context.Context,
	log util.Logger,
	condition metav1.Condition,
) (bool, error)

UpsertCondition upserts the given condition into the CRD status conditions. Returns true if the condition was changed. Useful to precise detect if condition transition happened.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertConditionAndSendEvent

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertConditionAndSendEvent(
	ctx context.Context,
	log util.Logger,
	condition metav1.Condition,
	eventType string,
	eventReason v1.EventReason,
	eventAction v1.EventAction,
	eventMessageFormat string,
	eventMessageArgs ...any,
) (bool, error)

UpsertConditionAndSendEvent upserts the given condition into the CRD status conditions. Sends an event if the condition was changed.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertStatus

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) UpsertStatus(
	ctx context.Context,
	log util.Logger,
) error

UpsertStatus upserts the current status of the Cluster into the CRD status.

func (*ResourceReconcilerBase[Status, T, ReplicaID, S]) VersionProbe added in v0.0.3

func (r *ResourceReconcilerBase[Status, T, ReplicaID, S]) VersionProbe(
	ctx context.Context,
	log controllerutil.Logger,
	cfg VersionProbeConfig,
) (VersionProbeResult, error)

VersionProbe manages a one-time Job to detect the version from a container image. Returns the version string when available, or empty string if the Job is pending/running.

type VersionProbeConfig added in v0.0.3

type VersionProbeConfig struct {
	// Name of the binary to run.
	Binary string
	// Labels to apply to the Job, inherited from the cluster spec.
	Labels map[string]string
	// Annotations to apply to the Job, inherited from the cluster spec.
	Annotations map[string]string
	// PodTemplate to apply to the Job, inherited from the cluster spec.
	PodTemplate v1.PodTemplateSpec
	// ContainerTemplate to apply to the Job, inherited from the cluster spec.
	ContainerTemplate v1.ContainerTemplateSpec
}

VersionProbeConfig holds parameters for the version probe Job.

type VersionProbeResult added in v0.0.3

type VersionProbeResult struct {
	// Version is the detected version string, empty if not yet available.
	Version string
	// Pending is true when the Job is still running or being created.
	Pending bool
	// Err if version probe failed it contains the error.
	Err error
}

VersionProbeResult holds the outcome of a version probe reconciliation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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