feat(heal): optionally protect the redis master from autoscaler eviction - #35
Merged
Merged
Conversation
Add an opt-in redis.preventMasterEviction flag. When enabled, the operator annotates the current master pod with cluster-autoscaler.kubernetes.io/safe-to-evict=false and marks slaves true, so the cluster autoscaler will not drain the node running the master and force an avoidable failover. The annotation follows the master as the role moves, in both the checker and healer relabel paths. Adds a Pod.UpdatePodAnnotations service method (JSON merge patch) and the matching mock. Regenerated the CRD for the new field. Refs upstream spotahome#689.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an opt-in
redis.preventMasterEvictionflag. When enabled, the operator annotates the current master pod withcluster-autoscaler.kubernetes.io/safe-to-evict: "false"and marks slaves"true", so the Kubernetes cluster-autoscaler won't drain the node running the master (which would force an avoidable failover). The annotation follows the master as the role moves — applied in both the checker and healer relabel paths.Why
Cluster-autoscaler scale-down can drain the node hosting the redis master, triggering an unnecessary failover and a brief write outage. Pinning only the master (slaves stay evictable) lets the autoscaler still consolidate the rest of the pool.
Design
Pod.UpdatePodAnnotationsservice method uses a JSON merge patch (creates the annotations map if absent), mirroring the existing targetedUpdatePodLabelspatch rather than a full-object update.Note on the mock
Adding the interface method requires regenerating
mocks/service/k8s. The committed mocks are mockery v2.20.0, which panics against the current Go 1.25 toolchain, so the new mock method is hand-written in the exact v2.20.0 format (a future correct regen is diff-free). Mocks are not part of the verify-generated CI check.Changes
api/.../types.go:RedisSettings.PreventMasterEviction(+ regenerated CRD).service/k8s/pod.go:UpdatePodAnnotations+ mock.check.go/heal.go: sharedapplyMasterEvictionAnnotationwired into both relabel paths.Upstream references
Test
go build ./...,go test ./...,gofmtclean; CRD regenerated via pinned codegen image.