Skip to content

Commit

Permalink
save profile
Browse files Browse the repository at this point in the history
  • Loading branch information
medyagh committed Apr 7, 2020
1 parent a350065 commit bee6815
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func runStart(cmd *cobra.Command, args []string) {
updateDriver(driverName)
}

cc, n, err := generateCfgFromFlags(cmd, *existing)
cc, n, err := generateCfgFromFlags(cmd, existing)
if err != nil {
exit.WithError("Failed to generate config", err)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func runStart(cmd *cobra.Command, args []string) {
}
}

if err := showKubectlInfo(kubeconfig, k8sVersion, cc.Name); err != nil {
if err := showKubectlInfo(kubeconfig, cc.KubernetesConfig.KubernetesVersion, cc.Name); err != nil {
glog.Errorf("kubectl info: %v", err)
}
}
Expand Down
67 changes: 31 additions & 36 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,27 @@ func ClusterFlagValue() string {
}

// generateCfgFromFlags generates config.ClusterConfig based on flags and supplied arguments
func generateCfgFromFlags(cmd *cobra.Command, existing config.ClusterConfig) (config.ClusterConfig, config.Node, error) {
func generateCfgFromFlags(cmd *cobra.Command, existing *config.ClusterConfig) (config.ClusterConfig, config.Node, error) {
cc := config.ClusterConfig{}

existing = updateExistingConfigFromFlags(cmd, existing)
r, err := cruntime.New(cruntime.Config{Type: existing.KubernetesConfig.ContainerRuntime})
if existing == nil { // create profile config first time
if err := config.CreateEmptyProfile(ClusterFlagValue()); err != nil {
return cc, config.Node{}, errors.Wrap(err, "create empty profile config")
}
} else {
cc = updateExistingConfigFromFlags(cmd, existing)
}

r, err := cruntime.New(cruntime.Config{Type: cc.KubernetesConfig.ContainerRuntime})
if err != nil {
return existing, config.Node{}, errors.Wrap(err, "new runtime manager")
return cc, config.Node{}, errors.Wrap(err, "new runtime manager")
}

// Pick good default values for --network-plugin and --enable-default-cni based on runtime.
if r.DefaultCNI() && !cmd.Flags().Changed(networkPlugin) {
existing.KubernetesConfig.NetworkPlugin = "cni"
cc.KubernetesConfig.NetworkPlugin = "cni"
if !cmd.Flags().Changed(enableDefaultCNI) {
existing.KubernetesConfig.EnableDefaultCNI = true
cc.KubernetesConfig.EnableDefaultCNI = true
}
}

Expand All @@ -165,13 +173,13 @@ func generateCfgFromFlags(cmd *cobra.Command, existing config.ClusterConfig) (co
}

if cmd.Flags().Changed(imageRepository) {
existing.KubernetesConfig.ImageRepository = viper.GetString(imageRepository)
cc.KubernetesConfig.ImageRepository = viper.GetString(imageRepository)
}

mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry))

if strings.ToLower(existing.KubernetesConfig.ImageRepository) == "auto" || mirrorCountry != "" {
found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(strings.TrimPrefix(getKubernetesVersion(&existing), version.VersionPrefix)))
if strings.ToLower(cc.KubernetesConfig.ImageRepository) == "auto" || mirrorCountry != "" {
found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, semver.MustParse(strings.TrimPrefix(getKubernetesVersion(&cc), version.VersionPrefix)))
if err != nil {
exit.WithError("Failed to check main repository and mirrors for images for images", err)
}
Expand All @@ -183,22 +191,23 @@ func generateCfgFromFlags(cmd *cobra.Command, existing config.ClusterConfig) (co
out.WarningT("None of the known repositories in your location are accessible. Using {{.image_repository_name}} as fallback.", out.V{"image_repository_name": autoSelectedRepository})
}
}
existing.KubernetesConfig.ImageRepository = autoSelectedRepository
cc.KubernetesConfig.ImageRepository = autoSelectedRepository
}

if cmd.Flags().Changed(imageRepository) {
out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": existing.KubernetesConfig.ImageRepository})
out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": cc.KubernetesConfig.ImageRepository})
}

var kubeNodeName string
if driver.BareMetal(existing.Driver) {
if driver.BareMetal(cc.Driver) {
kubeNodeName = "m01"
}
return createNode(cmd, existing, kubeNodeName)
return createNode(cmd, cc, kubeNodeName)
}

