Skip to content

Commit

Permalink
Merge pull request #207 from shonge/sentinel_exporter
Browse files Browse the repository at this point in the history
Sentinel exporter
  • Loading branch information
ese authored Dec 5, 2019
2 parents d728950 + 664ad83 commit 79009d8
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 36 deletions.
1 change: 1 addition & 0 deletions api/redisfailover/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
const (
defaultRedisNumber = 3
defaultSentinelNumber = 3
defaultSentinelExporterImage = "leominov/redis_sentinel_exporter:1.3.0"
defaultExporterImage = "oliver006/redis_exporter:v0.33.0"
defaultImage = "redis:5.0-alpine"
)
Expand Down
62 changes: 35 additions & 27 deletions api/redisfailover/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,38 @@ type RedisFailoverSpec 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"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
CustomConfig []string `json:"customConfig,omitempty"`
Command []string `json:"command,omitempty"`
ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"`
Storage RedisStorage `json:"storage,omitempty"`
Exporter RedisExporter `json:"exporter,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,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"`
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"`
ShutdownConfigMap string `json:"shutdownConfigMap,omitempty"`
Storage RedisStorage `json:"storage,omitempty"`
Exporter RedisExporter `json:"exporter,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"securityContext,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"`
}

// 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"`
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"`
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"`
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"`
Exporter SentinelExporter `json:"exporter,omitempty"`
}

// AuthSettings contains settings about auth
Expand All @@ -70,6 +71,13 @@ type RedisExporter struct {
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
}

// SentinelExporter defines the specification for the sentinel exporter
type SentinelExporter struct {
Enabled bool `json:"enabled,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
}

// RedisStorage defines the structure used to store the Redis Data
type RedisStorage struct {
KeepAfterDeletion bool `json:"keepAfterDeletion,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/redisfailover/v1/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (r *RedisFailover) Validate() error {
r.Spec.Redis.Exporter.Image = defaultExporterImage
}

if r.Spec.Sentinel.Exporter.Image == "" {
r.Spec.Sentinel.Exporter.Image = defaultSentinelExporterImage
}

if len(r.Spec.Sentinel.CustomConfig) == 0 {
r.Spec.Sentinel.CustomConfig = defaultSentinelCustomConfig
}
Expand Down
5 changes: 4 additions & 1 deletion example/redisfailover/enable-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ metadata:
spec:
sentinel:
replicas: 3
exporter:
enabled: true
image: leominov/redis_sentinel_exporter:1.3.0
redis:
replicas: 3
exporter:
enabled: true
image: oliver006/redis_exporter:v0.33.0
image: oliver006/redis_exporter:v0.33.0
16 changes: 9 additions & 7 deletions operator/redisfailover/service/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const (

// variables refering to the redis exporter port
const (
exporterPort = 9121
exporterPortName = "http-metrics"
exporterContainerName = "redis-exporter"
exporterDefaultRequestCPU = "25m"
exporterDefaultLimitCPU = "50m"
exporterDefaultRequestMemory = "50Mi"
exporterDefaultLimitMemory = "100Mi"
exporterPort = 9121
sentinelExporterPort = 9355
exporterPortName = "http-metrics"
exporterContainerName = "redis-exporter"
sentinelExporterContainerName = "sentinel-exporter"
exporterDefaultRequestCPU = "25m"
exporterDefaultLimitCPU = "50m"
exporterDefaultRequestMemory = "50Mi"
exporterDefaultLimitMemory = "100Mi"
)

const (
Expand Down
33 changes: 32 additions & 1 deletion operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
selectorLabels := generateSelectorLabels(sentinelRoleName, rf.Name)
labels = util.MergeLabels(labels, selectorLabels)

return &appsv1.Deployment{
sd := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Expand Down Expand Up @@ -455,6 +455,11 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
},
},
}
if rf.Spec.Sentinel.Exporter.Enabled {
exporter := createSentinelExporterContainer(rf)
sd.Spec.Template.Spec.Containers = append(sd.Spec.Template.Spec.Containers, exporter)
}
return sd
}

func generatePodDisruptionBudget(name string, namespace string, labels map[string]string, ownerRefs []metav1.OwnerReference, minAvailable intstr.IntOrString) *policyv1beta1.PodDisruptionBudget {
Expand Down Expand Up @@ -537,6 +542,32 @@ func createRedisExporterContainer(rf *redisfailoverv1.RedisFailover) corev1.Cont
return container
}

func createSentinelExporterContainer(rf *redisfailoverv1.RedisFailover) corev1.Container {
container := corev1.Container{
Name: sentinelExporterContainerName,
Image: rf.Spec.Sentinel.Exporter.Image,
ImagePullPolicy: pullPolicy(rf.Spec.Sentinel.Exporter.ImagePullPolicy),
Ports: []corev1.ContainerPort{
{
Name: "metrics",
ContainerPort: sentinelExporterPort,
Protocol: corev1.ProtocolTCP,
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(exporterDefaultLimitCPU),
corev1.ResourceMemory: resource.MustParse(exporterDefaultLimitMemory),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(exporterDefaultRequestCPU),
corev1.ResourceMemory: resource.MustParse(exporterDefaultRequestMemory),
},
},
}
return container
}

func getAffinity(affinity *corev1.Affinity, labels map[string]string) *corev1.Affinity {
if affinity != nil {
return affinity
Expand Down

0 comments on commit 79009d8

Please sign in to comment.