Skip to content
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

fix HA cluster kubeconfig #418

Merged
merged 2 commits into from Mar 28, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+30 −8
Diff settings

Always

Just for now

@@ -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"
@@ -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")
}
@@ -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
@@ -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,
})
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.