Skip to content

Commit

Permalink
controllers/prometheus-converter: properly copy ScrapeConfig spec
Browse files Browse the repository at this point in the history
Previously full object was marshalled and unmarshalled into vm version of scrape config.
It breaks resource creation at kubernetes API, since resourceVersion shouldn't be specified during create request
#942
  • Loading branch information
f41gh7 committed Apr 27, 2024
1 parent a6e3ad7 commit 8f025b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions controllers/converter/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,23 @@ func filterPrefixes(src map[string]string, filterPrefixes []string) map[string]s

// ConvertScrapeConfig creates VMScrapeConfig from prometheus scrapeConfig
func ConvertScrapeConfig(promscrapeConfig *monitoringv1alpha1.ScrapeConfig, conf *config.BaseOperatorConf) *victoriametricsv1beta1.VMScrapeConfig {
cs := &victoriametricsv1beta1.VMScrapeConfig{}
data, err := json.Marshal(promscrapeConfig)
cs := &victoriametricsv1beta1.VMScrapeConfig{
ObjectMeta: metav1.ObjectMeta{
Name: promscrapeConfig.Name,
Namespace: promscrapeConfig.Namespace,
Labels: filterPrefixes(promscrapeConfig.Labels, conf.FilterPrometheusConverterLabelPrefixes),
Annotations: filterPrefixes(promscrapeConfig.Annotations, conf.FilterPrometheusConverterAnnotationPrefixes),
},
}
data, err := json.Marshal(promscrapeConfig.Spec)
if err != nil {
log.Error(err, "failed to marshal prometheus scrapeconfig for converting", "name", promscrapeConfig.Name, "namespace", promscrapeConfig.Namespace)
log.Error(err, "POSSIBLE BUG: failed to marshal prometheus scrapeconfig for converting", "name", promscrapeConfig.Name, "namespace", promscrapeConfig.Namespace)
return cs
}
err = json.Unmarshal(data, cs)
err = json.Unmarshal(data, &cs.Spec)
if err != nil {
log.Error(err, "failed to convert prometheus scrapeconfig to VMScrapeConfig", "name", promscrapeConfig.Name, "namespace", promscrapeConfig.Namespace)
log.Error(err, "POSSIBLE BUG: failed to convert prometheus scrapeconfig to VMScrapeConfig", "name", promscrapeConfig.Name, "namespace", promscrapeConfig.Namespace)
return cs
}
cs.Labels = filterPrefixes(promscrapeConfig.Labels, conf.FilterPrometheusConverterLabelPrefixes)
cs.Annotations = filterPrefixes(promscrapeConfig.Annotations, conf.FilterPrometheusConverterAnnotationPrefixes)
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ aliases:
## Next release

- [vmagent](./api.md#vmagent): set `status.selector` field. It allows correctly use `VPA` with `vmagent`. See this [issue](https://github.com/VictoriaMetrics/operator/issues/693) for details.
- [prometheus-converter](./README.md): fixes bug with prometheus-operator ScrapeConfig converter. Only copy `spec` field for it. See this [issue](https://github.com/VictoriaMetrics/operator/issues/942) for details.

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

Expand Down

0 comments on commit 8f025b3

Please sign in to comment.