Skip to content

Commit 990916b

Browse files
fix lbm hash change due to addition of proxy_url (#432)
* fix lbm hash change due to addition of proxy_url The hash is calculated by hashing the json serialization of a part of the LB spec. As `proxyUrl` was not marked as omitempty, this changed the serialized value even when proxyUrl was not set. * add test to detect lb hash changes * add testcase with additional fields set but same hash
1 parent 6c3edb9 commit 990916b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

api/v1beta1/loadbalancer_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ type LoadBalancerLogForward struct {
183183
LokiURL string `json:"lokiUrl"`
184184
// ProxyUrl defines the http proxy url to use for connection to loki
185185
// +optional
186-
ProxyURL string `json:"proxyUrl"`
186+
ProxyURL string `json:"proxyUrl,omitempty"`
187187
// Labels define extra labels for loki.
188188
// +optional
189189
Labels map[string]string `json:"labels"`

internal/helper/loadbalancermachine_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
. "github.com/onsi/gomega"
88
corev1 "k8s.io/api/core/v1"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/utils/ptr"
1011

1112
yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
1213
)
@@ -310,3 +311,61 @@ makestep 1 3
310311
`))
311312
})
312313
})
314+
315+
var _ = DescribeTable("GetHashForLoadBalancerMachineSet",
316+
func(lb *yawolv1beta1.LoadBalancer, expectedHash string) {
317+
hash, err := GetHashForLoadBalancerMachineSet(lb)
318+
Expect(err).ToNot(HaveOccurred())
319+
Expect(hash).To(Equal(expectedHash))
320+
},
321+
Entry("empty config", &yawolv1beta1.LoadBalancer{}, "ogwzb3hasmo2o2tj"),
322+
Entry("basic config", &yawolv1beta1.LoadBalancer{
323+
ObjectMeta: metav1.ObjectMeta{
324+
Name: "test",
325+
Namespace: "testspace",
326+
},
327+
Spec: yawolv1beta1.LoadBalancerSpec{
328+
DebugSettings: yawolv1beta1.LoadBalancerDebugSettings{
329+
Enabled: true,
330+
SshkeyName: "key",
331+
},
332+
Options: yawolv1beta1.LoadBalancerOptions{
333+
LogForward: yawolv1beta1.LoadBalancerLogForward{
334+
Enabled: true,
335+
LokiURL: "url",
336+
},
337+
ServerGroupPolicy: "affinity",
338+
},
339+
},
340+
Status: yawolv1beta1.LoadBalancerStatus{
341+
PortID: ptr.To("port"),
342+
ServerGroupName: ptr.To("group-name"),
343+
},
344+
}, "5h3dhrkdncr5csa7"),
345+
Entry("basic config with extra fields but same hash", &yawolv1beta1.LoadBalancer{
346+
ObjectMeta: metav1.ObjectMeta{
347+
Name: "test",
348+
Namespace: "testspace",
349+
},
350+
Spec: yawolv1beta1.LoadBalancerSpec{
351+
DebugSettings: yawolv1beta1.LoadBalancerDebugSettings{
352+
Enabled: true,
353+
SshkeyName: "key",
354+
},
355+
Options: yawolv1beta1.LoadBalancerOptions{
356+
LogForward: yawolv1beta1.LoadBalancerLogForward{
357+
Enabled: true,
358+
LokiURL: "url",
359+
},
360+
ServerGroupPolicy: "affinity",
361+
InternalLB: true, // extra
362+
},
363+
Replicas: 3, // extra
364+
},
365+
Status: yawolv1beta1.LoadBalancerStatus{
366+
PortID: ptr.To("port"),
367+
ServerGroupName: ptr.To("group-name"),
368+
ExternalIP: ptr.To("1.2.3.4"), // extra
369+
},
370+
}, "5h3dhrkdncr5csa7"),
371+
)

0 commit comments

Comments
 (0)