builder

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package builder provides functions for constructing Kubernetes resources for Valkey operator managed instances.

Index

Constants

View Source
const (
	// TLSVolumeName is the name of the volume for TLS certificates.
	TLSVolumeName = "tls"

	// TLSMountPath is the mount path for TLS certificates inside containers.
	TLSMountPath = "/tls"

	// TLSPort is the TLS-enabled Valkey port.
	TLSPort = 16379

	// CertManagerAPIVersion is the API version for cert-manager Certificate resources.
	CertManagerAPIVersion = "cert-manager.io/v1"

	// CertManagerCertificateKind is the kind for cert-manager Certificate resources.
	CertManagerCertificateKind = "Certificate"
)
View Source
const (
	// ValkeyPort is the default Valkey server port.
	ValkeyPort = 6379

	// ValkeyConfigKey is the key used in the ConfigMap for the valkey configuration.
	ValkeyConfigKey = "valkey.conf"

	// DataDir is the directory where Valkey stores its data.
	DataDir = "/data"
)
View Source
const (
	// SentinelPort is the default Sentinel port.
	SentinelPort = 26379

	// SentinelConfigKey is the key used in the ConfigMap for sentinel configuration.
	SentinelConfigKey = "sentinel.conf"

	// SentinelContainerName is the name of the Sentinel container.
	SentinelContainerName = "sentinel"

	// SentinelConfigVolumeName is the name of the writable sentinel config volume.
	SentinelConfigVolumeName = "sentinel-config"

	// SentinelConfigMountPath is the mount path for the sentinel configuration.
	SentinelConfigMountPath = "/etc/sentinel"

	// SentinelDataDir is the working directory for Sentinel.
	SentinelDataDir = "/data"

	// SentinelQuorum is the default number of Sentinels that need to agree for failover.
	SentinelQuorum = 2

	// SentinelDownAfterMilliseconds is the default time before a master is considered down.
	SentinelDownAfterMilliseconds = 5000

	// SentinelFailoverTimeout is the default failover timeout.
	SentinelFailoverTimeout = 60000

	// SentinelParallelSyncs is the number of replicas that can sync simultaneously after failover.
	SentinelParallelSyncs = 1
)
View Source
const (
	// ValkeyContainerName is the name of the main Valkey container.
	ValkeyContainerName = "valkey"

	// ConfigVolumeName is the name of the volume for the master Valkey configuration (readonly).
	ConfigVolumeName = "config"

	// ReplicaConfigVolumeName is the name of the volume for the replica configuration (readonly, HA mode).
	ReplicaConfigVolumeName = "replica-config"

	// WritableConfigVolumeName is the name of the writable config volume (HA mode, populated by init container).
	WritableConfigVolumeName = "writable-config"

	// DataVolumeName is the name of the volume for persistent data.
	DataVolumeName = "data"

	// ConfigMountPath is the mount path for the master Valkey configuration (readonly).
	ConfigMountPath = "/etc/valkey"

	// ReplicaConfigMountPath is the mount path for the replica configuration (readonly, HA mode).
	ReplicaConfigMountPath = "/etc/valkey-replica"

	// WritableConfigMountPath is the mount path for the writable config (HA mode).
	WritableConfigMountPath = "/etc/valkey-active"

	// AuthSecretEnvName is the environment variable name used to inject the Valkey password.
	AuthSecretEnvName = "VALKEY_PASSWORD"
)

Variables

This section is empty.

Functions

func BuildClientService

func BuildClientService(v *vkov1.Valkey) *corev1.Service

BuildClientService builds the client-facing Service that points to the master pod. In standalone mode, it simply selects all Valkey pods. In HA mode, it uses selector labels (traffic is distributed across all pods). A dedicated read service can be used for read replicas.

func BuildConfigMap

func BuildConfigMap(v *vkov1.Valkey) *corev1.ConfigMap

BuildConfigMap builds the ConfigMap for Valkey configuration. In standalone mode or for the master in HA mode, isReplica should be false.

func BuildHeadlessService

func BuildHeadlessService(v *vkov1.Valkey) *corev1.Service

BuildHeadlessService builds the headless Service for StatefulSet DNS resolution.

func BuildReadService

func BuildReadService(v *vkov1.Valkey) *corev1.Service

BuildReadService builds a read-only Service that routes to all Valkey pods (replicas + master). Useful for read-heavy workloads in HA mode.

func BuildReplicaConfigMap

func BuildReplicaConfigMap(v *vkov1.Valkey) *corev1.ConfigMap

BuildReplicaConfigMap builds the ConfigMap for Valkey replica configuration (HA mode). It includes the `replicaof` directive pointing to the master.

func BuildSentinelCertificate

func BuildSentinelCertificate(v *vkov1.Valkey) *unstructured.Unstructured

BuildSentinelCertificate builds the cert-manager Certificate resource for Sentinel pods.

func BuildSentinelConfigMap

func BuildSentinelConfigMap(v *vkov1.Valkey) *corev1.ConfigMap

BuildSentinelConfigMap builds the ConfigMap for Sentinel configuration.

func BuildSentinelHeadlessService

func BuildSentinelHeadlessService(v *vkov1.Valkey) *corev1.Service

BuildSentinelHeadlessService builds the headless Service for Sentinel StatefulSet DNS resolution.

func BuildSentinelNetworkPolicy

func BuildSentinelNetworkPolicy(v *vkov1.Valkey) *networkingv1.NetworkPolicy

