From c48c9c5b0d09fb3e3438e269c7b5457585d062c2 Mon Sep 17 00:00:00 2001 From: yangw Date: Wed, 6 Nov 2024 21:52:56 +0800 Subject: [PATCH] feat: reconcile redis sentinel only on master changed (#1122) * feat: redissentinel reconcile only on master changed Signed-off-by: drivebyer * fix Lint Signed-off-by: drivebyer * e2e cleanup Signed-off-by: drivebyer --------- Signed-off-by: drivebyer --- example/v1beta2/redis-replication.yaml | 6 +- main.go | 12 ++- .../redissentinel/redissentinel_controller.go | 17 +++- .../redissentinel_controller_suite_test.go | 10 +- pkg/controllerutil/resource_watcher.go | 76 +++++++++++++++ .../ha}/chainsaw-test.yaml | 2 +- .../{ha-failover => setup/ha}/cli-pod.yaml | 0 .../replication-password/chainsaw-test.yaml | 53 ---------- .../ha/replication-password/password.yaml | 8 -- .../ha/replication-password/ready-secret.yaml | 6 -- .../ha/replication-password/replication.yaml | 30 ------ .../ha/replication-password/sentinel.yaml | 28 ------ .../ha}/replication.yaml | 0 .../ha/sentinel-password/chainsaw-test.yaml | 59 ----------- .../setup/ha/sentinel-password/cli-pod.yaml | 15 --- .../ready-replication-pvc.yaml | 42 -------- .../ready-replication-sts.yaml | 20 ---- .../ready-replication-svc.yaml | 91 ----------------- .../sentinel-password/ready-sentinel-sts.yaml | 36 ------- .../sentinel-password/ready-sentinel-svc.yaml | 97 ------------------- .../setup/ha/sentinel-password/secret.yaml | 8 -- .../setup/ha/sentinel-password/sentinel.yaml | 26 ----- .../{ha-failover => setup/ha}/sentinel.yaml | 0 .../setup/redis-sentinel/chainsaw-test.yaml | 59 ++++++++--- .../cli-pod.yaml | 0 .../ready-replication-pvc.yaml | 0 .../ready-replication-sts.yaml | 0 .../ready-replication-svc.yaml | 0 .../ready-sentinel-sts.yaml | 0 .../ready-sentinel-svc.yaml | 0 .../setup/redis-sentinel/ready-sts.yaml | 36 ------- .../setup/redis-sentinel/ready-svc.yaml | 97 ------------------- .../replication.yaml | 0 .../secret.yaml | 0 .../setup/redis-sentinel/sentinel.yaml | 10 +- 35 files changed, 161 insertions(+), 683 deletions(-) create mode 100644 pkg/controllerutil/resource_watcher.go rename tests/e2e-chainsaw/v1beta2/{ha-failover => setup/ha}/chainsaw-test.yaml (99%) rename tests/e2e-chainsaw/v1beta2/{ha-failover => setup/ha}/cli-pod.yaml (100%) delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/chainsaw-test.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/password.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-secret.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/replication.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/sentinel.yaml rename tests/e2e-chainsaw/v1beta2/{ha-failover => setup/ha}/replication.yaml (100%) delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/chainsaw-test.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/cli-pod.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-pvc.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-sts.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-svc.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-sts.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-svc.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/secret.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/sentinel.yaml rename tests/e2e-chainsaw/v1beta2/{ha-failover => setup/ha}/sentinel.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/cli-pod.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/ready-replication-pvc.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/ready-replication-sts.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/ready-replication-svc.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/ready-sentinel-sts.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/ready-sentinel-svc.yaml (100%) delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sts.yaml delete mode 100644 tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-svc.yaml rename tests/e2e-chainsaw/v1beta2/setup/{ha/sentinel-password => redis-sentinel}/replication.yaml (100%) rename tests/e2e-chainsaw/v1beta2/setup/{ha/replication-password => redis-sentinel}/secret.yaml (100%) diff --git a/example/v1beta2/redis-replication.yaml b/example/v1beta2/redis-replication.yaml index 1f4ca8194..b7708d3f5 100644 --- a/example/v1beta2/redis-replication.yaml +++ b/example/v1beta2/redis-replication.yaml @@ -20,9 +20,9 @@ spec: limits: cpu: 101m memory: 128Mi - redisSecret: - name: redis-secret - key: password +# redisSecret: +# name: redis-secret +# key: password # imagePullSecrets: # - name: regcred redisExporter: diff --git a/main.go b/main.go index df3c37573..9d46df50b 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( "github.com/OT-CONTAINER-KIT/redis-operator/pkg/controllers/rediscluster" "github.com/OT-CONTAINER-KIT/redis-operator/pkg/controllers/redisreplication" "github.com/OT-CONTAINER-KIT/redis-operator/pkg/controllers/redissentinel" + intctrlutil "github.com/OT-CONTAINER-KIT/redis-operator/pkg/controllerutil" "github.com/OT-CONTAINER-KIT/redis-operator/pkg/k8sutils" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -153,11 +154,12 @@ func main() { os.Exit(1) } if err = (&redissentinel.RedisSentinelReconciler{ - Client: mgr.GetClient(), - K8sClient: k8sclient, - Dk8sClient: dk8sClient, - Log: ctrl.Log.WithName("controllers").WithName("RedisSentinel"), - Scheme: mgr.GetScheme(), + Client: mgr.GetClient(), + K8sClient: k8sclient, + Dk8sClient: dk8sClient, + Log: ctrl.Log.WithName("controllers").WithName("RedisSentinel"), + Scheme: mgr.GetScheme(), + ReplicationWatcher: intctrlutil.NewResourceWatcher(), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "RedisSentinel") os.Exit(1) diff --git a/pkg/controllers/redissentinel/redissentinel_controller.go b/pkg/controllers/redissentinel/redissentinel_controller.go index 0a21e14a0..feb1ba695 100644 --- a/pkg/controllers/redissentinel/redissentinel_controller.go +++ b/pkg/controllers/redissentinel/redissentinel_controller.go @@ -9,6 +9,7 @@ import ( "github.com/OT-CONTAINER-KIT/redis-operator/pkg/k8sutils" "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" @@ -22,6 +23,8 @@ type RedisSentinelReconciler struct { Dk8sClient dynamic.Interface Log logr.Logger Scheme *runtime.Scheme + + ReplicationWatcher *intctrlutil.ResourceWatcher } func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { @@ -55,6 +58,17 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques return intctrlutil.RequeueAfter(reqLogger, time.Second*10, "Redis Replication is specified but not ready") } + if instance.Spec.RedisSentinelConfig != nil { + r.ReplicationWatcher.Watch( + ctx, + types.NamespacedName{ + Namespace: req.Namespace, + Name: instance.Spec.RedisSentinelConfig.RedisReplicationName, + }, + req.NamespacedName, + ) + } + // Create Redis Sentinel err = k8sutils.CreateRedisSentinel(ctx, r.K8sClient, r.Log, instance, r.K8sClient, r.Dk8sClient) if err != nil { @@ -71,12 +85,13 @@ func (r *RedisSentinelReconciler) Reconcile(ctx context.Context, req ctrl.Reques if err != nil { return intctrlutil.RequeueWithError(err, reqLogger, "") } - return intctrlutil.RequeueAfter(reqLogger, time.Second*10, "") + return intctrlutil.Reconciled() } // SetupWithManager sets up the controller with the Manager. func (r *RedisSentinelReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&redisv1beta2.RedisSentinel{}). + Watches(&redisv1beta2.RedisReplication{}, r.ReplicationWatcher). Complete(r) } diff --git a/pkg/controllers/redissentinel/redissentinel_controller_suite_test.go b/pkg/controllers/redissentinel/redissentinel_controller_suite_test.go index 54aaa2edd..ece28dc28 100644 --- a/pkg/controllers/redissentinel/redissentinel_controller_suite_test.go +++ b/pkg/controllers/redissentinel/redissentinel_controller_suite_test.go @@ -23,6 +23,7 @@ import ( "time" redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" + intctrlutil "github.com/OT-CONTAINER-KIT/redis-operator/pkg/controllerutil" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" @@ -100,10 +101,11 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(HaveOccurred()) err = (&RedisSentinelReconciler{ - Client: k8sManager.GetClient(), - K8sClient: k8sClient, - Dk8sClient: dk8sClient, - Scheme: k8sManager.GetScheme(), + Client: k8sManager.GetClient(), + K8sClient: k8sClient, + Dk8sClient: dk8sClient, + Scheme: k8sManager.GetScheme(), + ReplicationWatcher: intctrlutil.NewResourceWatcher(), }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) diff --git a/pkg/controllerutil/resource_watcher.go b/pkg/controllerutil/resource_watcher.go new file mode 100644 index 000000000..39ab8c8b3 --- /dev/null +++ b/pkg/controllerutil/resource_watcher.go @@ -0,0 +1,76 @@ +package controllerutil + +import ( + "context" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/util/workqueue" + "sigs.k8s.io/controller-runtime/pkg/event" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/reconcile" +) + +// ResourceWatcher implements handler.EventHandler and is used to trigger reconciliation when +// a watched object changes. It's designed to only be used for a single type of object. +// If multiple types should be watched, one ResourceWatcher for each type should be used. +type ResourceWatcher struct { + watched map[types.NamespacedName][]types.NamespacedName +} + +var _ handler.EventHandler = &ResourceWatcher{} + +// NewResourceWatcher will create a new ResourceWatcher with no watched objects. +func NewResourceWatcher() *ResourceWatcher { + return &ResourceWatcher{ + watched: make(map[types.NamespacedName][]types.NamespacedName), + } +} + +// Watch will add a new object to watch. +func (w ResourceWatcher) Watch(ctx context.Context, watchedName, dependentName types.NamespacedName) { + existing, hasExisting := w.watched[watchedName] + if !hasExisting { + existing = []types.NamespacedName{} + } + + for _, dependent := range existing { + if dependent == dependentName { + return + } + } + w.watched[watchedName] = append(existing, dependentName) +} + +func (w ResourceWatcher) Create(ctx context.Context, event event.CreateEvent, queue workqueue.RateLimitingInterface) { + w.handleEvent(event.Object, queue) +} + +func (w ResourceWatcher) Update(ctx context.Context, event event.UpdateEvent, queue workqueue.RateLimitingInterface) { + w.handleEvent(event.ObjectOld, queue) +} + +func (w ResourceWatcher) Delete(ctx context.Context, event event.DeleteEvent, queue workqueue.RateLimitingInterface) { + w.handleEvent(event.Object, queue) +} + +func (w ResourceWatcher) Generic(ctx context.Context, event event.GenericEvent, queue workqueue.RateLimitingInterface) { + w.handleEvent(event.Object, queue) +} + +// handleEvent is called when an event is received for an object. +// It will check if the object is being watched and trigger a reconciliation for +// the dependent object. +func (w ResourceWatcher) handleEvent(meta metav1.Object, queue workqueue.RateLimitingInterface) { + changedObjectName := types.NamespacedName{ + Name: meta.GetName(), + Namespace: meta.GetNamespace(), + } + + // Enqueue reconciliation for each dependent object. + for _, dep := range w.watched[changedObjectName] { + queue.Add(reconcile.Request{ + NamespacedName: dep, + }) + } +} diff --git a/tests/e2e-chainsaw/v1beta2/ha-failover/chainsaw-test.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/chainsaw-test.yaml similarity index 99% rename from tests/e2e-chainsaw/v1beta2/ha-failover/chainsaw-test.yaml rename to tests/e2e-chainsaw/v1beta2/setup/ha/chainsaw-test.yaml index 2987184e1..050f59672 100644 --- a/tests/e2e-chainsaw/v1beta2/ha-failover/chainsaw-test.yaml +++ b/tests/e2e-chainsaw/v1beta2/setup/ha/chainsaw-test.yaml @@ -2,7 +2,7 @@ apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: - name: ha-failover + name: setup-ha spec: steps: - try: diff --git a/tests/e2e-chainsaw/v1beta2/ha-failover/cli-pod.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/cli-pod.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/ha-failover/cli-pod.yaml rename to tests/e2e-chainsaw/v1beta2/setup/ha/cli-pod.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/chainsaw-test.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/chainsaw-test.yaml deleted file mode 100644 index 5e953798f..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/chainsaw-test.yaml +++ /dev/null @@ -1,53 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json -apiVersion: chainsaw.kyverno.io/v1alpha1 -kind: Test -metadata: - name: setup-ha-replication-password -spec: - steps: - - try: - - create: - file: secret.yaml - - assert: - file: secret.yaml - - apply: - file: replication.yaml - - assert: - file: ready-replication-sts.yaml - - assert: - file: ready-replication-svc.yaml - - assert: - file: ready-replication-pvc.yaml - - create: - file: password.yaml - - apply: - file: sentinel.yaml - - assert: - file: ready-sentinel-sts.yaml - - assert: - file: ready-sentinel-svc.yaml - - create: - file: cli-pod.yaml - - assert: - file: cli-pod.yaml - - name: Sleep for five minutes - try: - - sleep: - duration: 5m - - name: Ping Replicated Service from Cli Pod - try: - - script: - timeout: 10s - content: | - kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-replication.${NAMESPACE}.svc -p 6379 -a Opstree@1234 ping - check: - (contains($stdout, 'PONG')): true - - name: Ping Sentinel Service from Cli Pod - try: - - script: - timeout: 10s - content: | - kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-sentinel-sentinel.${NAMESPACE}.svc -p 26379 ping - check: - (contains($stdout, 'PONG')): true diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/password.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/password.yaml deleted file mode 100644 index d2411ff46..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/password.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -apiVersion: v1 -kind: Secret -metadata: - name: redis-replication-secret -stringData: - redis-replication-password: Opstree@1234 -type: Opaque diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-secret.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-secret.yaml deleted file mode 100644 index c6ee0b3ab..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-secret.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -apiVersion: v1 -kind: Secret -metadata: - name: redis-replication-secret -type: Opaque diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/replication.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/replication.yaml deleted file mode 100644 index 155811686..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/replication.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: redis.redis.opstreelabs.in/v1beta2 -kind: RedisReplication -metadata: - name: redis-replication -spec: - clusterSize: 3 - podSecurityContext: - runAsUser: 1000 - fsGroup: 1000 - kubernetesConfig: - image: quay.io/opstree/redis:latest - imagePullPolicy: Always - redisSecret: - name: redis-secret - key: password - resources: - requests: - cpu: 101m - memory: 128Mi - limits: - cpu: 101m - memory: 128Mi - storage: - volumeClaimTemplate: - spec: - accessModes: [ReadWriteOnce] - resources: - requests: - storage: 1Gi diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/sentinel.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/sentinel.yaml deleted file mode 100644 index 02fca1f8e..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/sentinel.yaml +++ /dev/null @@ -1,28 +0,0 @@ ---- -# yaml-language-server: $schema=../../../../../../../../config/crd/bases/redis.redis.opstreelabs.in_redissentinels.yaml -apiVersion: redis.redis.opstreelabs.in/v1beta2 -kind: RedisSentinel -metadata: - name: redis-sentinel -spec: - clusterSize: 1 - podSecurityContext: - runAsUser: 1000 - fsGroup: 1000 - redisSentinelConfig: - redisReplicationName: redis-replication - quorum: '1' - redisReplicationPassword: - secretKeyRef: - name: redis-replication-secret - key: redis-replication-password - kubernetesConfig: - image: quay.io/opstree/redis-sentinel:latest - imagePullPolicy: Always - resources: - requests: - cpu: 101m - memory: 128Mi - limits: - cpu: 101m - memory: 128Mi diff --git a/tests/e2e-chainsaw/v1beta2/ha-failover/replication.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/replication.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/ha-failover/replication.yaml rename to tests/e2e-chainsaw/v1beta2/setup/ha/replication.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/chainsaw-test.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/chainsaw-test.yaml deleted file mode 100644 index 5cd60104b..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/chainsaw-test.yaml +++ /dev/null @@ -1,59 +0,0 @@ ---- -# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json -apiVersion: chainsaw.kyverno.io/v1alpha1 -kind: Test -metadata: - name: setup-ha-sentinel-password -spec: - steps: - - try: - - apply: - file: replication.yaml - - assert: - file: ready-replication-sts.yaml - - assert: - file: ready-replication-svc.yaml - - assert: - file: ready-replication-pvc.yaml - - create: - file: secret.yaml - - assert: - file: secret.yaml - - apply: - file: sentinel.yaml - - assert: - file: ready-sentinel-sts.yaml - - assert: - file: ready-sentinel-svc.yaml - - create: - file: cli-pod.yaml - - assert: - file: cli-pod.yaml - - name: Sleep for five minutes - try: - - sleep: - duration: 5m - - name: Ping Replicated Service from Cli Pod - try: - - script: - timeout: 10s - content: | - kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-replication.${NAMESPACE}.svc -p 6379 ping - check: - (contains($stdout, 'PONG')): true - - name: Ping Sentinel Service from Cli Pod With password - try: - - script: - timeout: 10s - content: | - kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-sentinel-sentinel.${NAMESPACE}.svc -p 26379 -a Opstree@1234 ping - check: - (contains($stdout, 'PONG')): true - - name: Ping Sentinel Service from Cli Pod Without password - try: - - script: - timeout: 10s - content: | - kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-sentinel-sentinel.${NAMESPACE}.svc -p 26379 ping - check: - (contains($stdout, 'NOAUTH Authentication required')): true diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/cli-pod.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/cli-pod.yaml deleted file mode 100644 index e3049d88b..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/cli-pod.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -apiVersion: v1 -kind: Pod -metadata: - name: redis - labels: - app: redis -spec: - containers: - - name: redis - image: redis:alpine - resources: - limits: - cpu: 200m - memory: 500Mi diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-pvc.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-pvc.yaml deleted file mode 100644 index 10d9c886c..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-pvc.yaml +++ /dev/null @@ -1,42 +0,0 @@ ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: redis-replication-redis-replication-0 - labels: - app: redis-replication - redis_setup_type: replication - role: replication -status: - accessModes: [ReadWriteOnce] - capacity: - storage: 1Gi - phase: Bound ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: redis-replication-redis-replication-1 - labels: - app: redis-replication - redis_setup_type: replication - role: replication -status: - accessModes: [ReadWriteOnce] - capacity: - storage: 1Gi - phase: Bound ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: redis-replication-redis-replication-2 - labels: - app: redis-replication - redis_setup_type: replication - role: replication -status: - accessModes: [ReadWriteOnce] - capacity: - storage: 1Gi - phase: Bound diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-sts.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-sts.yaml deleted file mode 100644 index 7e1712a8e..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-sts.yaml +++ /dev/null @@ -1,20 +0,0 @@ ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - annotations: - redis.opstreelabs.in: 'true' - redis.opstreelabs.instance: redis-replication - labels: - app: redis-replication - redis_setup_type: replication - role: replication - name: redis-replication - ownerReferences: - - apiVersion: redis.redis.opstreelabs.in/v1beta2 - controller: true - kind: RedisReplication - name: redis-replication -status: - readyReplicas: 3 - replicas: 3 diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-svc.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-svc.yaml deleted file mode 100644 index 3e2e7ccbb..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-replication-svc.yaml +++ /dev/null @@ -1,91 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - prometheus.io/port: '9121' - prometheus.io/scrape: 'true' - redis.opstreelabs.in: 'true' - redis.opstreelabs.instance: redis-replication - labels: - app: redis-replication - redis_setup_type: replication - role: replication - name: redis-replication - ownerReferences: - - apiVersion: redis.redis.opstreelabs.in/v1beta2 - controller: true - kind: RedisReplication - name: redis-replication -spec: - ports: - - name: redis-client - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app: redis-replication - redis_setup_type: replication - role: replication - type: ClusterIP ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - prometheus.io/port: '9121' - prometheus.io/scrape: 'true' - redis.opstreelabs.in: 'true' - redis.opstreelabs.instance: redis-replication - labels: - app: redis-replication - redis_setup_type: replication - role: replication - name: redis-replication-additional - ownerReferences: - - apiVersion: redis.redis.opstreelabs.in/v1beta2 - controller: true - kind: RedisReplication - name: redis-replication -spec: - ports: - - name: redis-client - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app: redis-replication - redis_setup_type: replication - role: replication - type: ClusterIP ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - prometheus.io/port: '9121' - prometheus.io/scrape: 'true' - redis.opstreelabs.in: 'true' - redis.opstreelabs.instance: redis-replication - labels: - app: redis-replication - redis_setup_type: replication - role: replication - name: redis-replication-headless - ownerReferences: - - apiVersion: redis.redis.opstreelabs.in/v1beta2 - controller: true - kind: RedisReplication - name: redis-replication -spec: - clusterIP: None - ports: - - name: redis-client - port: 6379 - protocol: TCP - targetPort: 6379 - selector: - app: redis-replication - redis_setup_type: replication - role: replication - type: ClusterIP diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-sts.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-sts.yaml deleted file mode 100644 index 782908c01..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-sts.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -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: 1 - replicas: 1 diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-svc.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-svc.yaml deleted file mode 100644 index 5f0556616..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/ready-sentinel-svc.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -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-chainsaw/v1beta2/setup/ha/sentinel-password/secret.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/secret.yaml deleted file mode 100644 index cf1cf0a6a..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -apiVersion: v1 -kind: Secret -metadata: - name: redis-secret -data: - password: T3BzdHJlZUAxMjM0Cg== -type: Opaque diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/sentinel.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/sentinel.yaml deleted file mode 100644 index 345287bcd..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/sentinel.yaml +++ /dev/null @@ -1,26 +0,0 @@ ---- -apiVersion: redis.redis.opstreelabs.in/v1beta2 -kind: RedisSentinel -metadata: - name: redis-sentinel -spec: - clusterSize: 1 - podSecurityContext: - runAsUser: 1000 - fsGroup: 1000 - redisSentinelConfig: - redisReplicationName: redis-replication - quorum: '1' - kubernetesConfig: - image: quay.io/opstree/redis-sentinel:latest - imagePullPolicy: Always - redisSecret: - name: redis-secret - key: password - resources: - requests: - cpu: 101m - memory: 128Mi - limits: - cpu: 101m - memory: 128Mi diff --git a/tests/e2e-chainsaw/v1beta2/ha-failover/sentinel.yaml b/tests/e2e-chainsaw/v1beta2/setup/ha/sentinel.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/ha-failover/sentinel.yaml rename to tests/e2e-chainsaw/v1beta2/setup/ha/sentinel.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/chainsaw-test.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/chainsaw-test.yaml index 53a959c83..8ab92f0b7 100644 --- a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/chainsaw-test.yaml +++ b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/chainsaw-test.yaml @@ -7,22 +7,53 @@ metadata: spec: steps: - try: + - apply: + file: replication.yaml + - assert: + file: ready-replication-sts.yaml + - assert: + file: ready-replication-svc.yaml + - assert: + file: ready-replication-pvc.yaml + - create: + file: secret.yaml + - assert: + file: secret.yaml - apply: file: sentinel.yaml - assert: - file: ready-sts.yaml + file: ready-sentinel-sts.yaml - assert: - file: ready-svc.yaml - - - name: redis-sentinel-uninstall - description: Uninstall Redis Sentinel + file: ready-sentinel-svc.yaml + - create: + file: cli-pod.yaml + - assert: + file: cli-pod.yaml + - name: Sleep for five minutes + try: + - sleep: + duration: 5m + - name: Ping Replicated Service from Cli Pod + try: + - script: + timeout: 10s + content: | + kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-replication.${NAMESPACE}.svc -p 6379 ping + check: + (contains($stdout, 'PONG')): true + - name: Ping Sentinel Service from Cli Pod With password + try: + - script: + timeout: 10s + content: | + kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-sentinel-sentinel.${NAMESPACE}.svc -p 26379 -a Opstree@1234 ping + check: + (contains($stdout, 'PONG')): true + - name: Ping Sentinel Service from Cli Pod Without password try: - - delete: - ref: - name: redis-sentinel - kind: RedisSentinel - apiVersion: redis.redis.opstreelabs.in/v1beta2 - - error: - file: ready-sts.yaml - - error: - file: ready-svc.yaml + - script: + timeout: 10s + content: | + kubectl exec --namespace ${NAMESPACE} redis -- redis-cli -h redis-sentinel-sentinel.${NAMESPACE}.svc -p 26379 ping + check: + (contains($stdout, 'NOAUTH Authentication required')): true diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/cli-pod.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/cli-pod.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/cli-pod.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/cli-pod.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-pvc.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-pvc.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-pvc.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-pvc.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-sts.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-sts.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-sts.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-sts.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-svc.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-svc.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-replication-svc.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-replication-svc.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-sentinel-sts.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sentinel-sts.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-sentinel-sts.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sentinel-sts.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-sentinel-svc.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sentinel-svc.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/ready-sentinel-svc.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sentinel-svc.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sts.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sts.yaml deleted file mode 100644 index c983596f2..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-sts.yaml +++ /dev/null @@ -1,36 +0,0 @@ ---- -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 diff --git a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-svc.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-svc.yaml deleted file mode 100644 index 5f0556616..000000000 --- a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/ready-svc.yaml +++ /dev/null @@ -1,97 +0,0 @@ ---- -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-chainsaw/v1beta2/setup/ha/sentinel-password/replication.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/replication.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/sentinel-password/replication.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/replication.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/secret.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/secret.yaml similarity index 100% rename from tests/e2e-chainsaw/v1beta2/setup/ha/replication-password/secret.yaml rename to tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/secret.yaml diff --git a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/sentinel.yaml b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/sentinel.yaml index 2fc9f45fd..345287bcd 100644 --- a/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/sentinel.yaml +++ b/tests/e2e-chainsaw/v1beta2/setup/redis-sentinel/sentinel.yaml @@ -4,15 +4,19 @@ kind: RedisSentinel metadata: name: redis-sentinel spec: - clusterSize: 3 + clusterSize: 1 podSecurityContext: runAsUser: 1000 fsGroup: 1000 - # redisSentinelConfig: - # redisReplicationName : redis-replication + redisSentinelConfig: + redisReplicationName: redis-replication + quorum: '1' kubernetesConfig: image: quay.io/opstree/redis-sentinel:latest imagePullPolicy: Always + redisSecret: + name: redis-secret + key: password resources: requests: cpu: 101m