From 8892165179842650d664f9b028fd4e160f8c570b Mon Sep 17 00:00:00 2001 From: yangw Date: Tue, 24 Oct 2023 02:24:56 +0800 Subject: [PATCH] [Fix] : setup label redis_setup_type to sentinel (#679) * fix label redis_setup_type to sentinel Signed-off-by: drivebyer * add test Signed-off-by: drivebyer --------- Signed-off-by: drivebyer Signed-off-by: Matt Robinson --- k8sutils/redis-sentinel.go | 4 +- .../setup/redis-sentinel/00-install.yaml | 7 ++ .../setup/redis-sentinel/ready-sts.yaml | 35 +++++++ .../setup/redis-sentinel/ready-svc.yaml | 96 +++++++++++++++++++ .../setup/redis-sentinel/sentinel.yaml | 22 +++++ 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/v1beta2/setup/redis-sentinel/00-install.yaml create mode 100644 tests/e2e/v1beta2/setup/redis-sentinel/ready-sts.yaml create mode 100644 tests/e2e/v1beta2/setup/redis-sentinel/ready-svc.yaml create mode 100644 tests/e2e/v1beta2/setup/redis-sentinel/sentinel.yaml diff --git a/k8sutils/redis-sentinel.go b/k8sutils/redis-sentinel.go index 8e6b42f53..a4b7260ec 100644 --- a/k8sutils/redis-sentinel.go +++ b/k8sutils/redis-sentinel.go @@ -63,7 +63,7 @@ func (service RedisSentinelSTS) CreateRedisSentinelSetup(ctx context.Context, cr stateFulName := cr.ObjectMeta.Name + "-" + service.RedisStateFulType logger := statefulSetLogger(cr.Namespace, stateFulName) - labels := getRedisLabels(stateFulName, cluster, service.RedisStateFulType, cr.ObjectMeta.Labels) + labels := getRedisLabels(stateFulName, sentinel, service.RedisStateFulType, cr.ObjectMeta.Labels) annotations := generateStatefulSetsAnots(cr.ObjectMeta, cr.Spec.KubernetesConfig.IgnoreAnnotations) objectMetaInfo := generateObjectMetaInformation(stateFulName, cr.Namespace, labels, annotations) err := CreateOrUpdateStateFul( @@ -199,7 +199,7 @@ func (service RedisSentinelSTS) getSentinelCount(cr *redisv1beta2.RedisSentinel) func (service RedisSentinelService) CreateRedisSentinelService(cr *redisv1beta2.RedisSentinel) error { serviceName := cr.ObjectMeta.Name + "-" + service.RedisServiceRole logger := serviceLogger(cr.Namespace, serviceName) - labels := getRedisLabels(serviceName, cluster, service.RedisServiceRole, cr.ObjectMeta.Labels) + labels := getRedisLabels(serviceName, sentinel, service.RedisServiceRole, cr.ObjectMeta.Labels) annotations := generateServiceAnots(cr.ObjectMeta, nil) if cr.Spec.RedisExporter != nil && cr.Spec.RedisExporter.Enabled { diff --git a/tests/e2e/v1beta2/setup/redis-sentinel/00-install.yaml b/tests/e2e/v1beta2/setup/redis-sentinel/00-install.yaml new file mode 100644 index 000000000..21253678d --- /dev/null +++ b/tests/e2e/v1beta2/setup/redis-sentinel/00-install.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +apply: + - sentinel.yaml +assert: + - ready-sts.yaml + - ready-svc.yaml \ No newline at end of file diff --git a/tests/e2e/v1beta2/setup/redis-sentinel/ready-sts.yaml b/tests/e2e/v1beta2/setup/redis-sentinel/ready-sts.yaml new file mode 100644 index 000000000..c6056ab05 --- /dev/null +++ b/tests/e2e/v1beta2/setup/redis-sentinel/ready-sts.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + annotations: + redis.opstreelabs.in: "true" + redis.opstreelabs.instance: redis-sentinel + labels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + name: redis-sentinel-sentinel + ownerReferences: + - apiVersion: redis.redis.opstreelabs.in/v1beta2 + controller: true + kind: RedisSentinel + name: redis-sentinel +spec: + selector: + matchLabels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + serviceName: redis-sentinel-sentinel-headless + template: + metadata: + annotations: + redis.opstreelabs.in: "true" + redis.opstreelabs.instance: redis-sentinel + labels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel +status: + readyReplicas: 3 + replicas: 3 \ No newline at end of file diff --git a/tests/e2e/v1beta2/setup/redis-sentinel/ready-svc.yaml b/tests/e2e/v1beta2/setup/redis-sentinel/ready-svc.yaml new file mode 100644 index 000000000..4ce66a032 --- /dev/null +++ b/tests/e2e/v1beta2/setup/redis-sentinel/ready-svc.yaml @@ -0,0 +1,96 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + prometheus.io/port: "9121" + prometheus.io/scrape: "true" + redis.opstreelabs.in: "true" + redis.opstreelabs.instance: redis-sentinel + labels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + name: redis-sentinel-sentinel + ownerReferences: + - apiVersion: redis.redis.opstreelabs.in/v1beta2 + controller: true + kind: RedisSentinel + name: redis-sentinel +spec: + ports: + - name: sentinel-client + port: 26379 + protocol: TCP + targetPort: 26379 + selector: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + type: ClusterIP +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + prometheus.io/port: "9121" + prometheus.io/scrape: "true" + redis.opstreelabs.in: "true" + redis.opstreelabs.instance: redis-sentinel + labels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + name: redis-sentinel-sentinel-additional + ownerReferences: + - apiVersion: redis.redis.opstreelabs.in/v1beta2 + controller: true + kind: RedisSentinel + name: redis-sentinel +spec: + ports: + - name: sentinel-client + port: 26379 + protocol: TCP + targetPort: 26379 + selector: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + type: ClusterIP +status: + loadBalancer: {} +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + prometheus.io/port: "9121" + prometheus.io/scrape: "true" + redis.opstreelabs.in: "true" + redis.opstreelabs.instance: redis-sentinel + labels: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + name: redis-sentinel-sentinel-headless + ownerReferences: + - apiVersion: redis.redis.opstreelabs.in/v1beta2 + controller: true + kind: RedisSentinel + name: redis-sentinel +spec: + clusterIP: None + ports: + - name: sentinel-client + port: 26379 + protocol: TCP + targetPort: 26379 + selector: + app: redis-sentinel-sentinel + redis_setup_type: sentinel + role: sentinel + type: ClusterIP +status: + loadBalancer: {} diff --git a/tests/e2e/v1beta2/setup/redis-sentinel/sentinel.yaml b/tests/e2e/v1beta2/setup/redis-sentinel/sentinel.yaml new file mode 100644 index 000000000..d18d07f58 --- /dev/null +++ b/tests/e2e/v1beta2/setup/redis-sentinel/sentinel.yaml @@ -0,0 +1,22 @@ +--- +apiVersion: redis.redis.opstreelabs.in/v1beta2 +kind: RedisSentinel +metadata: + name: redis-sentinel +spec: + clusterSize: 3 + podSecurityContext: + runAsUser: 1000 + fsGroup: 1000 + redisSentinelConfig: + redisReplicationName : redis-replication + kubernetesConfig: + image: quay.io/opstree/redis-sentinel:latest + imagePullPolicy: Always + resources: + requests: + cpu: 101m + memory: 128Mi + limits: + cpu: 101m + memory: 128Mi \ No newline at end of file