Skip to content

Commit 06c6ea7

Browse files
authored
Merge pull request #7548 from alexander-demicev/controlplaneport
✨Make control plane port configurable in CAPD
2 parents a1c2fa8 + a2e7e63 commit 06c6ea7

File tree

8 files changed

+36
-16
lines changed

8 files changed

+36
-16
lines changed

test/e2e/data/infrastructure-docker/v1beta1/main/cluster-template-ipv6/cluster-ipv6.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ spec:
99
cidrBlocks: ['${DOCKER_SERVICE_IPV6_CIDRS}']
1010
pods:
1111
cidrBlocks: ['${DOCKER_POD_IPV6_CIDRS}']
12+
---
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
14+
kind: DockerCluster
15+
metadata:
16+
name: '${CLUSTER_NAME}'
17+
spec:
18+
controlPlaneEndpoint:
19+
port: 7777
20+
host: ""

test/infrastructure/docker/api/v1beta1/dockercluster_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type APIEndpoint struct {
9191
Host string `json:"host"`
9292

9393
// Port is the port on which the API server is serving.
94+
// Defaults to 6443 if not set.
9495
Port int `json:"port"`
9596
}
9697

test/infrastructure/docker/api/v1beta1/dockercluster_webhook.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ func (c *DockerCluster) ValidateDelete() error {
6161
return nil
6262
}
6363

64-
func defaultDockerClusterSpec(_ *DockerClusterSpec) {}
64+
func defaultDockerClusterSpec(s *DockerClusterSpec) {
65+
if s.ControlPlaneEndpoint.Port == 0 {
66+
s.ControlPlaneEndpoint.Port = 6443
67+
}
68+
}
6569

6670
func validateDockerClusterSpec(_ DockerClusterSpec) field.ErrorList {
6771
return nil

test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockerclusters.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/infrastructure/docker/config/crd/bases/infrastructure.cluster.x-k8s.io_dockerclustertemplates.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/infrastructure/docker/internal/controllers/dockercluster_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ func (r *DockerClusterReconciler) reconcileNormal(ctx context.Context, dockerClu
153153
return ctrl.Result{}, errors.Wrap(err, "failed to get ip for the load balancer")
154154
}
155155

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

161162
// Mark the dockerCluster ready

test/infrastructure/docker/internal/docker/kind_manager_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,6 @@ func TestCreateExternalLoadBalancerNode(t *testing.T) {
135135
g.Expect(runConfig).ToNot(BeNil())
136136
g.Expect(runConfig.Labels).To(HaveLen(2))
137137
g.Expect(runConfig.Labels["io.x-k8s.kind.role"]).To(Equal(constants.ExternalLoadBalancerNodeRoleValue))
138+
g.Expect(runConfig.PortMappings).To(HaveLen(1))
139+
g.Expect(runConfig.PortMappings[0].ContainerPort).To(Equal(int32(ControlPlanePort)))
138140
}

test/infrastructure/docker/internal/docker/loadbalancer.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ type lbCreator interface {
3838

3939
// LoadBalancer manages the load balancer for a specific docker cluster.
4040
type LoadBalancer struct {
41-
name string
42-
image string
43-
container *types.Node
44-
ipFamily clusterv1.ClusterIPFamily
45-
lbCreator lbCreator
41+
name string
42+
image string
43+
container *types.Node
44+
ipFamily clusterv1.ClusterIPFamily
45+
lbCreator lbCreator
46+
controlPlanePort int
4647
}
4748

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

7374
return &LoadBalancer{
74-
name: cluster.Name,
75-
image: image,
76-
container: container,
77-
ipFamily: ipFamily,
78-
lbCreator: &Manager{},
75+
name: cluster.Name,
76+
image: image,
77+
container: container,
78+
ipFamily: ipFamily,
79+
lbCreator: &Manager{},
80+
controlPlanePort: dockerCluster.Spec.ControlPlaneEndpoint.Port,
7981
}, nil
8082
}
8183

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

168170
loadBalancerConfig, err := loadbalancer.Config(&loadbalancer.ConfigData{
169-
ControlPlanePort: 6443,
171+
ControlPlanePort: s.controlPlanePort,
170172
BackendServers: backendServers,
171173
IPv6: s.ipFamily == clusterv1.IPv6IPFamily,
172174
})

0 commit comments

Comments
 (0)