close
The Wayback Machine - https://web.archive.org/web/20200905165509/https://github.com/kubernetes/minikube/issues/8658
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

minikube start --apiserver-names adds invalid entry to config.json #8658

Closed
BlackCrowned opened this issue Jul 6, 2020 · 7 comments
Closed

minikube start --apiserver-names adds invalid entry to config.json #8658

BlackCrowned opened this issue Jul 6, 2020 · 7 comments

Comments

@BlackCrowned
Copy link

@BlackCrowned BlackCrowned commented Jul 6, 2020

Steps to reproduce the issue:

Start minikube and set additional --apiserver-names:
minikube start --driver=docker --apiserver-names=localhost --apiserver-names=host.docker.internal

Output:

* minikube v1.12.0-beta.0 on Microsoft Windows 10 Education 10.0.18362 Build 18362
* Using the docker driver based on user configuration
* Starting control plane node minikube in cluster minikube
* Downloading Kubernetes v1.18.3 preload ...
    > preloaded-images-k8s-v3-v1.18.3-docker-overlay2-amd64.tar.lz4: 526.01 MiB
* Creating docker container (CPUs=2, Memory=4000MB) ...
* Preparing Kubernetes v1.18.3 on Docker 19.03.2 ...
  - kubeadm.pod-network-cidr=10.244.0.0/16
* Verifying Kubernetes components...
* Enabled addons: default-storageclass, storage-provisioner
* Done! kubectl is now configured to use "minikube"

! C:\Program Files\Docker\Docker\resources\bin\kubectl.exe is version 1.16.6-beta.0, which may be incompatible with Kubernetes 1.18.3.
* You can also use 'minikube kubectl -- get pods' to invoke a matching version

Expected Outcome:

In .minikube/profiles/minikube/config.json add entries "localhost" and "host.docker.internal" to ApiServerNames:

"KubernetesConfig": {
		"KubernetesVersion": "v1.18.3",
		"ClusterName": "minikube",
		"APIServerName": "minikubeCA",
		"APIServerNames": [
			"localhost",
			"host.docker.internal"
		],
		"APIServerIPs": null,
		"DNSDomain": "cluster.local",
		"ContainerRuntime": "docker",
		"CRISocket": "",
		"NetworkPlugin": "",
		"FeatureGates": "",
		"ServiceCIDR": "10.96.0.0/12",
		"ImageRepository": "",
		"LoadBalancerStartIP": "",
		"LoadBalancerEndIP": "",
		"ExtraOptions": [
			{
				"Component": "kubeadm",
				"Key": "pod-network-cidr",
				"Value": "10.244.0.0/16"
			}
		],
		"ShouldLoadCachedImages": true,
		"EnableDefaultCNI": false,
		"NodeIP": "",
		"NodePort": 8443,
		"NodeName": ""
	},

Actual Outcome:
The Entry "[localhost,host.docker.internal]" was added:

"KubernetesConfig": {
		"KubernetesVersion": "v1.18.3",
		"ClusterName": "minikube",
		"APIServerName": "minikubeCA",
		"APIServerNames": [
			"[localhost,host.docker.internal]"
		],
		"APIServerIPs": null,
		"DNSDomain": "cluster.local",
		"ContainerRuntime": "docker",
		"CRISocket": "",
		"NetworkPlugin": "",
		"FeatureGates": "",
		"ServiceCIDR": "10.96.0.0/12",
		"ImageRepository": "",
		"LoadBalancerStartIP": "",
		"LoadBalancerEndIP": "",
		"ExtraOptions": [
			{
				"Component": "kubeadm",
				"Key": "pod-network-cidr",
				"Value": "10.244.0.0/16"
			}
		],
		"ShouldLoadCachedImages": true,
		"EnableDefaultCNI": false,
		"NodeIP": "",
		"NodePort": 8443,
		"NodeName": ""
	},
@BlackCrowned
Copy link
Author

@BlackCrowned BlackCrowned commented Jul 6, 2020

Can't seem to reproduce

@jemygraw
Copy link

@jemygraw jemygraw commented Aug 13, 2020

This problem really exists for the following version:

appdelivery@appdelivery-qvm-1:~$ minikube version
minikube version: v1.12.1
commit: 997fd89b9d3a0072e3112c79d906b6367e760473-dirty
@jemygraw
Copy link

@jemygraw jemygraw commented Aug 13, 2020

@BlackCrowned it is right when you first run the minikube start command, and when you re-run the minikube start, it is wrong. So if you just run a new minikube, you will not reproduce it.

@jemygraw
Copy link

@jemygraw jemygraw commented Aug 13, 2020

@BlackCrowned I found the code which cause this error:

https://github.com/kubernetes/minikube/blob/master/cmd/minikube/cmd/start_flags.go#L539

viper.GetStringSlice does not return the expected slice.

I0813 14:45:12.401533   90740 start_flags.go:539] existing: {v1.18.3 minikube minikubeCA [k8s-beta.duokexuetang.com k8s-prod-replica.duokexuetang.com] [] cluster.local docker    10.96.0.0/12    [] true false   8443 }
I0813 14:45:12.401574   90740 start_flags.go:540] viper: [[k8s-beta.duokexuetang.com,k8s-prod-replica.duokexuetang.com]]
@jemygraw
Copy link

@jemygraw jemygraw commented Aug 13, 2020

It is a bug caused by package viper

// ToStringSliceE casts an interface to a []string type.
func ToStringSliceE(i interface{}) ([]string, error) {
	var a []string

	switch v := i.(type) {
	case []interface{}:
		for _, u := range v {
			a = append(a, ToString(u))
		}
		return a, nil
	case []string:
		return v, nil
	case string:
		return strings.Fields(v), nil
	case interface{}:
		str, err := ToStringE(v)
		if err != nil {
			return a, fmt.Errorf("unable to cast %#v of type %T to []string", i, i)
		}
		return []string{str}, nil
	default:
		return a, fmt.Errorf("unable to cast %#v of type %T to []string", i, i)
	}
}
@jemygraw
Copy link

@jemygraw jemygraw commented Aug 13, 2020

@BlackCrowned I write a simple program to express what happens.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var apiserverNames []string

type ClusterConfig struct {
	KubernetesConfig KubernetesConfig
}

type KubernetesConfig struct {
	APIServerNames []string
}

var startCmd = cobra.Command{
	Use: "start",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("apiserverNames=", viper.GetStringSlice("apiserver-names"))
		kubeConfig := KubernetesConfig{
			APIServerNames: apiserverNames,
		}
		clusterConfig := ClusterConfig{
			KubernetesConfig: kubeConfig,
		}
		data, _ := json.MarshalIndent(&clusterConfig, "", "    ")
		fmt.Println("Output=", string(data))
	},
}

func init() {
	startCmd.PersistentFlags().StringArrayVar(&apiserverNames, "apiserver-names", nil, "apiserver names")
	viper.BindPFlags(startCmd.PersistentFlags())
}

func main() {
	rootCmd := cobra.Command{}
	rootCmd.AddCommand(&startCmd)
	fmt.Println(rootCmd.Execute())
}

Output:

apiserverNames= [[hello,world]]
Output= {
    "KubernetesConfig": {
        "APIServerNames": [
            "hello",
            "world"
        ]
    }
}
@BlackCrowned
Copy link
Author

@BlackCrowned BlackCrowned commented Aug 13, 2020

@jemygraw Thank you for looking into this and creating a new issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.