Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ aliases:
* BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): recreate STS if immutable fields changed.
* BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): wait for STS deletion in case of recreation without throwing an error.
* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): ignore VMAuth update/delete operations if controller is disabled.
* BUGFIX: [vmalertmanager](https://docs.victoriametrics.com/operator/resources/vmalertmanager/): fixed ignored tracing config, when no alertmanagerconfig CRs collected. See [#1983](https://github.com/VictoriaMetrics/operator/issues/1983).

## [v0.68.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.68.1)
**Release date:** 23 February 2026
Expand Down
83 changes: 43 additions & 40 deletions internal/controller/operator/factory/vmalertmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ type parsedObjects struct {
}

func (pos *parsedObjects) buildConfig(cr *vmv1beta1.VMAlertmanager, baseCfg []byte, ac *build.AssetsCache) ([]byte, error) {
if len(pos.configs.All()) == 0 {
if len(pos.configs.All()) == 0 && cr.Spec.TracingConfig == nil {
return baseCfg, nil
}
var globalConfigOpts globalAlertmanagerConfig
if err := yaml.Unmarshal(baseCfg, &globalConfigOpts); err != nil {
return nil, fmt.Errorf("cannot parse global config options: %w", err)
}
var baseYAMLCfg alertmanagerConfig
if err := yaml.Unmarshal(baseCfg, &baseYAMLCfg); err != nil {
return nil, fmt.Errorf("cannot parse base cfg: %w", err)
Expand Down Expand Up @@ -63,49 +59,56 @@ func (pos *parsedObjects) buildConfig(cr *vmv1beta1.VMAlertmanager, baseCfg []by
})
}
}
var subRoutes []yaml.MapSlice
var timeIntervals []yaml.MapSlice
pos.configs.ForEachCollectSkipInvalid(func(cfg *vmv1beta1.VMAlertmanagerConfig) error {
if !build.MustSkipRuntimeValidation() {
if err := cfg.Validate(); err != nil {
return err
}

if len(pos.configs.All()) > 0 {
var globalConfigOpts globalAlertmanagerConfig
if err := yaml.Unmarshal(baseCfg, &globalConfigOpts); err != nil {
return nil, fmt.Errorf("cannot parse global config options: %w", err)
}
var receiverCfgs []yaml.MapSlice
for _, receiver := range cfg.Spec.Receivers {
receiverCfg, err := buildReceiver(cfg, receiver, &globalConfigOpts, ac)
if err != nil {
return err
var subRoutes []yaml.MapSlice
var timeIntervals []yaml.MapSlice
pos.configs.ForEachCollectSkipInvalid(func(cfg *vmv1beta1.VMAlertmanagerConfig) error {
if !build.MustSkipRuntimeValidation() {
if err := cfg.Validate(); err != nil {
return err
}
}
if len(receiverCfg) > 0 {
receiverCfgs = append(receiverCfgs, receiverCfg)
var receiverCfgs []yaml.MapSlice
for _, receiver := range cfg.Spec.Receivers {
receiverCfg, err := buildReceiver(cfg, receiver, &globalConfigOpts, ac)
if err != nil {
return err
}
if len(receiverCfg) > 0 {
receiverCfgs = append(receiverCfgs, receiverCfg)
}
}
}
mtis, err := buildGlobalTimeIntervals(cfg)
if err != nil {
return err
}
if cfg.Spec.Route != nil {
route, err := buildRoute(cfg, cfg.Spec.Route, true, cr)
mtis, err := buildGlobalTimeIntervals(cfg)
if err != nil {
return err
}
subRoutes = append(subRoutes, route)
}
baseYAMLCfg.Receivers = append(baseYAMLCfg.Receivers, receiverCfgs...)
for _, rule := range cfg.Spec.InhibitRules {
baseYAMLCfg.InhibitRules = append(baseYAMLCfg.InhibitRules, buildInhibitRule(cfg.Namespace, rule, !cr.Spec.DisableNamespaceMatcher))
if cfg.Spec.Route != nil {
route, err := buildRoute(cfg, cfg.Spec.Route, true, cr)
if err != nil {
return err
}
subRoutes = append(subRoutes, route)
}
baseYAMLCfg.Receivers = append(baseYAMLCfg.Receivers, receiverCfgs...)
for _, rule := range cfg.Spec.InhibitRules {
baseYAMLCfg.InhibitRules = append(baseYAMLCfg.InhibitRules, buildInhibitRule(cfg.Namespace, rule, !cr.Spec.DisableNamespaceMatcher))
}
if len(mtis) > 0 {
timeIntervals = append(timeIntervals, mtis...)
}
return nil
})
if len(subRoutes) > 0 {
baseYAMLCfg.Route.Routes = append(baseYAMLCfg.Route.Routes, subRoutes...)
}
if len(mtis) > 0 {
timeIntervals = append(timeIntervals, mtis...)
if len(timeIntervals) > 0 {
baseYAMLCfg.TimeIntervals = append(baseYAMLCfg.TimeIntervals, timeIntervals...)
}
return nil
})
if len(subRoutes) > 0 {
baseYAMLCfg.Route.Routes = append(baseYAMLCfg.Route.Routes, subRoutes...)
}
if len(timeIntervals) > 0 {
baseYAMLCfg.TimeIntervals = append(baseYAMLCfg.TimeIntervals, timeIntervals...)
}
if cr.Spec.TracingConfig != nil {
tracingCfg, err := buildTracingConfig(cr, ac)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,66 @@ func TestBuildConfig(t *testing.T) {
assert.Equal(t, o.want, string(data))
}

// tracing without discovered objects
f(opts{
cr: &vmv1beta1.VMAlertmanager{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
},
Spec: vmv1beta1.VMAlertmanagerSpec{
EnforcedNamespaceLabel: "alert-namespace",
ConfigNamespaceSelector: &metav1.LabelSelector{},
TracingConfig: &vmv1beta1.VMAlertmanagerTracingConfig{
Endpoint: "http://example.com",
TLSConfig: &vmv1beta1.TLSClientConfig{
CASecretRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "ca",
},
Key: "key",
},
},
Compression: "gzip",
HTTPHeaders: map[string]string{
"name": "value",
},
},
},
},
baseCfg: []byte(`global:
time_out: 1min
smtp_smarthost: some:443
`),
predefinedObjects: []runtime.Object{
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "ca",
Namespace: "default",
},
Data: map[string][]byte{
"key": []byte("value"),
},
},
},
want: `global:
smtp_smarthost: some:443
time_out: 1min
route:
receiver: blackhole
receivers:
- name: blackhole
templates: []
tracing:
tls_config:
ca_file: /etc/alertmanager/tls_assets/default_ca_key
compression: gzip
http_headers:
name: value
endpoint: http://example.com
`,
})

// override the top namespace matcher
f(opts{
cr: &vmv1beta1.VMAlertmanager{
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/vlcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ = Describe("test vlcluster Controller", Label("vl", "cluster", "vlcluster"
Expect(k8sClient.Create(ctx, cr)).ToNot(HaveOccurred())
Eventually(func() error {
return expectObjectStatusOperational(ctx, k8sClient, &vmv1.VLCluster{}, nsn)
}, eventualDeploymentAppReadyTimeout).ShouldNot(HaveOccurred())
}, eventualStatefulsetAppReadyTimeout).ShouldNot(HaveOccurred())
if verify != nil {
var created vmv1.VLCluster
Expect(k8sClient.Get(ctx, nsn, &created)).ToNot(HaveOccurred())
Expand Down Expand Up @@ -149,7 +149,7 @@ var _ = Describe("test vlcluster Controller", Label("vl", "cluster", "vlcluster"
Expect(k8sClient.Create(ctx, initCR)).ToNot(HaveOccurred())
Eventually(func() error {
return expectObjectStatusOperational(ctx, k8sClient, &vmv1.VLCluster{}, nsn)
}, eventualDeploymentAppReadyTimeout).ShouldNot(HaveOccurred())
}, eventualStatefulsetAppReadyTimeout).ShouldNot(HaveOccurred())

for _, step := range steps {
if step.setup != nil {
Expand All @@ -162,7 +162,7 @@ var _ = Describe("test vlcluster Controller", Label("vl", "cluster", "vlcluster"
Expect(k8sClient.Update(ctx, &toUpdate)).ToNot(HaveOccurred())
Eventually(func() error {
return expectObjectStatusOperational(ctx, k8sClient, &vmv1.VLCluster{}, nsn)
}, eventualDeploymentAppReadyTimeout).ShouldNot(HaveOccurred())
}, eventualStatefulsetAppReadyTimeout).ShouldNot(HaveOccurred())

var updated vmv1.VLCluster
Expect(k8sClient.Get(ctx, nsn, &updated)).ToNot(HaveOccurred())
Expand Down
Loading