Skip to content

Commit

Permalink
Hetzner Cloud Load Balancer support (hetznercloud#49)
Browse files Browse the repository at this point in the history
Closes hetznercloud#48

Co-authored-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
fhofherr and LKaemmerling authored Jun 23, 2020
1 parent e9e21be commit df90212
Show file tree
Hide file tree
Showing 45 changed files with 5,977 additions and 412 deletions.
Empty file added .errcheck_excludes.txt
Empty file.
2 changes: 1 addition & 1 deletion .github/workflows/goimports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.12'
go-version: '1.14'
- uses: actions/checkout@master
- name: Check imports
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish_on_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.12'
go-version: '1.14'
- uses: actions/checkout@master
- name: Publish latest tag to registry
env:
Expand All @@ -19,4 +19,4 @@ jobs:
docker version
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
docker build -t hetznercloud/hcloud-cloud-controller-manager:latest .
docker push hetznercloud/hcloud-cloud-controller-manager:latest
docker push hetznercloud/hcloud-cloud-controller-manager:latest
2 changes: 1 addition & 1 deletion .github/workflows/publish_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.12'
go-version: '1.14'
- name: Set env
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
- uses: actions/checkout@master
Expand Down
28 changes: 17 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
---
name: Run tests
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: '1.12'
- uses: actions/checkout@master
- name: Run tests
run: |
docker pull lkdevelopment/hetzner-cloud-api-mock
docker run -d -p 127.0.0.1:4000:8080 lkdevelopment/hetzner-cloud-api-mock
docker ps -a
go vet ./...
go test ./...
- uses: actions/setup-go@v1
with:
go-version: '1.14'
- uses: actions/checkout@master
- name: Run tests
run: |
docker pull lkdevelopment/hetzner-cloud-api-mock
docker run -d -p 127.0.0.1:4000:8080 lkdevelopment/hetzner-cloud-api-mock
docker ps -a
go vet ./...
go test ./...
env:
API_MOCK_PORT: 4000
API_MOCK_SOURCE: https://docs-internal.staging.hc-k8s.de/hc_public_internal.apib
HCLOUD_ENDPOINT: http://127.0.0.1:4000/v1
HCLOUD_TOKEN: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin
/vendor
/vendor
.coverage.out
48 changes: 48 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
include:
- project: "hc/backend/deploy-tools"
file: "ci/release/image.yml"
- project: "hc/backend/deploy-tools"
file: "ci/build/image.yml"


stages:
- test
- build
- release

variables:
GOPROXY: goproxy.prodext.hcinfra.de
GONOSUMDB: hetzner.cloud

test:lint:
stage: test
image: golangci/golangci-lint:v1.27.0
allow_failure: true
script:
- golangci-lint run -v
except:
- tags
- master
tags:
- hc-bladerunner

test:unit:
stage: test
image: golang:1.14
services:
- name: lkdevelopment/hetzner-cloud-api-mock:latest
alias: api-mock
variables:
API_MOCK_PORT: 4000
API_MOCK_SOURCE: https://docs-internal.staging.hc-k8s.de/hc_public_internal.apib
HCLOUD_ENDPOINT: http://api-mock:4000/v1
HCLOUD_TOKEN: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
NODE_NAME: "test"
script:
- GO_PACKAGES=$(command go list ./... | tr "\n" ",")
- go test -race -covermode=atomic -coverprofile=.coverage.out ./... 2> /dev/null
- go tool cover -func=.coverage.out | tail -n1
coverage: '/total:[^\d]+(\d+\.\d+%)/'
tags:
- hc-bladerunner
47 changes: 47 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
linters-settings:
errcheck:
exclude: ./.errcheck_excludes.txt
gocyclo:
min-complexity: 15
misspell:
locale: "US"

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- errcheck
- gocritic
- gocyclo
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- misspell
- prealloc
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck
- whitespace

issues:
include:
- EXC0002 # disable excluding of issues about comments from golint

exclude-rules:
- path: _test\.go
linters:
- gosec
- linters:
- gosec
text: "G204:"
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
Changelog
=========

v1.6.0
------

* Add support for hcloud Load Balancer
* Update kubernetes dependencies to v1.16.2
* Update build to go 1.14

v1.5.2
------

* Fix nil pointer dereference if network does not exist anymore (#42).

v1.5.1
------

* Add better error handling and validation for certain errors related to wrong API tokens

v1.5.0
------

* Support for Kubernetes 1.16

v1.4.0
------

* Add Networks Support

v1.3.0
------

* Kubernetes 1.11 and 1.12 are now supported
* update hcloud-go to 1.12.0

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @LKaemmerling @fhofherr
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
FROM golang:1.12 as builder
FROM golang:1.14 as builder
WORKDIR /maschine-controller/src
ADD . .
RUN go mod download
RUN CGO_ENABLED=0 go build -o hcloud-maschine-controller.bin .


FROM alpine:3.9
FROM alpine:3.11
RUN apk add --no-cache ca-certificates bash
COPY --from=builder /maschine-controller/src/hcloud-maschine-controller.bin /bin/hcloud-cloud-controller-manager
ENTRYPOINT ["/bin/hcloud-cloud-controller-manager"]
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Read more about kubernetes cloud controller managers in the [kubernetes document

## Features

- **instances interface**
Adds the server type to the `beta.kubernetes.io/instance-type` label, sets the external ipv4 and ipv6 addresses and deletes nodes from Kubernetes that were deleted from the Hetzner Cloud.
- **zones interface**
Makes Kubernetes aware of the failure domain of the server by setting the `failure-domain.beta.kubernetes.io/region` and `failure-domain.beta.kubernetes.io/zone` labels on the node.
- **instances interface**: adds the server type to the `beta.kubernetes.io/instance-type` label, sets the external ipv4 and ipv6 addresses and deletes nodes from Kubernetes that were deleted from the Hetzner Cloud.
- **zones interface**: makes Kubernetes aware of the failure domain of the server by setting the `failure-domain.beta.kubernetes.io/region` and `failure-domain.beta.kubernetes.io/zone` labels on the node.
- **Private Networks**: allows to use Hetzner Cloud Private Networks for your pods traffic.
- **Load Balancers**: allows to use Hetzner Cloud Load Balancers with Kubernetes Services


## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
effect: "NoSchedule"
hostNetwork: true
containers:
- image: hetznercloud/hcloud-cloud-controller-manager:v1.5.2
- image: hetznercloud/hcloud-cloud-controller-manager:v1.6.0
name: hcloud-cloud-controller-manager
command:
- "/bin/hcloud-cloud-controller-manager"
Expand Down
2 changes: 1 addition & 1 deletion deploy/v1.5.2.yaml → deploy/v1.6.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
- key: "node.kubernetes.io/not-ready"
effect: "NoSchedule"
containers:
- image: hetznercloud/hcloud-cloud-controller-manager:v1.5.2
- image: hetznercloud/hcloud-cloud-controller-manager:v1.6.0
name: hcloud-cloud-controller-manager
command:
- "/bin/hcloud-cloud-controller-manager"
Expand Down
56 changes: 56 additions & 0 deletions docs/load_balancers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Load Balancers

Load Balancer support is implemented in the Cloud Controller as of
version v1.6.0. For using the Hetzner Cloud Load Balancers you need to
deploy a `Service` of type `LoadBalancer`.

## Sample Service:

```
apiVersion: v1
kind: Service
metadata:
name: example-service
annotations:
load-balancer.hetzner.cloud/location: hel1
spec:
selector:
app: example
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
```

The sample service will create a Load Balancer in the location `hel1`
with a service with `listen_port = 80` and `destination_port = 8080`. So
every traffic that arrives at the Load Balancer on Port 80 will be
routed to the public interface of the targets on port 8080. You can
change the behavior of the Load Balancer by specifying more annotations.
A list of all available annotations can be found on
[pkg.go.dev](https://pkg.go.dev/github.com/hetznercloud/hcloud-cloud-controller-manager/internal/annotation).
If you have the cloud controller deployed with Private Network Support,
we attach the Load Balancer to the specific network automatically. You
can specifiy with an annotation that the Load Balancer should use the
private network instead of the public network.

## Sample Service with Networks:

```
apiVersion: v1
kind: Service
metadata:
name: example-service
annotations:
load-balancer.hetzner.cloud/location: hel1
load-balancer.hetzner.cloud/use-private-ip: "true"
spec:
selector:
app: example
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
```


Loading

0 comments on commit df90212

Please sign in to comment.