Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ By default, no service annotations will be applied to the Redis nor Sentinel ser

In order to apply custom service Annotations, you can provide the `serviceAnnotations` option inside redis/sentinel spec. An example can be found in the [custom annotations example file](example/redisfailover/custom-annotations.yaml).

### Allow Operator to Be Namespace-Scoped
By default operator is cluster wide.

In order to make operator namespace-scoped you can provide the env variable `WATCH_NAMESPACE` to the redisoperator deployment manifest.

```
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
```


### Control of label propagation.
By default the operator will propagate all labels on the CRD down to the resources that it creates. This can be problematic if the
labels on the CRD are not fully under your own control (for example: being deployed by a gitops operator)
Expand Down
12 changes: 7 additions & 5 deletions operator/redisfailover/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redisfailover
import (
"context"
"time"
"os"

"github.com/spotahome/kooper/v2/controller"
"github.com/spotahome/kooper/v2/controller/leaderelection"
Expand Down Expand Up @@ -33,10 +34,11 @@ func New(cfg Config, k8sService k8s.Services, k8sClient kubernetes.Interface, lo
rfService := rfservice.NewRedisFailoverKubeClient(k8sService, logger, kooperMetricsRecorder)
rfChecker := rfservice.NewRedisFailoverChecker(k8sService, redisClient, logger, kooperMetricsRecorder)
rfHealer := rfservice.NewRedisFailoverHealer(k8sService, redisClient, logger)

watchNamespace := os.Getenv("WATCH_NAMESPACE")

// Create the handlers.
rfHandler := NewRedisFailoverHandler(cfg, rfService, rfChecker, rfHealer, k8sService, kooperMetricsRecorder, logger)
rfRetriever := NewRedisFailoverRetriever(k8sService)
rfRetriever := NewRedisFailoverRetriever(k8sService, watchNamespace)

kooperLogger := kooperlogger{Logger: logger.WithField("operator", "redisfailover")}
// Leader election service.
Expand All @@ -58,13 +60,13 @@ func New(cfg Config, k8sService k8s.Services, k8sClient kubernetes.Interface, lo
})
}

func NewRedisFailoverRetriever(cli k8s.Services) controller.Retriever {
func NewRedisFailoverRetriever(cli k8s.Services, watchNamespace string) controller.Retriever {
return controller.MustRetrieverFromListerWatcher(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
return cli.ListRedisFailovers(context.Background(), "", options)
return cli.ListRedisFailovers(context.Background(), watchNamespace, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
return cli.WatchRedisFailovers(context.Background(), "", options)
return cli.WatchRedisFailovers(context.Background(), watchNamespace, options)
},
})
}
Expand Down