Skip to content

✨Make control plane port configurable in CAPD #7548

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

Merged
merged 1 commit into from
Jan 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ spec:
cidrBlocks: ['${DOCKER_SERVICE_IPV6_CIDRS}']
pods:
cidrBlocks: ['${DOCKER_POD_IPV6_CIDRS}']
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerCluster
metadata:
name: '${CLUSTER_NAME}'
spec:
controlPlaneEndpoint:
port: 7777
host: ""
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type APIEndpoint struct {
Host string `json:"host"`

// Port is the port on which the API server is serving.
// Defaults to 6443 if not set.
Port int `json:"port"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (c *DockerCluster) ValidateDelete() error {
return nil
}

func defaultDockerClusterSpec(_ *DockerClusterSpec) {}
func defaultDockerClusterSpec(s *DockerClusterSpec) {
if s.ControlPlaneEndpoint.Port == 0 {
s.ControlPlaneEndpoint.Port = 6443
}
}

func validateDockerClusterSpec(_ DockerClusterSpec) field.ErrorList {
return nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ func (r *DockerClusterReconciler) reconcileNormal(ctx context.Context, dockerClu
return ctrl.Result{}, errors.Wrap(err, "failed to get ip for the load balancer")
}

dockerCluster.Spec.ControlPlaneEndpoint = infrav1.APIEndpoint{
Host: lbIP,
Port: 6443,
if dockerCluster.Spec.ControlPlaneEndpoint.Host == "" {
// Surface the control plane endpoint
// Note: the control plane port is already set by the user or defaulted by the dockerCluster webhook.
dockerCluster.Spec.ControlPlaneEndpoint.Host = lbIP
}

// Mark the dockerCluster ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,6 @@ func TestCreateExternalLoadBalancerNode(t *testing.T) {
g.Expect(runConfig).ToNot(BeNil())
g.Expect(runConfig.Labels).To(HaveLen(2))
g.Expect(runConfig.Labels["io.x-k8s.kind.role"]).To(Equal(constants.ExternalLoadBalancerNodeRoleValue))
g.Expect(runConfig.PortMappings).To(HaveLen(1))
g.Expect(runConfig.PortMappings[0].ContainerPort).To(Equal(int32(ControlPlanePort)))
}
24 changes: 13 additions & 11 deletions test/infrastructure/docker/internal/docker/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ type lbCreator interface {

// LoadBalancer manages the load balancer for a specific docker cluster.
type LoadBalancer struct {
name string
image string
container *types.Node
ipFamily clusterv1.ClusterIPFamily
lbCreator lbCreator
name string
image string
container *types.Node
ipFamily clusterv1.ClusterIPFamily
lbCreator lbCreator
controlPlanePort int
}

// NewLoadBalancer returns a new helper for managing a docker loadbalancer with a given name.
Expand Down Expand Up @@ -71,11 +72,12 @@ func NewLoadBalancer(ctx context.Context, cluster *clusterv1.Cluster, dockerClus
image := getLoadBalancerImage(dockerCluster)

return &LoadBalancer{
name: cluster.Name,
image: image,
container: container,
ipFamily: ipFamily,
lbCreator: &Manager{},
name: cluster.Name,
image: image,
container: container,
ipFamily: ipFamily,
lbCreator: &Manager{},
controlPlanePort: dockerCluster.Spec.ControlPlaneEndpoint.Port,
}, nil
}

Expand Down Expand Up @@ -166,7 +168,7 @@ func (s *LoadBalancer) UpdateConfiguration(ctx context.Context) error {
}

loadBalancerConfig, err := loadbalancer.Config(&loadbalancer.ConfigData{
ControlPlanePort: 6443,
ControlPlanePort: s.controlPlanePort,
BackendServers: backendServers,
IPv6: s.ipFamily == clusterv1.IPv6IPFamily,
})
Expand Down