Skip to content

Commit 055d36c

Browse files
cluster: fix infinite cluster load balancer configuration secret reconcile
1 parent 1b40e31 commit 055d36c

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ aliases:
1818
* FEATURE: [vmoperator](https://docs.victoriametrics.com/operator/): use `operator_bad_objects_total` metric with `object_namespace` and `crd` labels to track invalid objects managed by VMAgent, VMAuth, VMAlert and VMAlertmanager. Old `operator_alertmanager_bad_objects_count` and `operator_vmalert_bad_objects_count` are deprecated and will be removed in next releases.
1919

2020
* BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): fixed HPA cleanup logic for all cluster resources, before it was constantly recreated. Bug introduced in [this commit](https://github.com/VictoriaMetrics/operator/commit/983d1678c37497a7d03d2f57821219fd4975deec).
21+
* BUGFIX: [VMCluster](https://docs.victoriametrics.com/operator/resources/vmcluster/), [VLCluster](https://docs.victoriametrics.com/operator/resources/vlcluster/) and [VTCluster](https://docs.victoriametrics.com/operator/resources/vtcluster/): prevent cluster load balancer from infinite reconcile.
2122

2223
## [v0.66.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.66.1)
2324

internal/controller/operator/factory/vlcluster/vmauth_lb.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"sort"
7+
"strings"
78

89
appsv1 "k8s.io/api/apps/v1"
910
corev1 "k8s.io/api/core/v1"
@@ -92,26 +93,25 @@ func buildVMauthLBSecret(cr *vmv1.VLCluster) *corev1.Secret {
9293
selectURL := fmt.Sprintf("%s://%s.%s:%s",
9394
selectProto, cr.PrefixedInternalName(vmv1beta1.ClusterComponentSelect), targetHostSuffix, selectPort)
9495

95-
lbScrt := &corev1.Secret{
96-
ObjectMeta: buildLBConfigSecretMeta(cr),
97-
// TODO: add backend auth
98-
StringData: map[string]string{"config.yaml": fmt.Sprintf(`
96+
lbConfig := fmt.Sprintf(`
9997
unauthorized_user:
10098
url_map:
10199
- src_paths:
102100
- "/insert/.*"
103101
- "/internal/insert"
104-
url_prefix: "%s"
102+
url_prefix: %q
105103
discover_backend_ips: true
106104
- src_paths:
107105
- ".*"
108-
url_prefix: "%s"
106+
url_prefix: %q
109107
discover_backend_ips: true
110-
`, insertURL,
111-
selectURL,
112-
)},
108+
`, insertURL, selectURL)
109+
110+
return &corev1.Secret{
111+
ObjectMeta: buildLBConfigSecretMeta(cr),
112+
// TODO: add backend auth
113+
Data: map[string][]byte{"config.yaml": []byte(strings.TrimSpace(lbConfig))},
113114
}
114-
return lbScrt
115115
}
116116

117117
func buildVMauthLBDeployment(cr *vmv1.VLCluster) (*appsv1.Deployment, error) {

internal/controller/operator/factory/vmalert/vmalert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func TestCreateOrUpdate(t *testing.T) {
467467
Name: "notifier-cfg",
468468
Namespace: "default",
469469
},
470-
StringData: map[string]string{"cfg.yaml": "static: []"},
470+
Data: map[string][]byte{"cfg.yaml": []byte("static: []")},
471471
},
472472
&appsv1.Deployment{
473473
ObjectMeta: metav1.ObjectMeta{

internal/controller/operator/factory/vmcluster/vmcluster.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,24 +1285,27 @@ func buildVMAuthLBSecret(cr *vmv1beta1.VMCluster) *corev1.Secret {
12851285
if cr.Spec.VMInsert != nil {
12861286
insertPort = cr.Spec.VMInsert.Port
12871287
}
1288-
lbScrt := &corev1.Secret{
1289-
ObjectMeta: buildLBConfigSecretMeta(cr),
1290-
StringData: map[string]string{"config.yaml": fmt.Sprintf(`
1288+
1289+
insertUrl := fmt.Sprintf("http://srv+%s.%s:%s", cr.PrefixedInternalName(vmv1beta1.ClusterComponentInsert), targetHostSuffix, insertPort)
1290+
selectUrl := fmt.Sprintf("http://srv+%s.%s:%s", cr.PrefixedInternalName(vmv1beta1.ClusterComponentSelect), targetHostSuffix, selectPort)
1291+
1292+
lbConfig := fmt.Sprintf(`
12911293
unauthorized_user:
12921294
url_map:
12931295
- src_paths:
12941296
- "/insert/.*"
1295-
url_prefix: "http://srv+%s.%s:%s"
1297+
url_prefix: %q
12961298
discover_backend_ips: true
12971299
- src_paths:
12981300
- "/.*"
1299-
url_prefix: "http://srv+%s.%s:%s"
1301+
url_prefix: %q
13001302
discover_backend_ips: true
1301-
`, cr.PrefixedInternalName(vmv1beta1.ClusterComponentInsert), targetHostSuffix, insertPort,
1302-
cr.PrefixedInternalName(vmv1beta1.ClusterComponentSelect), targetHostSuffix, selectPort,
1303-
)},
1303+
`, insertUrl, selectUrl)
1304+
return &corev1.Secret{
1305+
ObjectMeta: buildLBConfigSecretMeta(cr),
1306+
// TODO: add backend auth
1307+
Data: map[string][]byte{"config.yaml": []byte(strings.TrimSpace(lbConfig))},
13041308
}
1305-
return lbScrt
13061309
}
13071310

13081311
func buildVMAuthLBDeployment(cr *vmv1beta1.VMCluster) (*appsv1.Deployment, error) {

internal/controller/operator/factory/vtcluster/vmauth_lb.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package vtcluster
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
appsv1 "k8s.io/api/apps/v1"
89
corev1 "k8s.io/api/core/v1"
@@ -91,26 +92,25 @@ func buildVMauthLBSecret(cr *vmv1.VTCluster) *corev1.Secret {
9192
selectURL := fmt.Sprintf("%s://%s.%s:%s",
9293
selectProto, cr.PrefixedInternalName(vmv1beta1.ClusterComponentSelect), targetHostSuffix, selectPort)
9394

94-
lbScrt := &corev1.Secret{
95-
ObjectMeta: buildLBConfigSecretMeta(cr),
96-
// TODO: add backend auth
97-
StringData: map[string]string{"config.yaml": fmt.Sprintf(`
95+
lbConfig := fmt.Sprintf(`
9896
unauthorized_user:
9997
url_map:
10098
- src_paths:
10199
- "/insert/.*"
102100
- "/internal/insert"
103-
url_prefix: "%s"
101+
url_prefix: %q
104102
discover_backend_ips: true
105103
- src_paths:
106104
- ".*"
107-
url_prefix: "%s"
105+
url_prefix: %q
108106
discover_backend_ips: true
109-
`, insertURL,
110-
selectURL,
111-
)},
107+
`, insertURL, selectURL)
108+
109+
return &corev1.Secret{
110+
ObjectMeta: buildLBConfigSecretMeta(cr),
111+
// TODO: add backend auth
112+
Data: map[string][]byte{"config.yaml": []byte(strings.TrimSpace(lbConfig))},
112113
}
113-
return lbScrt
114114
}
115115

116116
func buildVMauthLBDeployment(cr *vmv1.VTCluster) (*appsv1.Deployment, error) {

0 commit comments

Comments
 (0)