Skip to content

Commit

Permalink
2.fix selector match for config resources like VMUser, VMRule... , be…
Browse files Browse the repository at this point in the history
…fore it could be ignored when update resource labels
  • Loading branch information
Haleygo authored and f41gh7 committed Apr 23, 2024
1 parent 15509a4 commit 4d47f04
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion controllers/vmalertmanagerconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (r *VMAlertmanagerConfigReconciler) Reconcile(ctx context.Context, req ctrl
l := l.WithValues("alertmanager", am.Name)
ctx := logger.AddToContext(ctx, l)

if !am.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !am.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, &instance, am, am.Spec.ConfigSelector, am.Spec.ConfigNamespaceSelector)
if err != nil {
l.Error(err, "cannot match alertmanager against selector, probably bug")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmnodescrape_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (r *VMNodeScrapeReconciler) Reconcile(ctx context.Context, req ctrl.Request
continue
}
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.NodeScrapeSelector, currentVMagent.Spec.NodeScrapeNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmNodeScrape")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmpodscrape_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (r *VMPodScrapeReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
reqLogger = reqLogger.WithValues("vmagent", vmagentItem.Name)
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.PodScrapeSelector, currentVMagent.Spec.PodScrapeNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmPodScrape")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmprobe_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func (r *VMProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
continue
}
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.ProbeSelector, currentVMagent.Spec.ProbeNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmProbe")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmrule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (r *VMRuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
continue
}
currVMAlert := &vmalertItem
if !currVMAlert.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currVMAlert.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currVMAlert, currVMAlert.Spec.RuleSelector, currVMAlert.Spec.RuleNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmalert and vmRule")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmscrapeconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func (r *VMScrapeConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reque
continue
}
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.ScrapeConfigSelector, currentVMagent.Spec.ScrapeConfigNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmScrapeConfig")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmservicescrape_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ func (r *VMServiceScrapeReconciler) Reconcile(ctx context.Context, req ctrl.Requ
continue
}
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.ServiceScrapeSelector, currentVMagent.Spec.ServiceScrapeNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmServiceScrape")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmstaticscrape_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (r *VMStaticScrapeReconciler) Reconcile(ctx context.Context, req ctrl.Reque
continue
}
currentVMagent := &vmagentItem
if !currentVMagent.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMagent.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, instance, currentVMagent, currentVMagent.Spec.StaticScrapeSelector, currentVMagent.Spec.StaticScrapeNamespaceSelector)
if err != nil {
reqLogger.Error(err, "cannot match vmagent and vmStaticScrape")
Expand Down
3 changes: 2 additions & 1 deletion controllers/vmuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func (r *VMUserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
}
// reconcile users for given vmauth.
currentVMAuth := &vmauthItem
if !currentVMAuth.Spec.SelectAllByDefault {
// only check selector when deleting, since labels can be changed when updating and we can't tell if it was selected before.
if instance.DeletionTimestamp.IsZero() && !currentVMAuth.Spec.SelectAllByDefault {
match, err := isSelectorsMatchesTargetCRD(ctx, r.Client, &instance, currentVMAuth, currentVMAuth.Spec.UserSelector, currentVMAuth.Spec.UserNamespaceSelector)
if err != nil {
l.Error(err, "cannot match vmauth and VMUser")
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ aliases:

## Next release

- [operator](./README.md): fix conversion from `ServiceMonitor` to `VMServiceScrape`, `bearerTokenSecret` is dropped mistakenly since [v0.43.0](https://github.com/VictoriaMetrics/operator/releases/tag/v0.43.0). See [this issue](https://github.com/VictoriaMetrics/operator/issues/932).
- [operator](./README.md): fix selector match for config resources like VMUser, VMRule... , before it could be ignored when update resource labels.

<a name="v0.43.2"></a>

## [v0.43.2](https://github.com/VictoriaMetrics/operator/releases/tag/v0.43.2) - 22 Apr 2024
Expand Down

0 comments on commit 4d47f04

Please sign in to comment.