// updateExistingConfigFromFlags will update the existing config from the flags - used on a second start
func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterConfig) config.ClusterConfig {
// skipping updating existing docker env , docker opt, InsecureRegistry, registryMirror, extra-config, apiserver-ips
func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterConfig) config.ClusterConfig {
if cmd.Flags().Changed(containerRuntime) {
existing.KubernetesConfig.ContainerRuntime = viper.GetString(containerRuntime)
}
Expand Down Expand Up @@ -240,6 +249,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
}
existing.DiskSize = d
}

if cmd.Flags().Changed("vm-driver") {
existing.Driver = viper.GetString("vm-driver")
}
Expand All @@ -253,7 +263,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
}

if cmd.Flags().Changed(vsockPorts) {
existing.HyperkitVSockPorts = viper.GetString(vsockPorts)
existing.HyperkitVSockPorts = viper.GetStringSlice(vsockPorts)
}

if cmd.Flags().Changed(nfsShare) {
Expand All @@ -264,12 +274,6 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
existing.NFSSharesRoot = viper.GetString(nfsSharesRoot)
}

// skipping updating existing docker env , docker opt, InsecureRegistry, registryMirror

if cmd.Flags().Changed(vpnkitSock) {
existing.NFSSharesRoot = viper.GetStringSlice(nfsSharesRoot)
}

if cmd.Flags().Changed(hostOnlyCIDR) {
existing.HostOnlyCIDR = viper.GetString(hostOnlyCIDR)
}
Expand All @@ -279,7 +283,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
}

if cmd.Flags().Changed(hypervUseExternalSwitch) {
existing.HypervUseExternalSwitch = viper.GetString(hypervUseExternalSwitch)
existing.HypervUseExternalSwitch = viper.GetBool(hypervUseExternalSwitch)
}

if cmd.Flags().Changed(hypervExternalAdapter) {
Expand All @@ -295,11 +299,11 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
}

if cmd.Flags().Changed(kvmGPU) {
existing.KVMGPU = viper.GetString(kvmGPU)
existing.KVMGPU = viper.GetBool(kvmGPU)
}

if cmd.Flags().Changed(kvmHidden) {
existing.KVMHidden = viper.GetString(kvmHidden)
existing.KVMHidden = viper.GetBool(kvmHidden)
}

if cmd.Flags().Changed(disableDriverMounts) {
Expand Down Expand Up @@ -339,11 +343,7 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
}

if cmd.Flags().Changed("apiserver-names") {
existing.KubernetesConfig.APIServerNames = viper.GetString("apiserver-names")
}

if cmd.Flags().Changed("apiserver-ips") {
existing.KubernetesConfig.APIServerIPs = viper.GetString("apiserver-ips")
existing.KubernetesConfig.APIServerNames = viper.GetStringSlice("apiserver-names")
}

if cmd.Flags().Changed(dnsDomain) {
Expand Down Expand Up @@ -378,21 +378,17 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing config.ClusterCo
existing.KubernetesConfig.ShouldLoadCachedImages = viper.GetBool(cacheImages)
}

if cmd.Flags().Changed("extra-config") {
existing.KubernetesConfig.ExtraOptions = viper.GetVar("extra-config")
}

if cmd.Flags().Changed(imageRepository) {
existing.KubernetesConfig.ImageRepository = viper.GetString(imageRepository)
}

if cmd.Flags().Changed(enableDefaultCNI) {
existing.KubernetesConfig.EnableDefaultCNI = viper.GetBool(enableDefaultCNI)
}

existing.VerifyComponents = interpretWaitFlag(*cmd)

return existing
return *existing
}

// interpretWaitFlag interprets the wait flag and respects the legacy minikube users
Expand Down Expand Up @@ -439,4 +435,3 @@ func interpretWaitFlag(cmd cobra.Command) map[string]bool {
glog.Infof("Waiting for components: %+v", waitComponents)
return waitComponents
}

1 change: 1 addition & 0 deletions pkg/minikube/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...

func (c *simpleConfigLoader) WriteConfigToFile(profileName string, cc *ClusterConfig, miniHome ...string) error {
// Move to profile package
fmt.Println("inside WriteConfigToFile")
path := profileFilePath(profileName, miniHome...)
contents, err := json.MarshalIndent(cc, "", " ")
if err != nil {
Expand Down

0 comments on commit bee6815

Please sign in to comment.