Skip to content
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
28 changes: 24 additions & 4 deletions pkg/cluster/internal/create/actions/kubeadminit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pkg/errors"

"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/cluster/internal/haproxy"
"sigs.k8s.io/kind/pkg/cluster/internal/kubeadm"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/exec"
Expand Down Expand Up @@ -81,10 +82,7 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
// must be modified in order to use the random host port reserved
// for the API server and exposed by the node

// retrives the random host where the API server is exposed
// TODO(fabrizio pandini): when external load-balancer will be
// implemented this should be modified accordingly
hostPort, err := node.Ports(kubeadm.APIServerPort)
hostPort, err := getAPIServerPort(allNodes)
if err != nil {
return errors.Wrap(err, "failed to get kubeconfig from node")
}
Expand Down Expand Up @@ -143,6 +141,28 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
return nil
}

// getAPIServerPort returns the port on the host on which the APIServer
// is exposed
func getAPIServerPort(allNodes []nodes.Node) (int32, error) {
// select the external loadbalancer first
node, err := nodes.ExternalLoadBalancerNode(allNodes)
if err != nil {
return 0, err
}
// node will be nil if there is no load balancer
if node != nil {
return node.Ports(haproxy.ControlPlanePort)
}

// fallback to the bootstrap control plane
node, err = nodes.BootstrapControlPlaneNode(allNodes)
if err != nil {
return 0, err
}

return node.Ports(kubeadm.APIServerPort)
}

// a default storage class
// we need this for e2es (StatefulSet)
const defaultStorageClassManifest = `# host-path based default storage class
Expand Down
10 changes: 6 additions & 4 deletions pkg/cluster/internal/create/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ func nodesToCreate(cfg *config.Cluster, clusterName string) []nodeSpec {
if controlPlanes > 1 {
role := constants.ExternalLoadBalancerNodeRoleValue
desiredNodes = append(desiredNodes, nodeSpec{
Name: nameNode(role),
Image: controlPlaneImage, // TODO(bentheelder): get from config instead
Role: role,
ExtraMounts: []cri.Mount{},
Name: nameNode(role),
Image: controlPlaneImage, // TODO(bentheelder): get from config instead
Role: role,
ExtraMounts: []cri.Mount{},
APIServerAddress: cfg.Networking.APIServerAddress,
APIServerPort: cfg.Networking.APIServerPort,
})
}

Expand Down