Repository: hetznercloud/hcloud-cloud-controller-manager (go)

Issue:
Loadbalancer service healthcheck for traefik
Hi,

i deployed traefik to my cluster and have service working for it:

```bash
traefik                                      ClusterIP      10.96.231.57   <none>                     8000/TCP,8080/TCP,4443/TCP,27017/TCP        32h
my-hetzner-loadbalancer   LoadBalancer   10.96.57.135   10.98.0.2,<hide external lb ip>   80:30862/TCP,8080:32150/TCP,443:32425/TCP   34h
whoami                                       ClusterIP      10.96.117.38   <none>                     80/TCP                                      24h
```

I cant get Loadbalancer work longer than durring "healthcheck". I I go to port 8080 as soon i start changes on my loadbalancer i get webpages and websocket to traefik dashboard is connected. It holds connection aslong as i let browser tab  open. I can also reach "whoami" container with HTTPS.

But after healthcheck is done it goes red on web page with status unhealthy. And after that i cant connect any of the services.

Can someone help we with that?

Same behaviour i have on other accounts and loadbalancers.

Here my output.

Here my description for LB Service:

```yaml
apiVersion: v1
kind: Service
metadata:
  name: my-hetzner-loadbalancer
  labels:
    app.kubernetes.io/name: hetzner-loadbalancer
    app.kubernetes.io/instance: my-hetzner
  annotations:
    # https://pkg.go.dev/github.com/hetznercloud/hcloud-cloud-controller-manager/internal/annotation?tab=doc
    load-balancer.hetzner.cloud/name: <my-hetzner-loadbalancer-name>
    load-balancer.hetzner.cloud/location: nbg1
    load-balancer.hetzner.cloud/type: "lb11"
    load-balancer.hetzner.cloud/use-private-ip: "true"
    load-balancer.hetzner.cloud/uses-proxyprotocol: "true"
spec:
  externalTrafficPolicy: Cluster
  selector:
    app.kubernetes.io/instance: traefik
    app.kubernetes.io/name: traefik
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8000
    - name: traefik
      port: 8080
      protocol: TCP
      targetPort: 8080
    - name: https
      port: 443
      protocol: TCP
      targetPort: 4443
  type: LoadBalancer
  externalTrafficPolicy: "Local"
```

Pull request:
Update default health check
Closes #87 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76df58fe..ec95218c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,9 @@ Changelog
 master
 ------
 * Fix: nil pointer dereference when Load Balancers were disabled
-* Update hcloud-go to 1.21.1
+* Update hcloud-go to 1.22.0
 * Update build to go 1.15
+* Fix: update default health check (#87)
 
 v1.7.0
 ------
diff --git a/go.mod b/go.mod
index feeba021..d43164cc 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/NYTimes/gziphandler v1.1.1 // indirect
 	github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
 	github.com/golang/groupcache v0.0.0-20171101203131-84a468cf14b4 // indirect
-	github.com/hetznercloud/hcloud-go v1.21.1
+	github.com/hetznercloud/hcloud-go v1.22.0
 	github.com/stretchr/testify v1.6.1
 	github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
 	gopkg.in/square/go-jose.v2 v2.3.0 // indirect
diff --git a/go.sum b/go.sum
index 01b521b8..5cf3db64 100644
--- a/go.sum
+++ b/go.sum
@@ -299,8 +299,8 @@ github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh
 github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
 github.com/heketi/heketi v9.0.1-0.20190917153846-c2e2a4ab7ab9+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva7RS5ytVoSoholZQON6o=
 github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7UkZt1i4FQeQy0R2T8GLUwQhOP5M1gBhy4=
-github.com/hetznercloud/hcloud-go v1.21.1 h1:LWNozxiZhKmeMqYbAS7KsAcPcxg47afCnTeLKmN+n7w=
-github.com/hetznercloud/hcloud-go v1.21.1/go.mod h1:xng8lbDUg+xM1dgc0yGHX5EeqbwIq7UYlMWMTx3SQVg=
+github.com/hetznercloud/hcloud-go v1.22.0 h1:CC0jwkaBzwP4ObFE0sdJBTvGh5DE9kB/tuDETnRfOik=
+github.com/hetznercloud/hcloud-go v1.22.0/go.mod h1:xng8lbDUg+xM1dgc0yGHX5EeqbwIq7UYlMWMTx3SQVg=
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
diff --git a/internal/hcops/load_balancer.go b/internal/hcops/load_balancer.go
index 10ae85f8..16f95b14 100644
--- a/internal/hcops/load_balancer.go
+++ b/internal/hcops/load_balancer.go
@@ -769,6 +769,11 @@ func (b *hclbServiceOptsBuilder) buildAddServiceOpts() (hcloud.LoadBalancerAddSe
 				TLS:         b.healthCheckOpts.httpOpts.TLS,
 			}
 		}
+	} else {
+		opts.HealthCheck = &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+			Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+			Port:     hcloud.Int(b.destinationPort),
+		}
 	}
 
 	return opts, nil
