Skip to content

Commit

Permalink
Refactor rotateIfNeeded function to use label selector for listing de…
Browse files Browse the repository at this point in the history
…ployments
  • Loading branch information
ykadowak committed Mar 8, 2024
1 parent 2b035ee commit 6ace761
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/index/operator/service/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ func (o *operator) rotateIfNeeded(ctx context.Context, pod pod.Pod) error {
}

Check warning on line 181 in pkg/index/operator/service/operator.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/operator/service/operator.go#L177-L181

Added lines #L177 - L181 were not covered by tests

var depList client.DeploymentList
label := client.MatchingLabels(map[string]string{o.readReplicaLabelKey: podIdx})
if err := o.client.List(ctx, &depList, label); err != nil {
selector, err := o.client.LabelSelector(o.readReplicaLabelKey, client.SelectionOpEquals, []string{podIdx})
if err != nil {
return fmt.Errorf("creating label selector: %w", err)
}
listOpts := client.ListOptions{
Namespace: o.namespace,
LabelSelector: selector,
}
if err := o.client.List(ctx, &depList, &listOpts); err != nil {
return err
}
if len(depList.Items) == 0 {
Expand Down

0 comments on commit 6ace761

Please sign in to comment.