Browse Source

add timeouts to crd, add multiport to services

master
Vladimir Smagin 1 year ago
parent
commit
e1932d0f0a
Signed by: 21h GPG Key ID: 13BCE12E5618F071
4 changed files with 34 additions and 19 deletions
  1. +5
    -3
      pkg/apis/blindage/v1alpha1/redis_types.go
  2. +10
    -8
      pkg/controller/manifests/manifest_service.go
  3. +2
    -2
      pkg/controller/redis/reconcile.go
  4. +17
    -6
      pkg/controller/redis/redis_controller.go

+ 5
- 3
pkg/apis/blindage/v1alpha1/redis_types.go View File

@ -20,9 +20,11 @@ type RedisSpec struct {
PersistentVolumeSize resource.Quantity `json:"persistentVolumeSize,omitempty"` // default 1Gi
// haproxy
UseHAProxy bool `json:"useHAProxy,omitempty"` // set true to activate HAProxy deployment
HAProxyImage string `json:"haproxyImage,omitempty"` // override default haproxy:1.9.4-alpine
HAProxyReplicas *int32 `json:"haproxyReplicas,omitempty"` // override default 1
UseHAProxy bool `json:"useHAProxy,omitempty"` // set true to activate HAProxy deployment
HAProxyImage string `json:"haproxyImage,omitempty"` // override default haproxy:1.9.4-alpine
HAProxyReplicas *int32 `json:"haproxyReplicas,omitempty"` // override default 1
HAProxyTimeoutServer int `json:"haproxyTimeoutServer,omitempty"` // default 30
HAProxyTimeoutClient int `json:"haproxyTimeoutClient,omitempty"` // default 30
// manage resources
PodRequests *v1.ResourceList `json:"podRequests,omitempty"`


+ 10
- 8
pkg/controller/manifests/manifest_service.go View File

@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)
func GenerateService(cr *blindagev1alpha1.Redis, serviceName, portName string, portNum int32, labels map[string]string) corev1.Service {
func GenerateService(cr *blindagev1alpha1.Redis, serviceName string, ports map[string]int32, labels map[string]string) corev1.Service {
labelsComplete := MergeLabels(BaseLabels(cr), labels)
@ -22,13 +22,15 @@ func GenerateService(cr *blindagev1alpha1.Redis, serviceName, portName string, p
service.Spec.Type = corev1.ServiceTypeClusterIP
service.Spec.Ports = []corev1.ServicePort{
{
Name: portName,
Port: portNum,
Protocol: corev1.ProtocolTCP,
TargetPort: intstr.FromString(portName),
},
for portName, portNum := range ports {
service.Spec.Ports = []corev1.ServicePort{
{
Name: portName,
Port: portNum,
Protocol: corev1.ProtocolTCP,
TargetPort: intstr.FromString(portName),
},
}
}
service.Spec.Selector = labelsComplete


+ 2
- 2
pkg/controller/redis/reconcile.go View File

@ -55,10 +55,10 @@ func (r *ReconcileRedis) ReconcileConfigmap(reqLogger logr.Logger, cr *blindagev
}
// ReconcileService one function to reconcile all services
func (r *ReconcileRedis) ReconcileService(reqLogger logr.Logger, cr *blindagev1alpha1.Redis, serviceName, portName string, portNum int32, selector map[string]string) (reconcile.Result, error) {
func (r *ReconcileRedis) ReconcileService(reqLogger logr.Logger, cr *blindagev1alpha1.Redis, serviceName string, ports map[string]int32, selector map[string]string) (reconcile.Result, error) {
// reconcile Service
newService := manifests.GenerateService(cr, serviceName, portName, portNum, selector)
newService := manifests.GenerateService(cr, serviceName, ports, selector)
if err := controllerutil.SetControllerReference(cr, &newService, r.scheme); err != nil {
raven.CaptureErrorAndWait(err, nil)


+ 17
- 6
pkg/controller/redis/redis_controller.go View File

@ -158,7 +158,7 @@ fi
servicePortName := "sentinel"
servicePort := int32(26379)
serviceSelector := map[string]string{"component": "sentinel"}
if _, err := r.ReconcileService(reqLogger, instance, serviceName, servicePortName, servicePort, serviceSelector); err != nil {
if _, err := r.ReconcileService(reqLogger, instance, serviceName, map[string]int32{servicePortName: servicePort}, serviceSelector); err != nil {
return reconcile.Result{}, err
}
@ -166,7 +166,7 @@ fi
servicePortName = "redis"
servicePort = int32(6379)
serviceSelector = map[string]string{"component": "redis"}
if _, err := r.ReconcileService(reqLogger, instance, serviceName, servicePortName, servicePort, serviceSelector); err != nil {
if _, err := r.ReconcileService(reqLogger, instance, serviceName, map[string]int32{servicePortName: servicePort}, serviceSelector); err != nil {
return reconcile.Result{}, err
}
@ -280,8 +280,9 @@ global
defaults
mode tcp
timeout connect 5s
timeout server 30s
timeout client 30s
timeout server %vs
timeout client %vs
option tcpka
listen stats
mode http
bind :9000
@ -304,7 +305,17 @@ backend bk_redis
tcp-check expect string +OK
`}
configHaproxyConfigData["haproxy.cfg"] = configHaproxyConfigData["haproxy.cfg"] + redisEndpoints
haproxyTimeoutServer := 30
if instance.Spec.HAProxyTimeoutServer > 0 {
haproxyTimeoutServer = instance.Spec.HAProxyTimeoutServer
}
haproxyTimeoutClient := 30
if instance.Spec.HAProxyTimeoutServer > 0 {
haproxyTimeoutClient = instance.Spec.HAProxyTimeoutServer
}
configHaproxyConfigData["haproxy.cfg"] = fmt.Sprintf(configHaproxyConfigData["haproxy.cfg"], haproxyTimeoutServer, haproxyTimeoutClient) + redisEndpoints
if _, err := r.ReconcileConfigmap(reqLogger, instance, configHaproxyConfigName, configHaproxyConfigData); err != nil {
return reconcile.Result{}, err
@ -321,7 +332,7 @@ backend bk_redis
servicePortName = "haproxy"
servicePort = int32(6379)
serviceSelector = map[string]string{"component": "haproxy"}
if _, err := r.ReconcileService(reqLogger, instance, serviceName, servicePortName, servicePort, serviceSelector); err != nil {
if _, err := r.ReconcileService(reqLogger, instance, serviceName, map[string]int32{servicePortName: servicePort, "stats": 9000}, serviceSelector); err != nil {
return reconcile.Result{}, err
}


Loading…
Cancel
Save