Merge pull request #4058 from moduspwnens/master

Fixed status checking with non-default apiserver-port.
pull/3755/head
Thomas Strömberg 2019-04-08 11:48:29 -07:00 committed by GitHub
commit fad8355f99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 11 deletions

View File

@ -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 // The kube config must be update must come before bootstrapping, otherwise health checks may use a stale IP
kubeconfig := updateKubeConfig(host, &config) kubeconfig := updateKubeConfig(host, &config)
bootstrapCluster(bs, cr, runner, config.KubernetesConfig, preexisting) bootstrapCluster(bs, cr, runner, config.KubernetesConfig, preexisting)
validateCluster(bs, cr, runner, ip)
apiserverPort := config.KubernetesConfig.NodePort
validateCluster(bs, cr, runner, ip, apiserverPort)
configureMounts() configureMounts()
if err = LoadCachedImagesInConfigFile(); err != nil { if err = LoadCachedImagesInConfigFile(); err != nil {
console.Failure("Unable to load cached images from config file.") console.Failure("Unable to load cached images from config file.")
@ -543,7 +545,7 @@ func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner b
} }
// validateCluster validates that the cluster is well-configured and healthy // 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 ...") console.OutStyle("verifying-noline", "Verifying component health ...")
k8sStat := func() (err error) { k8sStat := func() (err error) {
st, err := bs.GetKubeletStatus() st, err := bs.GetKubeletStatus()
@ -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)) exit.WithLogEntries("kubelet checks failed", err, logs.FindProblems(r, bs, runner))
} }
aStat := func() (err error) { aStat := func() (err error) {
st, err := bs.GetAPIServerStatus(net.ParseIP(ip)) st, err := bs.GetAPIServerStatus(net.ParseIP(ip), apiserverPort)
console.Out(".") console.Out(".")
if err != nil || st != state.Running.String() { if err != nil || st != state.Running.String() {
return &pkgutil.RetriableError{Err: fmt.Errorf("apiserver status=%s err=%v", st, err)} return &pkgutil.RetriableError{Err: fmt.Errorf("apiserver status=%s err=%v", st, err)}

View File

@ -92,7 +92,13 @@ var statusCmd = &cobra.Command{
glog.Errorln("Error host driver ip status:", err) 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 { if err != nil {
glog.Errorln("Error apiserver status:", err) glog.Errorln("Error apiserver status:", err)
} else if apiserverSt != state.Running.String() { } else if apiserverSt != state.Running.String() {

View File

@ -43,7 +43,7 @@ type Bootstrapper interface {
LogCommands(LogOptions) map[string]string LogCommands(LogOptions) map[string]string
SetupCerts(cfg config.KubernetesConfig) error SetupCerts(cfg config.KubernetesConfig) error
GetKubeletStatus() (string, error) GetKubeletStatus() (string, error)
GetAPIServerStatus(net.IP) (string, error) GetAPIServerStatus(net.IP, int) (string, error)
} }
const ( const (

View File

@ -122,8 +122,8 @@ func (k *Bootstrapper) GetKubeletStatus() (string, error) {
} }
// GetAPIServerStatus returns the api-server status // GetAPIServerStatus returns the api-server status
func (k *Bootstrapper) GetAPIServerStatus(ip net.IP) (string, error) { func (k *Bootstrapper) GetAPIServerStatus(ip net.IP, apiserverPort int) (string, error) {
url := fmt.Sprintf("https://%s:%d/healthz", ip, util.APIServerPort) url := fmt.Sprintf("https://%s:%d/healthz", ip, apiserverPort)
// To avoid: x509: certificate signed by unknown authority // To avoid: x509: certificate signed by unknown authority
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},

View File

@ -251,7 +251,7 @@ func UpdateKubeconfigIP(ip net.IP, filename string, machineName string) (bool, e
if kip.Equal(ip) { if kip.Equal(ip) {
return false, nil return false, nil
} }
kport, err := getPortFromKubeConfig(filename, machineName) kport, err := GetPortFromKubeConfig(filename, machineName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -291,8 +291,8 @@ func getIPFromKubeConfig(filename, machineName string) (net.IP, error) {
return ip, nil return ip, nil
} }
// getPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified // GetPortFromKubeConfig returns the Port number stored for minikube in the kubeconfig specified
func getPortFromKubeConfig(filename, machineName string) (int, error) { func GetPortFromKubeConfig(filename, machineName string) (int, error) {
con, err := ReadConfigOrNew(filename) con, err := ReadConfigOrNew(filename)
if err != nil { if err != nil {
return 0, errors.Wrap(err, "Error getting kubeconfig status") return 0, errors.Wrap(err, "Error getting kubeconfig status")

View File

@ -46,9 +46,10 @@ func TestStartStop(t *testing.T) {
"--extra-config=kubelet.network-plugin=cni", "--extra-config=kubelet.network-plugin=cni",
fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion), fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
}}, }},
{"containerd", []string{ {"containerd_and_non_default_apiserver_port", []string{
"--container-runtime=containerd", "--container-runtime=containerd",
"--docker-opt containerd=/var/run/containerd/containerd.sock", "--docker-opt containerd=/var/run/containerd/containerd.sock",
"--apiserver-port=8444",
}}, }},
{"crio_ignore_preflights", []string{ {"crio_ignore_preflights", []string{
"--container-runtime=crio", "--container-runtime=crio",