Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use full cfg in lbops #557

Merged
merged 1 commit into from
Nov 8, 2023
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
2 changes: 1 addition & 1 deletion hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *cloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
ActionClient: &c.client.Action,
NetworkClient: &c.client.Network,
NetworkID: c.networkID,
Cfg: c.cfg.LoadBalancer,
Cfg: c.cfg,
}

return newLoadBalancers(lbOps, c.cfg.LoadBalancer.DisablePrivateIngress, c.cfg.LoadBalancer.DisableIPv6), true
Expand Down
10 changes: 5 additions & 5 deletions internal/hcops/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type LoadBalancerOps struct {
CertOps *CertificateOps
RetryDelay time.Duration
NetworkID int64
Cfg config.LoadBalancerConfiguration
Cfg config.HCCMConfiguration
}

// GetByK8SServiceUID tries to find a Load Balancer by its Kubernetes service
Expand Down Expand Up @@ -164,8 +164,8 @@ func (l *LoadBalancerOps) Create(
if v, ok := annotation.LBType.StringFromService(svc); ok {
opts.LoadBalancerType.Name = v
}
if l.Cfg.Location != "" {
opts.Location = &hcloud.Location{Name: l.Cfg.Location}
if l.Cfg.LoadBalancer.Location != "" {
opts.Location = &hcloud.Location{Name: l.Cfg.LoadBalancer.Location}
}
if v, ok := annotation.LBLocation.StringFromService(svc); ok {
if v == "" {
Expand All @@ -176,7 +176,7 @@ func (l *LoadBalancerOps) Create(
opts.Location = &hcloud.Location{Name: v}
}
}
opts.NetworkZone = hcloud.NetworkZone(l.Cfg.NetworkZone)
opts.NetworkZone = hcloud.NetworkZone(l.Cfg.LoadBalancer.NetworkZone)
if v, ok := annotation.LBNetworkZone.StringFromService(svc); ok {
opts.NetworkZone = hcloud.NetworkZone(v)
}
Expand Down Expand Up @@ -658,7 +658,7 @@ func (l *LoadBalancerOps) getUsePrivateIP(svc *corev1.Service) (bool, error) {
usePrivateIP, err := annotation.LBUsePrivateIP.BoolFromService(svc)
if err != nil {
if errors.Is(err, annotation.ErrNotSet) {
return l.Cfg.UsePrivateIP, nil
return l.Cfg.LoadBalancer.UsePrivateIP, nil
}
return false, err
}
Expand Down
64 changes: 41 additions & 23 deletions internal/hcops/load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestGetByK8SServiceUID(t *testing.T) {
func TestLoadBalancerOps_Create(t *testing.T) {
type testCase struct {
name string
cfg config.LoadBalancerConfiguration
cfg config.HCCMConfiguration
serviceAnnotations map[annotation.Name]interface{}
createOpts hcloud.LoadBalancerCreateOpts
mock func(t *testing.T, tt *testCase, fx *hcops.LoadBalancerOpsFixture)
Expand All @@ -254,8 +254,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
tests := []testCase{
{
name: "create with with location name (and default set)",
cfg: config.LoadBalancerConfiguration{
Location: "hel1",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
Location: "hel1",
},
},
serviceAnnotations: map[annotation.Name]interface{}{
annotation.LBLocation: "fsn1",
Expand All @@ -274,8 +276,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
},
{
name: "create with network zone name only (and default set)",
cfg: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
},
},
serviceAnnotations: map[annotation.Name]interface{}{
annotation.LBNetworkZone: "eu-central",
Expand All @@ -292,8 +296,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
},
{
name: "create with location as default only",
cfg: config.LoadBalancerConfiguration{
Location: "fsn1",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
Location: "fsn1",
},
},
createOpts: hcloud.LoadBalancerCreateOpts{
Name: "some-lb",
Expand All @@ -309,8 +315,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
},
{
name: "create with network zone as default only",
cfg: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
},
},
createOpts: hcloud.LoadBalancerCreateOpts{
Name: "some-lb",
Expand All @@ -324,8 +332,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
},
{
name: "create with network zone and reset default location",
cfg: config.LoadBalancerConfiguration{
Location: "hel1",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
Location: "hel1",
},
},
serviceAnnotations: map[annotation.Name]interface{}{
annotation.LBLocation: "",
Expand All @@ -343,8 +353,10 @@ func TestLoadBalancerOps_Create(t *testing.T) {
},
{
name: "create with location and reset default network zone",
cfg: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
NetworkZone: "eu-central",
},
},
serviceAnnotations: map[annotation.Name]interface{}{
annotation.LBLocation: "fsn1",
Expand Down Expand Up @@ -590,7 +602,7 @@ func TestLoadBalancerOps_Delete(t *testing.T) {

type LBReconcilementTestCase struct {
name string
cfg config.LoadBalancerConfiguration
cfg config.HCCMConfiguration
serviceUID string
serviceAnnotations map[annotation.Name]interface{}
servicePorts []corev1.ServicePort
Expand Down Expand Up @@ -1189,9 +1201,11 @@ func TestLoadBalancerOps_ReconcileHCLBTargets(t *testing.T) {
},
{
name: "enable use of private network via default",
cfg: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: true,
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: true,
},
},
k8sNodes: []*corev1.Node{
{Spec: corev1.NodeSpec{ProviderID: "hcloud://1"}},
Expand Down Expand Up @@ -1219,9 +1233,11 @@ func TestLoadBalancerOps_ReconcileHCLBTargets(t *testing.T) {
},
{
name: "enable use of private network via annotation",
cfg: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: false,
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: false,
},
},
k8sNodes: []*corev1.Node{
{Spec: corev1.NodeSpec{ProviderID: "hcloud://1"}},
Expand Down Expand Up @@ -1252,9 +1268,11 @@ func TestLoadBalancerOps_ReconcileHCLBTargets(t *testing.T) {
},
{
name: "disable use of private network via annotation",
cfg: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: true,
cfg: config.HCCMConfiguration{
LoadBalancer: config.LoadBalancerConfiguration{
// Make sure the annotation overrides the default
UsePrivateIP: true,
},
},
k8sNodes: []*corev1.Node{
{Spec: corev1.NodeSpec{ProviderID: "hcloud://1"}},
Expand Down
Loading