Skip to content

Commit

Permalink
Merge pull request #4058 from moduspwnens/master
Browse files Browse the repository at this point in the history
Fixed status checking with non-default apiserver-port.
  • Loading branch information
tstromberg authored Apr 8, 2019
2 parents f404df2 + b7ffe5b commit fad8355
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
8 changes: 5 additions & 3 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func runStart(cmd *cobra.Command, args []string) {
// The kube config must be update must come before bootstrapping, otherwise health checks may use a stale IP
kubeconfig := updateKubeConfig(host, &config)
bootstrapCluster(bs, cr, runner, config.KubernetesConfig, preexisting)
validateCluster(bs, cr, runner, ip)

apiserverPort := config.KubernetesConfig.NodePort
validateCluster(bs, cr, runner, ip, apiserverPort)
configureMounts()
if err = LoadCachedImagesInConfigFile(); err != nil {
console.Failure("Unable to load cached images from config file.")
Expand Down Expand Up @@ -543,7 +545,7 @@ func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner b
}

// validateCluster validates that the cluster is well-configured and healthy
func validateCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner bootstrapper.CommandRunner, ip string) {
func validateCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner bootstrapper.CommandRunner, ip string, apiserverPort int) {
console.OutStyle("verifying-noline", "Verifying component health ...")
k8sStat := func() (err error) {
st, err := bs.GetKubeletStatus()
Expand All @@ -558,7 +560,7 @@ func validateCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner bo
exit.WithLogEntries("kubelet checks failed", err, logs.FindProblems(r, bs, runner))
}
aStat := func() (err error) {
st, err := bs.GetAPIServerStatus(net.ParseIP(ip))
st, err := bs.GetAPIServerStatus(net.ParseIP(ip), apiserverPort)
console.Out(".")
if err != nil || st != state.Running.String() {
return &pkgutil.RetriableError{Err: fmt.Errorf("apiserver status=%s err=%v", st, err)}
Expand Down
8 changes: 7 additions & 1 deletion cmd/minikube/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ var statusCmd = &cobra.Command{
glog.Errorln("Error host driver ip status:", err)
}

apiserverSt, err = clusterBootstrapper.GetAPIServerStatus(ip)
apiserverPort, err := pkgutil.GetPortFromKubeConfig(util.GetKubeConfigPath(), config.GetMachineName())
if err != nil {
// Fallback to presuming default apiserver port
apiserverPort = pkgutil.APIServerPort
}

apiserverSt, err = clusterBootstrapper.GetAPIServerStatus(ip, apiserverPort)
if err != nil {
glog.Errorln("Error apiserver status:", err)
} else if apiserverSt != state.Running.String() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Bootstrapper interface {
LogCommands(LogOptions) map[string]string
SetupCerts(cfg config.KubernetesConfig) error
GetKubeletStatus() (string, error)
GetAPIServerStatus(net.IP) (string, error)
GetAPIServerStatus(net.IP, int) (string, error)
}

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (k *Bootstrapper) GetKubeletStatus() (string, error) {
}

// GetAPIServerStatus returns the api-server status
func (k *Bootstrapper) GetAPIServerStatus(ip net.IP) (string, error) {
url := fmt.Sprintf("https://%s:%d/healthz", ip, util.APIServerPort)
func (k *Bootstrapper) GetAPIServerStatus(ip net.IP, apiserverPort int) (string, error) {
url := fmt.Sprintf("https://%s:%d/healthz", ip, apiserverPort)
// To avoid: x509: certificate signed by unknown authority
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func UpdateKubeconfigIP(ip net.IP, filename string, machineName string) (bool, e
if kip.Equal(ip) {
return false, nil
}
kport, err := getPortFromKubeConfig(filename, machineName)
kport, err := GetPortFromKubeConfig(filename, machineName)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -291,8 +291,8 @@ func getIPFromKubeConfig(filename, machineName string) (net.IP, error) {
return ip, nil
}

// getPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified
func getPortFromKubeConfig(filename, machineName string) (int, error) {
// GetPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified
func GetPortFromKubeConfig(filename, machineName string) (int, error) {
con, err := ReadConfigOrNew(filename)
if err != nil {
return 0, errors.Wrap(err, "Error getting kubeconfig status")
Expand Down
3 changes: 2 additions & 1 deletion test/integration/start_stop_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func TestStartStop(t *testing.T) {
"--extra-config=kubelet.network-plugin=cni",
fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
}},
{"containerd", []string{
{"containerd_and_non_default_apiserver_port", []string{
"--container-runtime=containerd",
"--docker-opt containerd=/var/run/containerd/containerd.sock",
"--apiserver-port=8444",
}},
{"crio_ignore_preflights", []string{
"--container-runtime=crio",
Expand Down

0 comments on commit fad8355

Please sign in to comment.