Skip to content

Commit 2aa2443

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 c57219e commit 2aa2443

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 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
}
7879

@@ -93,6 +94,7 @@ func parseFlags() CmdConfig {
9394
flag.BoolVar(&config.AllowOnlyReadyReplicas, "allow-only-ready-replicas", false, "Populate only Ready receiver replicas in the hashring configuration")
9495
flag.BoolVar(&config.AllowDynamicScaling, "allow-dynamic-scaling", false, "Update the hashring configuration on scale down events.")
9596
flag.BoolVar(&config.AnnotatePodsOnChange, "annotate-pods-on-change", false, "Annotates pods with current timestamp on a hashring change")
97+
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.")
9698
flag.DurationVar(&config.ScaleTimeout, "scale-timeout", defaultScaleTimeout, "A timeout to wait for receivers to really start after they report healthy")
9799
flag.Parse()
98100

@@ -152,6 +154,7 @@ func main() {
152154
labelValue: labelValue,
153155
allowOnlyReadyReplicas: config.AllowOnlyReadyReplicas,
154156
annotatePodsOnChange: config.AnnotatePodsOnChange,
157+
annotatePodsLabel: config.AnnotatePodsLabel,
155158
allowDynamicScaling: config.AllowDynamicScaling,
156159
scaleTimeout: config.ScaleTimeout,
157160
}
@@ -337,6 +340,7 @@ type options struct {
337340
allowOnlyReadyReplicas bool
338341
allowDynamicScaling bool
339342
annotatePodsOnChange bool
343+
annotatePodsLabel string
340344
scaleTimeout time.Duration
341345
}
342346

@@ -743,11 +747,15 @@ func (c *controller) saveHashring(ctx context.Context, hashring []receive.Hashri
743747
func (c *controller) annotatePods(ctx context.Context) {
744748
annotationKey := fmt.Sprintf("%s/%s", c.options.labelKey, "lastControllerUpdate")
745749
updateTime := fmt.Sprintf("%d", time.Now().Unix())
750+
annotatePodsLabel := fmt.Sprintf("%s=%s", c.options.labelKey, c.options.labelValue)
751+
if c.options.annotatePodsLabel != "" {
752+
annotatePodsLabel = c.options.annotatePodsLabel
753+
}
746754

747755
// Select pods that have a controllerLabel matching ours.
748756
podList, err := c.klient.CoreV1().Pods(c.options.namespace).List(ctx,
749757
metav1.ListOptions{
750-
LabelSelector: fmt.Sprintf("%s=%s", c.options.labelKey, c.options.labelValue),
758+
LabelSelector: annotatePodsLabel,
751759
})
752760
if err != nil {
753761
level.Error(c.logger).Log("msg", "failed to list pods belonging to controller", "err", err)

0 commit comments

Comments
 (0)