Documentation
¶
Overview ¶
Package builder provides functions for constructing Kubernetes resources for Valkey operator managed instances.
Index ¶
- Constants
- func BuildClientService(v *vkov1.Valkey) *corev1.Service
- func BuildConfigMap(v *vkov1.Valkey) *corev1.ConfigMap
- func BuildHeadlessService(v *vkov1.Valkey) *corev1.Service
- func BuildReadService(v *vkov1.Valkey) *corev1.Service
- func BuildReplicaConfigMap(v *vkov1.Valkey) *corev1.ConfigMap
- func BuildSentinelCertificate(v *vkov1.Valkey) *unstructured.Unstructured
- func BuildSentinelConfigMap(v *vkov1.Valkey) *corev1.ConfigMap
- func BuildSentinelHeadlessService(v *vkov1.Valkey) *corev1.Service
- func BuildSentinelNetworkPolicy(v *vkov1.Valkey) *networkingv1.NetworkPolicy
- func BuildSentinelStatefulSet(v *vkov1.Valkey) *appsv1.StatefulSet
- func BuildStatefulSet(v *vkov1.Valkey) *appsv1.StatefulSet
- func BuildValkeyCertificate(v *vkov1.Valkey) *unstructured.Unstructured
- func BuildValkeyNetworkPolicy(v *vkov1.Valkey) *networkingv1.NetworkPolicy
- func CertificateOwnerRef(v *vkov1.Valkey) metav1.OwnerReference
- func ClientServiceName(v *vkov1.Valkey) string
- func ConfigMapName(v *vkov1.Valkey) string
- func DesiredServicePort(v *vkov1.Valkey) corev1.ServicePort
- func GenerateSentinelConf(v *vkov1.Valkey) string
- func GenerateValkeyConf(v *vkov1.Valkey, isReplica bool) string
- func MasterAddress(v *vkov1.Valkey) string
- func NetworkPolicyHasChanged(desired, current *networkingv1.NetworkPolicy) bool
- func NetworkPolicyName(v *vkov1.Valkey) string
- func ProbeCommand(v *vkov1.Valkey) []string
- func ReadServiceName(v *vkov1.Valkey) string
- func ReplicaConfigMapName(v *vkov1.Valkey) string
- func SentinelCertificateName(v *vkov1.Valkey) string
- func SentinelConfigMapName(v *vkov1.Valkey) string
- func SentinelMonitorName(v *vkov1.Valkey) string
- func SentinelNetworkPolicyName(v *vkov1.Valkey) string
- func SentinelStatefulSetHasChanged(desired, current *appsv1.StatefulSet) bool
- func SentinelTLSSecretName(v *vkov1.Valkey) string
- func ServicePort(v *vkov1.Valkey) int32
- func StatefulSetHasChanged(desired, current *appsv1.StatefulSet) bool
- func ValkeyCertificateName(v *vkov1.Valkey) string
- func ValkeyTLSSecretName(v *vkov1.Valkey) string
Constants ¶
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" )
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" )
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 )
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 ¶
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 ¶
BuildConfigMap builds the ConfigMap for Valkey configuration. In standalone mode or for the master in HA mode, isReplica should be false.
func BuildHeadlessService ¶
BuildHeadlessService builds the headless Service for StatefulSet DNS resolution.
func BuildReadService ¶
BuildReadService builds a read-only Service that routes to all Valkey pods (replicas + master). Useful for read-heavy workloads in HA mode.
func BuildReplicaConfigMap ¶
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 ¶
BuildSentinelConfigMap builds the ConfigMap for Sentinel configuration.
func BuildSentinelHeadlessService ¶
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 ¶
ClientServiceName returns the name for the client-facing Service.
func ConfigMapName ¶
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 ¶
GenerateSentinelConf generates the sentinel.conf content based on the CRD spec.
func GenerateValkeyConf ¶
GenerateValkeyConf generates the valkey.conf content based on the CRD spec. The isReplica parameter controls whether replicaof directives are included.
func MasterAddress ¶
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 ¶
NetworkPolicyName returns the name for the Valkey NetworkPolicy.
func ProbeCommand ¶
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 ¶
ReadServiceName returns the name for the read-only (replica) Service.
func ReplicaConfigMapName ¶
ReplicaConfigMapName returns the name for the replica Valkey ConfigMap (HA mode).
func SentinelCertificateName ¶
SentinelCertificateName returns the name of the Certificate resource for Sentinel pods.
func SentinelConfigMapName ¶
SentinelConfigMapName returns the name for the Sentinel ConfigMap.
func SentinelMonitorName ¶
SentinelMonitorName returns the name used for the `sentinel monitor` directive.
func SentinelNetworkPolicyName ¶
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 ¶
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 ¶
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 ¶
ValkeyCertificateName returns the name of the Certificate resource for Valkey pods.
func ValkeyTLSSecretName ¶
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.