@@ -813,6 +818,11 @@ func (b *hclbServiceOptsBuilder) buildUpdateServiceOpts() (hcloud.LoadBalancerUp
 				TLS:         b.healthCheckOpts.httpOpts.TLS,
 			}
 		}
+	} else {
+		opts.HealthCheck = &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+			Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+			Port:     hcloud.Int(b.destinationPort),
+		}
 	}
 
 	return opts, nil


Test patch:
diff --git a/internal/hcops/load_balancer_internal_test.go b/internal/hcops/load_balancer_internal_test.go
index 408b3406..0252ec0d 100644
--- a/internal/hcops/load_balancer_internal_test.go
+++ b/internal/hcops/load_balancer_internal_test.go
@@ -25,10 +25,18 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
 				ListenPort:      hcloud.Int(80),
 				DestinationPort: hcloud.Int(8080),
 				Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
+				HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8080),
+				},
 			},
 			expectedUpdateOpts: hcloud.LoadBalancerUpdateServiceOpts{
 				DestinationPort: hcloud.Int(8080),
 				Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
+				HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8080),
+				},
 			},
 		},
 		{
@@ -42,11 +50,19 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
 				DestinationPort: hcloud.Int(8081),
 				Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 				Proxyprotocol:   hcloud.Bool(true),
+				HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8081),
+				},
 			},
 			expectedUpdateOpts: hcloud.LoadBalancerUpdateServiceOpts{
 				DestinationPort: hcloud.Int(8081),
 				Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 				Proxyprotocol:   hcloud.Bool(true),
+				HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8081),
+				},
 			},
 		},
 		{
@@ -71,6 +87,10 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
 					RedirectHTTP:   hcloud.Bool(true),
 					StickySessions: hcloud.Bool(true),
 				},
+				HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8082),
+				},
 			},
 			expectedUpdateOpts: hcloud.LoadBalancerUpdateServiceOpts{
 				DestinationPort: hcloud.Int(8082),
@@ -82,6 +102,10 @@ func TestHCLBServiceOptsBuilder(t *testing.T) {
 					RedirectHTTP:   hcloud.Bool(true),
 					StickySessions: hcloud.Bool(true),
 				},
+				HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+					Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+					Port:     hcloud.Int(8082),
+				},
 			},
 		},
 		{
diff --git a/internal/hcops/load_balancer_test.go b/internal/hcops/load_balancer_test.go
index 6351bdd7..914d9da1 100644
--- a/internal/hcops/load_balancer_test.go
+++ b/internal/hcops/load_balancer_test.go
@@ -802,6 +802,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 					Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 					ListenPort:      hcloud.Int(80),
 					DestinationPort: hcloud.Int(8080),
+					HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8080),
+					},
 				}
 				action := tt.fx.MockAddService(opts, tt.initialLB, nil)
 				tt.fx.MockWatchProgress(action, nil)
@@ -810,6 +814,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 					Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 					ListenPort:      hcloud.Int(443),
 					DestinationPort: hcloud.Int(8443),
+					HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8443),
+					},
 				}
 				action = tt.fx.MockAddService(opts, tt.initialLB, nil)
 				tt.fx.MockWatchProgress(action, nil)
@@ -841,6 +849,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 					Protocol:        hcloud.LoadBalancerServiceProtocolHTTP,
 					ListenPort:      hcloud.Int(81),
 					DestinationPort: hcloud.Int(8081),
+					HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8081),
+					},
 				}
 				action := tt.fx.MockAddService(opts, tt.initialLB, nil)
 				tt.fx.MockWatchProgress(action, nil)
@@ -849,6 +861,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 					Protocol:        hcloud.LoadBalancerServiceProtocolHTTP,
 					ListenPort:      hcloud.Int(444),
 					DestinationPort: hcloud.Int(8444),
+					HealthCheck: &hcloud.LoadBalancerAddServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8444),
+					},
 				}
 				action = tt.fx.MockAddService(opts, tt.initialLB, nil)
 				tt.fx.MockWatchProgress(action, nil)
@@ -881,6 +897,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 				opts := hcloud.LoadBalancerUpdateServiceOpts{
 					Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 					DestinationPort: hcloud.Int(8081),
+					HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8081),
+					},
 				}
 				action := tt.fx.MockUpdateService(opts, tt.initialLB, 80, nil)
 				tt.fx.MockWatchProgress(action, nil)
@@ -888,6 +908,10 @@ func TestLoadBalancerOps_ReconcileHCLBServices(t *testing.T) {
 				opts = hcloud.LoadBalancerUpdateServiceOpts{
 					Protocol:        hcloud.LoadBalancerServiceProtocolTCP,
 					DestinationPort: hcloud.Int(8444),
+					HealthCheck: &hcloud.LoadBalancerUpdateServiceOptsHealthCheck{
+						Protocol: hcloud.LoadBalancerServiceProtocolTCP,
+						Port:     hcloud.Int(8444),
+					},
 				}
 				action = tt.fx.MockUpdateService(opts, tt.initialLB, 443, nil)
 				tt.fx.MockWatchProgress(action, nil)