Skip to content
Merged
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Redis Operator creates/configures/manages redis-failovers atop Kubernetes.
- [Using kustomize](#using-kustomize)
- [Usage](#usage)
- [Reducing update churn (`--enable-hash`)](#reducing-update-churn---enable-hash)
- [Reconcile interval (`--resync-period`)](#reconcile-interval---resync-period)
- [Persistence](#persistence)
- [NodeAffinity and Tolerations](#nodeaffinity-and-tolerations)
- [Topology Spread Contraints](#topology-spread-contraints)
Expand Down Expand Up @@ -166,6 +167,13 @@ sync, because the operator's *desired* object is unchanged and so its hash still
trading the operator's self-healing of manual drift for far fewer API writes. The flag is **off by
default**, so upgrading changes nothing until you opt in.

### Reconcile interval (`--resync-period`)

Beyond reacting to change events, the operator re-reconciles every `RedisFailover` on a fixed
interval so it can recover from missed events and correct drift. This defaults to `30s` and can be
tuned with `--resync-period` (any Go duration, e.g. `--resync-period=1m`). Larger values reduce API
load at the cost of slower periodic healing; smaller values react faster but poll more often.

### Persistence

The operator has the ability of add persistence to Redis data. By default an `emptyDir` will be used, so the data is not saved.
Expand Down
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"path/filepath"
"regexp"
"time"

"github.com/dnse-tech/redis-operator/operator/redisfailover"
"k8s.io/client-go/util/homedir"
Expand All @@ -23,6 +24,7 @@ type CMDFlags struct {
Concurrency int
LogLevel string
EnableObjectHashing bool
ResyncPeriod time.Duration
}

// Init initializes and parse the flags
Expand All @@ -43,6 +45,7 @@ func (c *CMDFlags) Init() {
// Off by default: skipping unchanged writes also stops the operator from
// correcting resources edited by hand, so opting in is a deliberate choice.
flag.BoolVar(&c.EnableObjectHashing, "enable-hash", false, "Skip updating owned resources when they already match the desired state")
flag.DurationVar(&c.ResyncPeriod, "resync-period", 30*time.Second, "How often every RedisFailover is re-reconciled even without a change event")
// Parse flags
flag.Parse()

Expand All @@ -58,5 +61,6 @@ func (c *CMDFlags) ToRedisOperatorConfig() redisfailover.Config {
MetricsPath: c.MetricsPath,
Concurrency: c.Concurrency,
SupportedNamespacesRegex: c.SupportedNamespacesRegex,
ResyncPeriod: c.ResyncPeriod,
}
}
5 changes: 5 additions & 0 deletions operator/redisfailover/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package redisfailover

import "time"

// Config is the configuration for the redis operator.
type Config struct {
ListenAddress string
MetricsPath string
Concurrency int
SupportedNamespacesRegex string
// ResyncPeriod is how often every RedisFailover is re-reconciled even
// without a change event. Zero falls back to the built-in default.
ResyncPeriod time.Duration
}
11 changes: 8 additions & 3 deletions operator/redisfailover/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
)

const (
resync = 30 * time.Second
operatorName = "redis-operator"
lockKey = "redis-failover-lease"
defaultResync = 30 * time.Second
operatorName = "redis-operator"
lockKey = "redis-failover-lease"
)

// New will create an operator that is responsible of managing all the required stuff
Expand All @@ -40,6 +40,11 @@ func New(cfg Config, k8sService k8s.Services, k8sClient kubernetes.Interface, lo
rfHandler := NewRedisFailoverHandler(cfg, rfService, rfChecker, rfHealer, k8sService, kooperMetricsRecorder, logger)
rfRetriever := NewRedisFailoverRetriever(cfg, k8sService)

resync := cfg.ResyncPeriod
if resync <= 0 {
resync = defaultResync
}

kooperLogger := kooperlogger{Logger: logger.WithField("operator", "redisfailover")}
// Leader election service.
leSVC, err := leaderelection.NewDefault(lockKey, lockNamespace, k8sClient, kooperLogger)
Expand Down