Skip to content

Commit

Permalink
controllers/converter: allows to add ArgoCD ingore annotations
Browse files Browse the repository at this point in the history
it should simplify operator usage with converted prometheus objects managed by argoCD
#509
  • Loading branch information
f41gh7 committed Aug 16, 2022
1 parent 81d4b84 commit 191bf96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions controllers/converter/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,23 @@ func ConvertPromRule(prom *v1.PrometheusRule, conf *config.BaseOperatorConf) *v1
},
}
}
cr.Annotations = maybeAddArgoCDIgnoreAnnotations(conf.PrometheusConverterAddArgoCDIgnoreAnnotations, cr.Annotations)
return cr
}

func maybeAddArgoCDIgnoreAnnotations(mustAdd bool, dst map[string]string) map[string]string {
if !mustAdd {
// fast path
return dst
}
if dst == nil {
dst = make(map[string]string)
}
dst["argocd.argoproj.io/compare-options"] = "IgnoreExtraneous"
dst["argocd.argoproj.io/sync-options"] = "Prune=false"
return dst
}

func ConvertServiceMonitor(serviceMon *v1.ServiceMonitor, conf *config.BaseOperatorConf) *v1beta1vm.VMServiceScrape {
cs := &v1beta1vm.VMServiceScrape{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -100,6 +114,7 @@ func ConvertServiceMonitor(serviceMon *v1.ServiceMonitor, conf *config.BaseOpera
},
}
}
cs.Annotations = maybeAddArgoCDIgnoreAnnotations(conf.PrometheusConverterAddArgoCDIgnoreAnnotations, cs.Annotations)
return cs
}

Expand Down Expand Up @@ -326,6 +341,7 @@ func ConvertPodMonitor(podMon *v1.PodMonitor, conf *config.BaseOperatorConf) *v1
},
}
}
cs.Annotations = maybeAddArgoCDIgnoreAnnotations(conf.PrometheusConverterAddArgoCDIgnoreAnnotations, cs.Annotations)
return cs
}

Expand Down Expand Up @@ -395,6 +411,7 @@ func ConvertProbe(probe *v1.Probe, conf *config.BaseOperatorConf) *v1beta1vm.VMP
},
}
}
cp.Annotations = maybeAddArgoCDIgnoreAnnotations(conf.PrometheusConverterAddArgoCDIgnoreAnnotations, cp.Annotations)
return cp
}

Expand Down
7 changes: 5 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type BaseOperatorConf struct {
UseCustomConfigReloader bool `default:"false"`
// container registry name prefix, e.g. docker.io
ContainerRegistry string `default:""`
CustomConfigReloaderImage string `default:"victoriametrics/operator:config-reloader-0.1.0"`
CustomConfigReloaderImage string `default:"victoriametrics/operator:config-reloader-v0.27.0"`
PSPAutoCreateEnabled bool `default:"true"`
VMAlertDefault struct {
Image string `default:"victoriametrics/vmalert"`
Expand Down Expand Up @@ -223,7 +223,10 @@ type BaseOperatorConf struct {
PrometheusRule bool `default:"true"`
Probe bool `default:"true"`
}
EnabledPrometheusConverterOwnerReferences bool `default:"false"`
// adds compare-options and sync-options for prometheus objects converted by operator
// it helps to properly use converter with ArgoCD
PrometheusConverterAddArgoCDIgnoreAnnotations bool `default:"false"`
EnabledPrometheusConverterOwnerReferences bool `default:"false"`
// allows filtering for converted labels, labels with matched prefix will be ignored
FilterPrometheusConverterLabelPrefixes []string `default:""`
// allows filtering for converted annotations, annotations with matched prefix will be ignored
Expand Down

0 comments on commit 191bf96

Please sign in to comment.