Skip to content
Merged
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
10 changes: 3 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 40005,
"port": 40000,
"host": "127.0.0.1",
"trace": "verbose",
"env": {
"WATCH_NAMESPACE": "default",
"KUBERNETES_CONFIG": "${HOME}/.kube/config",
}
"trace": "verbose"
}
]
}
}
242 changes: 112 additions & 130 deletions Makefile

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions api/v1/redkeycluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ func (redkeyCluster RedkeyCluster) NamespacedName() types.NamespacedName {
}
}

// GetLabels returns the labels from Spec.Labels or an empty map if nil.
func (redkeyCluster RedkeyCluster) GetLabels() map[string]string {
if redkeyCluster.Spec.Labels != nil {
return *redkeyCluster.Spec.Labels
}
return map[string]string{}
}

// RedkeyClusterSpec defines the desired state of RedkeyCluster.
// +kubebuilder:validation:XValidation:rule="self.ephemeral || has(self.storage)", message="Ephemeral or storage must be set"
// +kubebuilder:validation:XValidation:rule="!(self.ephemeral && has(self.storage))", message="Ephemeral and storage cannot be combined"
Expand Down
2 changes: 1 addition & 1 deletion controllers/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *RedkeyClusterReconciler) checkAndCreateStatefulSet(ctx context.Context,
if errors.IsNotFound(err) {
// Create StatefulSet
r.logInfo(redkeyCluster.NamespacedName(), "Creating statefulset")
statefulSet, createSsetError = r.createStatefulSet(ctx, req, redkeyCluster.Spec, *redkeyCluster.Spec.Labels, configMap)
statefulSet, createSsetError = r.createStatefulSet(ctx, req, redkeyCluster.Spec, redkeyCluster.GetLabels(), configMap)
if createSsetError != nil {
r.logError(redkeyCluster.NamespacedName(), createSsetError, "Error when creating StatefulSet")
return immediateRequeue, createSsetError
Expand Down
4 changes: 2 additions & 2 deletions controllers/pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *RedkeyClusterReconciler) updatePodDisruptionBudget(ctx context.Context,
refreshedPdb.Spec.MaxUnavailable = nil
refreshedPdb.Spec.MinAvailable = &redkeyCluster.Spec.Pdb.PdbSizeAvailable
}
refreshedPdb.ObjectMeta.Labels = *redkeyCluster.Spec.Labels
refreshedPdb.ObjectMeta.Labels = redkeyCluster.GetLabels()
refreshedPdb.Spec.Selector.MatchLabels = map[string]string{redis.RedkeyClusterLabel: redkeyCluster.ObjectMeta.Name, r.getStatefulSetSelectorLabel(redkeyCluster): "redis"}

var updateErr = r.Client.Update(ctx, refreshedPdb)
Expand All @@ -86,7 +86,7 @@ func (r *RedkeyClusterReconciler) checkAndManagePodDisruptionBudget(ctx context.
if err != nil {
if errors.IsNotFound(err) {
// Create PodDisruptionBudget
pdb := r.createPodDisruptionBudget(req, redkeyCluster, *redkeyCluster.Spec.Labels)
pdb := r.createPodDisruptionBudget(req, redkeyCluster, redkeyCluster.GetLabels())
ctrl.SetControllerReference(redkeyCluster, pdb, r.Scheme)
pdbCreateErr := r.Client.Create(ctx, pdb)
if pdbCreateErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion controllers/redis_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ func (r *RedkeyClusterReconciler) upgradeClusterConfigurationUpdate(ctx context.
}

// RedkeyCluster .Spec.Labels
mergedLabels := *redkeyCluster.Spec.Labels
mergedLabels := redkeyCluster.GetLabels()
defaultLabels := map[string]string{
redis.RedkeyClusterLabel: redkeyCluster.Name,
r.getStatefulSetSelectorLabel(redkeyCluster): "redis",
Expand Down
62 changes: 52 additions & 10 deletions controllers/robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *RedkeyClusterReconciler) handleRobinConfig(ctx context.Context, req ctr
}

// Create Robin ConfigMap
newConfigMap := r.createRobinConfigMap(req, redkeyCluster.Spec, *redkeyCluster.Spec.Labels)
newConfigMap := r.createRobinConfigMap(req, redkeyCluster.Spec, redkeyCluster.GetLabels())
r.createRobinObject(ctx, newConfigMap, redkeyCluster, "configmap")
return nil
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (r *RedkeyClusterReconciler) handleRobinDeployment(ctx context.Context, req
}

// Create Robin Deployment
robinDeployment := r.createRobinDeployment(req, redkeyCluster, *redkeyCluster.Spec.Labels)
robinDeployment := r.createRobinDeployment(req, redkeyCluster, redkeyCluster.GetLabels())
r.createRobinObject(ctx, robinDeployment, redkeyCluster, "deployment")
return
}
Expand Down Expand Up @@ -255,15 +255,57 @@ func (r *RedkeyClusterReconciler) createRobinDeployment(req ctrl.Request, redkey
}

func (r *RedkeyClusterReconciler) getRobinConfiguration(req ctrl.Request, spec redkeyv1.RedkeyClusterSpec) robin.Configuration {
// Set default values for Robin configuration
reconcilerInterval := 30
reconcilerCleanupInterval := 30
clusterHealthProbe := 60
clusterHealingTime := 60
clusterMaxRetries := 10
clusterBackOff := 10
metricsInterval := 60
var metricsRedisInfoKeys []string

// Override with provided values if they exist
if spec.Robin != nil && spec.Robin.Config != nil {
if spec.Robin.Config.Reconciler != nil {
if spec.Robin.Config.Reconciler.IntervalSeconds != nil {
reconcilerInterval = *spec.Robin.Config.Reconciler.IntervalSeconds
}
if spec.Robin.Config.Reconciler.OperationCleanUpIntervalSeconds != nil {
reconcilerCleanupInterval = *spec.Robin.Config.Reconciler.OperationCleanUpIntervalSeconds
}
}
if spec.Robin.Config.Cluster != nil {
if spec.Robin.Config.Cluster.HealthProbePeriodSeconds != nil {
clusterHealthProbe = *spec.Robin.Config.Cluster.HealthProbePeriodSeconds
}
if spec.Robin.Config.Cluster.HealingTimeSeconds != nil {
clusterHealingTime = *spec.Robin.Config.Cluster.HealingTimeSeconds
}
if spec.Robin.Config.Cluster.MaxRetries != nil {
clusterMaxRetries = *spec.Robin.Config.Cluster.MaxRetries
}
if spec.Robin.Config.Cluster.BackOff != nil {
clusterBackOff = *spec.Robin.Config.Cluster.BackOff
}
}
if spec.Robin.Config.Metrics != nil {
if spec.Robin.Config.Metrics.IntervalSeconds != nil {
metricsInterval = *spec.Robin.Config.Metrics.IntervalSeconds
}
metricsRedisInfoKeys = spec.Robin.Config.Metrics.RedisInfoKeys
}
}

config := robin.Configuration{
Metadata: map[string]string{
"namespace": req.Namespace,
},
Redis: robin.RedisConfig{
Standalone: false,
Reconciler: robin.RedisReconcilerConfig{
IntervalSeconds: *spec.Robin.Config.Reconciler.IntervalSeconds,
OperationCleanupIntervalSeconds: *spec.Robin.Config.Reconciler.OperationCleanUpIntervalSeconds,
IntervalSeconds: reconcilerInterval,
OperationCleanupIntervalSeconds: reconcilerCleanupInterval,
},
Cluster: robin.RedkeyClusterConfig{
Namespace: req.Namespace,
Expand All @@ -272,14 +314,14 @@ func (r *RedkeyClusterReconciler) getRobinConfiguration(req ctrl.Request, spec r
ReplicasPerPrimary: int(spec.ReplicasPerPrimary),
Status: redkeyv1.RobinStatusUnknown,
Ephemeral: spec.Ephemeral,
HealthProbePeriodSeconds: *spec.Robin.Config.Cluster.HealthProbePeriodSeconds,
HealingTimeSeconds: *spec.Robin.Config.Cluster.HealingTimeSeconds,
MaxRetries: *spec.Robin.Config.Cluster.MaxRetries,
BackOff: time.Duration(*spec.Robin.Config.Cluster.BackOff) * time.Second,
HealthProbePeriodSeconds: clusterHealthProbe,
HealingTimeSeconds: clusterHealingTime,
MaxRetries: clusterMaxRetries,
BackOff: time.Duration(clusterBackOff) * time.Second,
},
Metrics: robin.RedisMetricsConfig{
IntervalSeconds: *spec.Robin.Config.Metrics.IntervalSeconds,
RedisInfoKeys: spec.Robin.Config.Metrics.RedisInfoKeys,
IntervalSeconds: metricsInterval,
RedisInfoKeys: metricsRedisInfoKeys,
},
},
}
Expand Down
Loading