BuildSentinelNetworkPolicy builds the NetworkPolicy that allows Valkey→Sentinel and Sentinel↔Sentinel traffic. It restricts ingress to the Sentinel port from Valkey and Sentinel pods.

func BuildSentinelStatefulSet

func BuildSentinelStatefulSet(v *vkov1.Valkey) *appsv1.StatefulSet

BuildSentinelStatefulSet builds the StatefulSet for Sentinel instances.

func BuildStatefulSet

func BuildStatefulSet(v *vkov1.Valkey) *appsv1.StatefulSet

BuildStatefulSet builds the StatefulSet for Valkey instances.

func BuildValkeyCertificate

func BuildValkeyCertificate(v *vkov1.Valkey) *unstructured.Unstructured

BuildValkeyCertificate builds the cert-manager Certificate resource for Valkey pods.

func BuildValkeyNetworkPolicy

func BuildValkeyNetworkPolicy(v *vkov1.Valkey) *networkingv1.NetworkPolicy

BuildValkeyNetworkPolicy builds the NetworkPolicy that allows Valkey↔Valkey and Sentinel→Valkey traffic within the cluster. It restricts ingress to the Valkey port from other Valkey pods and Sentinel pods.

func CertificateOwnerRef

func CertificateOwnerRef(v *vkov1.Valkey) metav1.OwnerReference

CertificateOwnerRef returns an OwnerReference for setting on Certificate resources.

func ClientServiceName

func ClientServiceName(v *vkov1.Valkey) string

ClientServiceName returns the name for the client-facing Service.

func ConfigMapName

func ConfigMapName(v *vkov1.Valkey) string

ConfigMapName returns the name for the Valkey ConfigMap.

func DesiredServicePort

func DesiredServicePort(v *vkov1.Valkey) corev1.ServicePort

DesiredServicePort returns the port spec for Services, accounting for TLS.

func GenerateSentinelConf

func GenerateSentinelConf(v *vkov1.Valkey) string

GenerateSentinelConf generates the sentinel.conf content based on the CRD spec.

func GenerateValkeyConf

func GenerateValkeyConf(v *vkov1.Valkey, isReplica bool) string

GenerateValkeyConf generates the valkey.conf content based on the CRD spec. The isReplica parameter controls whether replicaof directives are included.

func MasterAddress

func MasterAddress(v *vkov1.Valkey) string

MasterAddress returns the DNS address of the master pod (pod-0 of the StatefulSet). Used for `replicaof` configuration in replica pods.

func NetworkPolicyHasChanged

func NetworkPolicyHasChanged(desired, current *networkingv1.NetworkPolicy) bool

NetworkPolicyHasChanged returns true if the desired NetworkPolicy differs from the current one.

func NetworkPolicyName

func NetworkPolicyName(v *vkov1.Valkey) string

NetworkPolicyName returns the name for the Valkey NetworkPolicy.

func ProbeCommand

func ProbeCommand(v *vkov1.Valkey) []string

ProbeCommand returns the probe command, accounting for TLS and auth. When auth is enabled, the probe uses a shell command to expand the VALKEY_PASSWORD environment variable for the -a flag.

func ReadServiceName

func ReadServiceName(v *vkov1.Valkey) string

ReadServiceName returns the name for the read-only (replica) Service.

func ReplicaConfigMapName

func ReplicaConfigMapName(v *vkov1.Valkey) string

ReplicaConfigMapName returns the name for the replica Valkey ConfigMap (HA mode).

func SentinelCertificateName

func SentinelCertificateName(v *vkov1.Valkey) string

SentinelCertificateName returns the name of the Certificate resource for Sentinel pods.

func SentinelConfigMapName

func SentinelConfigMapName(v *vkov1.Valkey) string

SentinelConfigMapName returns the name for the Sentinel ConfigMap.

func SentinelMonitorName

func SentinelMonitorName(v *vkov1.Valkey) string

SentinelMonitorName returns the name used for the `sentinel monitor` directive.

func SentinelNetworkPolicyName

func SentinelNetworkPolicyName(v *vkov1.Valkey) string

SentinelNetworkPolicyName returns the name for the Sentinel NetworkPolicy.

func SentinelStatefulSetHasChanged

func SentinelStatefulSetHasChanged(desired, current *appsv1.StatefulSet) bool

SentinelStatefulSetHasChanged returns true if the live Sentinel StatefulSet differs from desired.

func SentinelTLSSecretName

func SentinelTLSSecretName(v *vkov1.Valkey) string

SentinelTLSSecretName returns the name of the Secret that holds TLS certs for Sentinel. When cert-manager is used, a separate Certificate is created for Sentinel. When a user-provided secret is used, the same secret is shared.

func ServicePort

func ServicePort(v *vkov1.Valkey) int32

ServicePort returns the Valkey client port, accounting for TLS configuration.

func StatefulSetHasChanged

func StatefulSetHasChanged(desired, current *appsv1.StatefulSet) bool

StatefulSetHasChanged returns true if the live StatefulSet differs from the desired spec in ways that require an update (image, replicas, resources, config).

func ValkeyCertificateName

func ValkeyCertificateName(v *vkov1.Valkey) string

ValkeyCertificateName returns the name of the Certificate resource for Valkey pods.

func ValkeyTLSSecretName

func ValkeyTLSSecretName(v *vkov1.Valkey) string

ValkeyTLSSecretName returns the name of the Secret that holds TLS certs for Valkey. When cert-manager is used, this is the Secret created by the Certificate resource. When a user-provided secret is used, this returns the user's secret name.

Types

This section is empty.

Jump to

Keyboard shortcuts

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