Skip to content

Commit

Permalink
Merge pull request #431 from pych/topology-spread-contraints
Browse files Browse the repository at this point in the history
[Feature]: Add topology spread constraints.
  • Loading branch information
ese authored Aug 31, 2022
2 parents fa8c5b9 + b685e84 commit 6662e1d
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 57 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ In order to have persistence, a `PersistentVolumeClaim` usage is allowed. The fu

You can use NodeAffinity and Tolerations to deploy Pods to isolated groups of Nodes. Examples are given for [node affinity](example/redisfailover/node-affinity.yaml), [pod anti affinity](example/redisfailover/pod-anti-affinity.yaml) and [tolerations](example/redisfailover/tolerations.yaml).

## Topology Spread Contraints

You can use the `topologySpreadContraints` to ensure the pods of a type(redis or sentinel) are evenly distributed across zones/nodes. Examples are for using [topology spread constraints](example/redisfailover/topology-spread-contraints.yaml). Further document on how `topologySpreadConstraints` work could be found [here](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/).

### Custom configurations

It is possible to configure both Redis and Sentinel. This is done with the `customConfig` option inside their spec. It is a list of configurations and their values. Example are given in the [custom config example file](example/redisfailover/custom-config.yaml).
Expand Down
98 changes: 50 additions & 48 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,60 @@ type RedisCommandRename struct {

// RedisSettings defines the specification of the redis cluster
type RedisSettings struct {
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Port int32 `json:"port,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
CustomCommandRenames []RedisCommandRename `json:"customCommandRenames,omitempty"`
Command []string `json:"command,omitempty"`
ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"`
Storage RedisStorage `json:"storage,omitempty"`
InitContainers []corev1.Container `json:"initContainers,omitempty"`
Exporter RedisExporter `json:"exporter,omitempty"`
ExtraContainers []corev1.Container `json:"extraContainers,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
HostNetwork bool `json:"hostNetwork,omitempty"`
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
TerminationGracePeriodSeconds int64 `json:"terminationGracePeriod,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Port int32 `json:"port,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
CustomCommandRenames []RedisCommandRename `json:"customCommandRenames,omitempty"`
Command []string `json:"command,omitempty"`
ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"`
Storage RedisStorage `json:"storage,omitempty"`
InitContainers []corev1.Container `json:"initContainers,omitempty"`
Exporter RedisExporter `json:"exporter,omitempty"`
ExtraContainers []corev1.Container `json:"extraContainers,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
HostNetwork bool `json:"hostNetwork,omitempty"`
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
TerminationGracePeriodSeconds int64 `json:"terminationGracePeriod,omitempty"`
}

// SentinelSettings defines the specification of the sentinel cluster
type SentinelSettings struct {
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
Command []string `json:"command,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
InitContainers []corev1.Container `json:"initContainers,omitempty"`
Exporter SentinelExporter `json:"exporter,omitempty"`
ExtraContainers []corev1.Container `json:"extraContainers,omitempty"`
ConfigCopy SentinelConfigCopy `json:"configCopy,omitempty"`
HostNetwork bool `json:"hostNetwork,omitempty"`
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
Command []string `json:"command,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
InitContainers []corev1.Container `json:"initContainers,omitempty"`
Exporter SentinelExporter `json:"exporter,omitempty"`
ExtraContainers []corev1.Container `json:"extraContainers,omitempty"`
ConfigCopy SentinelConfigCopy `json:"configCopy,omitempty"`
HostNetwork bool `json:"hostNetwork,omitempty"`
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// AuthSettings contains settings about auth
Expand Down
41 changes: 41 additions & 0 deletions example/redisfailover/topology-spread-contraints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: tsc
---
apiVersion: databases.spotahome.com/v1
kind: RedisFailover
metadata:
name: redis-tsc
namespace: tsc
spec:
redis:
topologySpreadConstraints:
- labelSelector:
matchLabels:
app.kubernetes.io/component: redis
maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- labelSelector:
matchLabels:
app.kubernetes.io/component: redis
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
sentinel:
replicas: 3
topologySpreadConstraints:
- labelSelector:
matchLabels:
app.kubernetes.io/component: sentinel
maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
- labelSelector:
matchLabels:
app.kubernetes.io/component: sentinel
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
Loading

0 comments on commit 6662e1d

Please sign in to comment.