Skip to content

Commit 54a6f39

Browse files
committed
Allow to annotate pods on change using a different label
This change allows users to optionally specify a different label (than the one used to watch receiver pods) for annotating pods on hashring change. This is useful in a separate Thanos receiver router and ingestor setup: https://thanos.io/tip/proposals-accepted/202012-receive-split.md/ where we need to watch a different set of ingestor pods to update the hashring, but the hashring is consumed by a different set of router pods. Signed-off-by: Ratnadeep Debnath <[email protected]>
1 parent 7140e94 commit 54a6f39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type CmdConfig struct {
7373
AllowOnlyReadyReplicas bool
7474
AllowDynamicScaling bool
7575
AnnotatePodsOnChange bool
76+
AnnotatePodsLabel string
7677
ScaleTimeout time.Duration
7778
useAzAwareHashRing bool
7879
podAzAnnotationKey string
@@ -95,6 +96,7 @@ func parseFlags() CmdConfig {
9596
flag.BoolVar(&config.AllowOnlyReadyReplicas, "allow-only-ready-replicas", false, "Populate only Ready receiver replicas in the hashring configuration")
9697
flag.BoolVar(&config.AllowDynamicScaling, "allow-dynamic-scaling", false, "Update the hashring configuration on scale down events.")
9798
flag.BoolVar(&config.AnnotatePodsOnChange, "annotate-pods-on-change", false, "Annotates pods with current timestamp on a hashring change")
99+
flag.StringVar(&config.AnnotatePodsLabel, "annotate-pods-label", "", "The label pods must have to be annotated with current timestamp by the controller on a hashring change.")
98100
flag.DurationVar(&config.ScaleTimeout, "scale-timeout", defaultScaleTimeout, "A timeout to wait for receivers to really start after they report healthy")
99101
flag.BoolVar(&config.useAzAwareHashRing, "use-az-aware-hashring", false, "A boolean to use az aware hashring to comply with Thanos v0.32+")
100102
flag.StringVar(&config.podAzAnnotationKey, "pod-az-annotation-key", "", "pod annotation key for AZ Info, If not specified or key not found, will use sts name as AZ key")
@@ -156,6 +158,7 @@ func main() {
156158
labelValue: labelValue,
157159
allowOnlyReadyReplicas: config.AllowOnlyReadyReplicas,
158160
annotatePodsOnChange: config.AnnotatePodsOnChange,
161+
annotatePodsLabel: config.AnnotatePodsLabel,
159162
allowDynamicScaling: config.AllowDynamicScaling,
160163
scaleTimeout: config.ScaleTimeout,
161164
useAzAwareHashRing: config.useAzAwareHashRing,
@@ -343,6 +346,7 @@ type options struct {
343346
allowOnlyReadyReplicas bool
344347
allowDynamicScaling bool
345348
annotatePodsOnChange bool
349+
annotatePodsLabel string
346350
scaleTimeout time.Duration
347351
useAzAwareHashRing bool
348352
podAzAnnotationKey string
@@ -788,11 +792,16 @@ func (c *controller) saveHashring(ctx context.Context, hashring []receive.Hashri
788792
func (c *controller) annotatePods(ctx context.Context) {
789793
annotationKey := fmt.Sprintf("%s/%s", c.options.labelKey, "lastControllerUpdate")
790794
updateTime := fmt.Sprintf("%d", time.Now().Unix())
795+
annotatePodsLabel := fmt.Sprintf("%s=%s", c.options.labelKey, c.options.labelValue)
796+
797+
if c.options.annotatePodsLabel != "" {
798+
annotatePodsLabel = c.options.annotatePodsLabel
799+
}
791800

792801
// Select pods that have a controllerLabel matching ours.
793802
podList, err := c.klient.CoreV1().Pods(c.options.namespace).List(ctx,
794803
metav1.ListOptions{
795-
LabelSelector: fmt.Sprintf("%s=%s", c.options.labelKey, c.options.labelValue),
804+
LabelSelector: annotatePodsLabel,
796805
})
797806
if err != nil {
798807
level.Error(c.logger).Log("msg", "failed to list pods belonging to controller", "err", err)

0 commit comments

Comments
 (0)