Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentinel exporter #207

Merged
merged 8 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
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 @@ -24,37 +24,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 @@ -69,6 +70,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
exproter:
shonge marked this conversation as resolved.
Show resolved Hide resolved
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
49 changes: 40 additions & 9 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ func generateRedisStatefulSet(rf *redisfailoverv1.RedisFailover, labels map[stri
Annotations: rf.Spec.Redis.PodAnnotations,
},
Spec: corev1.PodSpec{
Affinity: getAffinity(rf.Spec.Redis.Affinity, labels),
Tolerations: rf.Spec.Redis.Tolerations,
NodeSelector: rf.Spec.Redis.NodeSelector,
SecurityContext: getSecurityContext(rf.Spec.Redis.SecurityContext),
Affinity: getAffinity(rf.Spec.Redis.Affinity, labels),
Tolerations: rf.Spec.Redis.Tolerations,
NodeSelector: rf.Spec.Redis.NodeSelector,
SecurityContext: getSecurityContext(rf.Spec.Redis.SecurityContext),
ImagePullSecrets: rf.Spec.Redis.ImagePullSecrets,
Containers: []corev1.Container{
{
Expand Down Expand Up @@ -279,7 +279,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 All @@ -297,10 +297,10 @@ func generateSentinelDeployment(rf *redisfailoverv1.RedisFailover, labels map[st
Annotations: rf.Spec.Sentinel.PodAnnotations,
},
Spec: corev1.PodSpec{
Affinity: getAffinity(rf.Spec.Sentinel.Affinity, labels),
Tolerations: rf.Spec.Sentinel.Tolerations,
NodeSelector: rf.Spec.Sentinel.NodeSelector,
SecurityContext: getSecurityContext(rf.Spec.Sentinel.SecurityContext),
Affinity: getAffinity(rf.Spec.Sentinel.Affinity, labels),
Tolerations: rf.Spec.Sentinel.Tolerations,
NodeSelector: rf.Spec.Sentinel.NodeSelector,
SecurityContext: getSecurityContext(rf.Spec.Sentinel.SecurityContext),
ImagePullSecrets: rf.Spec.Sentinel.ImagePullSecrets,
InitContainers: []corev1.Container{
{
Expand Down Expand Up @@ -404,6 +404,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 @@ -486,6 +491,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