Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions api/v1alpha1/valkeycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ type ValkeyClusterSpec struct {
// Override the default Valkey image
Image string `json:"image,omitempty"`

// Override the default Valkey exporter image
ExporterImage string `json:"exporterImage,omitempty"`
// Exporter Configuration options
// +optional
Exporter ExporterSpec `json:"exporter,omitempty"`

// The number of shards groups. Each shard group contains one primary and N replicas.
// +kubebuilder:validation:Minimum=1
Expand All @@ -45,10 +46,6 @@ type ValkeyClusterSpec struct {
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// Override resource requirements for the Valkey exporter container in each pod
// +optional
ExporterResources corev1.ResourceRequirements `json:"exporterResources,omitempty"`

// Tolerations to apply to the pods
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Expand All @@ -63,6 +60,19 @@ type ValkeyClusterSpec struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`
}

type ExporterSpec struct {
// Override the default Exporter image
Image string `json:"image,omitempty"`

// Override resource requirements for the Valkey exporter container in each pod
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// Enable or disable the exporter sidecar container
// +kubebuilder:default=true
Enabled bool `json:"enabled,omitempty"`
}

// ValkeyClusterStatus defines the observed state of ValkeyCluster.
type ValkeyClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
18 changes: 17 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 66 additions & 58 deletions config/crd/bases/valkey.io_valkeyclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -972,67 +972,75 @@ spec:
x-kubernetes-list-type: atomic
type: object
type: object
exporterImage:
description: Override the default Valkey exporter image
type: string
exporterResources:
description: Override resource requirements for the Valkey exporter
container in each pod
exporter:
description: Exporter Configuration options
properties:
claims:
description: |-
Claims lists the names of resources, defined in spec.resourceClaims,
that are used by this container.
enabled:
default: true
description: Enable or disable the exporter sidecar container
type: boolean
image:
description: Override the default Exporter image
type: string
resources:
description: Override resource requirements for the Valkey exporter
container in each pod
properties:
claims:
description: |-
Claims lists the names of resources, defined in spec.resourceClaims,
that are used by this container.

This field depends on the
DynamicResourceAllocation feature gate.
This field depends on the
DynamicResourceAllocation feature gate.

This field is immutable. It can only be set for containers.
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: |-
Name must match the name of one entry in pod.spec.resourceClaims of
the Pod where this field is used. It makes that resource available
inside a container.
type: string
request:
description: |-
Request is the name chosen for a request in the referenced claim.
If empty, everything from the claim is made available, otherwise
only the result of this request.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Limits describes the maximum amount of compute resources allowed.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Requests describes the minimum amount of compute resources required.
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
This field is immutable. It can only be set for containers.
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: |-
Name must match the name of one entry in pod.spec.resourceClaims of
the Pod where this field is used. It makes that resource available
inside a container.
type: string
request:
description: |-
Request is the name chosen for a request in the referenced claim.
If empty, everything from the claim is made available, otherwise
only the result of this request.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Limits describes the maximum amount of compute resources allowed.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Requests describes the minimum amount of compute resources required.
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
otherwise to an implementation-defined value. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
type: object
image:
Expand Down
48 changes: 48 additions & 0 deletions internal/controller/deployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package controller

import (
"context"

appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

valkeyv1 "valkey.io/valkey-operator/api/v1alpha1"
)

func (r *ValkeyClusterReconciler) upsertDeployment(ctx context.Context, cluster *valkeyv1.ValkeyCluster, shard int, salt string) error {

Check failure on line 15 in internal/controller/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

func (*ValkeyClusterReconciler).upsertDeployment is unused (unused)

Check failure on line 15 in internal/controller/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

func (*ValkeyClusterReconciler).upsertDeployment is unused (unused)
logger := log.FromContext(ctx)

existingDeployment := &appsv1.Deployment{}
err := r.Get(ctx, client.ObjectKey{Namespace: cluster.Namespace, Name: cluster.Name}, existingDeployment)
if err != nil {
if apierrors.IsNotFound(err) {
// Deployment does not exist, create it
newDeployment := r.deploymentForValkeyCluster(cluster, shard, salt)
logger.Info("Creating a new Deployment", "Deployment.Namespace", newDeployment.Namespace, "Deployment.Name", newDeployment.Name)
if err := r.Create(ctx, newDeployment); err != nil {
logger.Error(err, "Failed to create new Deployment", "Deployment.Namespace", newDeployment.Namespace, "Deployment.Name", newDeployment.Name)
return err
}
}
logger.Error(err, "Failed to get Deployment")
return err
}
// Deployment exists, update it if necessary
logger.Info("Deployment already exists, skipping creation", "Deployment.Namespace", existingDeployment.Namespace, "Deployment.Name", existingDeployment.Name)

return nil
}

func (r *ValkeyClusterReconciler) deploymentForValkeyCluster(cluster *valkeyv1.ValkeyCluster, shard int, salt string) *appsv1.Deployment {

Check failure on line 39 in internal/controller/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

func (*ValkeyClusterReconciler).deploymentForValkeyCluster is unused (unused)

Check failure on line 39 in internal/controller/deployment.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

func (*ValkeyClusterReconciler).deploymentForValkeyCluster is unused (unused)
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: cluster.Name,
Namespace: cluster.Namespace,
Labels: labels(cluster, shard, salt),
},
}
return deployment
}
35 changes: 35 additions & 0 deletions internal/controller/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package controller

import (
"fmt"
"maps"

valkeyv1 "valkey.io/valkey-operator/api/v1alpha1"
)

func labels(cluster *valkeyv1.ValkeyCluster, shard int, salt string) map[string]string {
if cluster.Labels == nil {
cluster.Labels = make(map[string]string)
}
l := maps.Clone(cluster.Labels)
l["app.kubernetes.io/name"] = "valkey"
l["app.kubernetes.io/instance"] = cluster.Name
l["app.kubernetes.io/managed-by"] = "valkey-operator"
l["app.kubernetes.io/part-of"] = "valkey"
l["app.kubernetes.io/component"] = "valkey-cluster"
if shard >= 0 {
l["valkey.io/shard"] = fmt.Sprintf("%d", shard)
}
if salt != "" {
l["valkey.io/salt"] = salt
}
return l
}

func l(cluster *valkeyv1.ValkeyCluster) map[string]string {
return labels(cluster, -1, "")
}

func annotations(cluster *valkeyv1.ValkeyCluster) map[string]string {
return maps.Clone(cluster.Annotations)
}
Loading
Loading