Skip to content

Commit

Permalink
fix lbm hash change due to addition of proxy_url (#432)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MichaelEischer authored Oct 31, 2024
1 parent 6c3edb9 commit 990916b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/v1beta1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type LoadBalancerLogForward struct {
LokiURL string `json:"lokiUrl"`
// ProxyUrl defines the http proxy url to use for connection to loki
// +optional
ProxyURL string `json:"proxyUrl"`
ProxyURL string `json:"proxyUrl,omitempty"`
// Labels define extra labels for loki.
// +optional
Labels map[string]string `json:"labels"`
Expand Down
59 changes: 59 additions & 0 deletions internal/helper/loadbalancermachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
)
Expand Down Expand Up @@ -310,3 +311,61 @@ makestep 1 3
`))
})
})

var _ = DescribeTable("GetHashForLoadBalancerMachineSet",
func(lb *yawolv1beta1.LoadBalancer, expectedHash string) {
hash, err := GetHashForLoadBalancerMachineSet(lb)
Expect(err).ToNot(HaveOccurred())
Expect(hash).To(Equal(expectedHash))
},
Entry("empty config", &yawolv1beta1.LoadBalancer{}, "ogwzb3hasmo2o2tj"),
Entry("basic config", &yawolv1beta1.LoadBalancer{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "testspace",
},
Spec: yawolv1beta1.LoadBalancerSpec{
DebugSettings: yawolv1beta1.LoadBalancerDebugSettings{
Enabled: true,
SshkeyName: "key",
},
Options: yawolv1beta1.LoadBalancerOptions{
LogForward: yawolv1beta1.LoadBalancerLogForward{
Enabled: true,
LokiURL: "url",
},
ServerGroupPolicy: "affinity",
},
},
Status: yawolv1beta1.LoadBalancerStatus{
PortID: ptr.To("port"),
ServerGroupName: ptr.To("group-name"),
},
}, "5h3dhrkdncr5csa7"),
Entry("basic config with extra fields but same hash", &yawolv1beta1.LoadBalancer{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "testspace",
},
Spec: yawolv1beta1.LoadBalancerSpec{
DebugSettings: yawolv1beta1.LoadBalancerDebugSettings{
Enabled: true,
SshkeyName: "key",
},
Options: yawolv1beta1.LoadBalancerOptions{
LogForward: yawolv1beta1.LoadBalancerLogForward{
Enabled: true,
LokiURL: "url",
},
ServerGroupPolicy: "affinity",
InternalLB: true, // extra
},
Replicas: 3, // extra
},
Status: yawolv1beta1.LoadBalancerStatus{
PortID: ptr.To("port"),
ServerGroupName: ptr.To("group-name"),
ExternalIP: ptr.To("1.2.3.4"), // extra
},
}, "5h3dhrkdncr5csa7"),
)

0 comments on commit 990916b

Please sign in to comment.