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

return IP address using kubeconfig --internal #1583

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 15 additions & 4 deletions pkg/cluster/internal/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ package kubeconfig

import (
"bytes"
"fmt"
"net"

"sigs.k8s.io/kind/pkg/cluster/internal/context"
"sigs.k8s.io/kind/pkg/cluster/internal/providers/provider/common"
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
"sigs.k8s.io/kind/pkg/errors"

Expand Down Expand Up @@ -89,15 +92,23 @@ func get(ctx *context.Context, external bool) (*kubeconfig.Config, error) {
return nil, errors.Wrap(err, "failed to get cluster internal kubeconfig")
}

// if we're doing external we need to override the server endpoint
server := ""
var endpoint string
if external {
endpoint, err := ctx.GetAPIServerEndpoint()
endpoint, err = ctx.GetAPIServerEndpoint()
if err != nil {
return nil, err
}
server = "https://" + endpoint
} else {
// TODO: make it independent of the IP protocol
// hardcoded to IPv4 because --internal is a flag used to get access
// from outside of the cluster and docker does not have IPv6 only support
host, _, err := node.IP()
if err != nil {
return nil, err
}
endpoint = net.JoinHostPort(host, fmt.Sprintf("%d", common.APIServerInternalPort))
}
server := "https://" + endpoint

// actually encode
return kubeconfig.KINDFromRawKubeadm(buff.String(), ctx.Name(), server)
Expand Down