From c54be0bcb10e33e3570e99c9bb3cc022e86740db Mon Sep 17 00:00:00 2001 From: killianmuldoon Date: Tue, 7 Mar 2023 16:20:43 +0000 Subject: [PATCH] Make load balancer first-party package in CAPD --- .../src/developer/providers/v1.3-to-v1.4.md | 2 +- .../docker/internal/docker/loadbalancer.go | 2 +- .../forked => }/loadbalancer/config.go | 25 +++++++++++++------ .../forked => }/loadbalancer/const.go | 20 ++++++++------- .../forked => }/loadbalancer/doc.go | 5 ++-- .../internal/third_party/forked/README.md | 7 ------ 6 files changed, 33 insertions(+), 28 deletions(-) rename test/infrastructure/docker/internal/{third_party/forked => }/loadbalancer/config.go (72%) rename test/infrastructure/docker/internal/{third_party/forked => }/loadbalancer/const.go (56%) rename test/infrastructure/docker/internal/{third_party/forked => }/loadbalancer/doc.go (73%) delete mode 100644 test/infrastructure/docker/internal/third_party/forked/README.md diff --git a/docs/book/src/developer/providers/v1.3-to-v1.4.md b/docs/book/src/developer/providers/v1.3-to-v1.4.md index 574c78f2086f..2d5057ff91d3 100644 --- a/docs/book/src/developer/providers/v1.3-to-v1.4.md +++ b/docs/book/src/developer/providers/v1.3-to-v1.4.md @@ -70,7 +70,7 @@ maintainers of providers and consumers of our Go API. For more information, please see: https://github.com/kubernetes/enhancements/issues/2845 - A new `KCPRemediationSpec` test has been added providing better test coverage for KCP remediation most common use cases. As a consequence `MachineRemediationSpec` now only tests remediation of worker machines (NOTE: we plan to improve this test as well in a future iteration). - +- Package `test/infrastructure/docker/internal/third_party/forked/loadbalancer` has been moved to `test/infrastructure/docker/internal/loadbalancer` to allow it to diverge from the upstream Kind package. ### Suggested changes for providers - Providers should add an explicit security context to their controllers deployment, see [#7831](https://github.com/kubernetes-sigs/cluster-api/pull/7831) for reference. diff --git a/test/infrastructure/docker/internal/docker/loadbalancer.go b/test/infrastructure/docker/internal/docker/loadbalancer.go index 1508ad4dfc02..2126165b1c1b 100644 --- a/test/infrastructure/docker/internal/docker/loadbalancer.go +++ b/test/infrastructure/docker/internal/docker/loadbalancer.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/cluster-api/test/infrastructure/container" infrav1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1" "sigs.k8s.io/cluster-api/test/infrastructure/docker/internal/docker/types" - "sigs.k8s.io/cluster-api/test/infrastructure/docker/internal/third_party/forked/loadbalancer" + "sigs.k8s.io/cluster-api/test/infrastructure/docker/internal/loadbalancer" ) type lbCreator interface { diff --git a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/config.go b/test/infrastructure/docker/internal/loadbalancer/config.go similarity index 72% rename from test/infrastructure/docker/internal/third_party/forked/loadbalancer/config.go rename to test/infrastructure/docker/internal/loadbalancer/config.go index feb6ce2e9f4a..a17280f86bba 100644 --- a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/config.go +++ b/test/infrastructure/docker/internal/loadbalancer/config.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Kubernetes Authors. +Copyright 2023 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,19 +23,25 @@ import ( "sigs.k8s.io/kind/pkg/errors" ) -// ConfigData is supplied to the loadbalancer config template +// ConfigData is supplied to the loadbalancer config template. type ConfigData struct { ControlPlanePort int BackendServers map[string]string IPv6 bool } -// DefaultConfigTemplate is the loadbalancer config template -const DefaultConfigTemplate = `# generated by kind +// ConfigTemplate is the loadbalancer config template. +const ConfigTemplate = `# generated by kind global log /dev/log local0 log /dev/log local1 notice daemon + # limit memory usage to approximately 18 MB + maxconn 100000 + +resolvers docker + nameserver dns 127.0.0.11:53 + defaults log global mode tcp @@ -44,24 +50,27 @@ defaults timeout connect 5000 timeout client 50000 timeout server 50000 + # allow to boot despite dns don't resolve backends + default-server init-addr none + frontend control-plane bind *:{{ .ControlPlanePort }} {{ if .IPv6 -}} bind :::{{ .ControlPlanePort }}; {{- end }} default_backend kube-apiservers + backend kube-apiservers option httpchk GET /healthz # TODO: we should be verifying (!) {{range $server, $address := .BackendServers}} - server {{ $server }} {{ $address }} check check-ssl verify none + server {{ $server }} {{ $address }} check check-ssl verify none resolvers docker resolve-prefer {{ if $.IPv6 -}} ipv6 {{- else -}} ipv4 {{- end }} {{- end}} ` -// Config returns a kubeadm config generated from config data, in particular -// the kubernetes version +// Config generates the loadbalancer config from the ConfigTemplate and ConfigData. func Config(data *ConfigData) (config string, err error) { - t, err := template.New("loadbalancer-config").Parse(DefaultConfigTemplate) + t, err := template.New("loadbalancer-config").Parse(ConfigTemplate) if err != nil { return "", errors.Wrap(err, "failed to parse config template") } diff --git a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/const.go b/test/infrastructure/docker/internal/loadbalancer/const.go similarity index 56% rename from test/infrastructure/docker/internal/third_party/forked/loadbalancer/const.go rename to test/infrastructure/docker/internal/loadbalancer/const.go index 82bf261452ad..924536b6f433 100644 --- a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/const.go +++ b/test/infrastructure/docker/internal/loadbalancer/const.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Kubernetes Authors. +Copyright 2023 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,14 +16,16 @@ limitations under the License. package loadbalancer -// Image defines the loadbalancer image name -const Image = "haproxy" +const ( + // Image is the loadbalancer image name. + Image = "haproxy" -// DefaultImageRepository defines the loadbalancer image repository -const DefaultImageRepository = "kindest" + // DefaultImageRepository is the loadbalancer image repository. + DefaultImageRepository = "kindest" -// DefaultImageTag defines the loadbalancer image tag -const DefaultImageTag = "v20210715-a6da3463" + // DefaultImageTag is the loadbalancer image tag. + DefaultImageTag = "v20230227-d46f45b6" -// ConfigPath defines the path to the config file in the image -const ConfigPath = "/usr/local/etc/haproxy/haproxy.cfg" + // ConfigPath is the path to the config file in the image. + ConfigPath = "/usr/local/etc/haproxy/haproxy.cfg" +) diff --git a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/doc.go b/test/infrastructure/docker/internal/loadbalancer/doc.go similarity index 73% rename from test/infrastructure/docker/internal/third_party/forked/loadbalancer/doc.go rename to test/infrastructure/docker/internal/loadbalancer/doc.go index 6e53f388d302..d9317b49d21c 100644 --- a/test/infrastructure/docker/internal/third_party/forked/loadbalancer/doc.go +++ b/test/infrastructure/docker/internal/loadbalancer/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Kubernetes Authors. +Copyright 2023 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,5 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package loadbalancer contains external loadbalancer related constants and configuration +// Package loadbalancer contains external loadbalancer related constants and configuration. +// This package was originally forked from the kind load balancer at https://github.com/kubernetes-sigs/kind/tree/v0.7.0/pkg/cluster/internal/loadbalancer package loadbalancer diff --git a/test/infrastructure/docker/internal/third_party/forked/README.md b/test/infrastructure/docker/internal/third_party/forked/README.md deleted file mode 100644 index 8c73ad41fcbc..000000000000 --- a/test/infrastructure/docker/internal/third_party/forked/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# loadbalancer - -Repo: https://github.com/kubernetes-sigs/kind -Path: https://github.com/kubernetes-sigs/kind/tree/v0.7.0/pkg/cluster/internal/loadbalancer - -Tag: `v0.7.0` -