Skip to content

Commit

Permalink
add validateImageRepository func for validates --image-repository args
Browse files Browse the repository at this point in the history
  • Loading branch information
yxxhero committed Mar 9, 2021
1 parent 3760bf7 commit 416f92a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@ func validateFlags(cmd *cobra.Command, drvName string) {
validateListenAddress(viper.GetString(listenAddress))
}

if cmd.Flags().Changed(imageRepository) {
validateImageRepository(viper.GetString(imageRepository))
}

if cmd.Flags().Changed(containerRuntime) {
runtime := strings.ToLower(viper.GetString(containerRuntime))

Expand Down Expand Up @@ -1208,6 +1212,18 @@ func validateRegistryMirror() {
}
}

// This function validates if the --image-repository
// args match the format of registry.cn-hangzhou.aliyuncs.com/google_containers
func validateImageRepository(imagRepo string) {
URL, err := url.Parse(imagRepo)
if err != nil {
klog.Errorln("Error Parsing URL: ", err)
}
if URL.Scheme != "" || strings.HasSuffix(URL.Path, "/") {
exit.Message(reason.Usage, "Sorry, the url provided with the --image-repository flag is invalid: {{.url}}", out.V{"url": imagRepo})
}
}

// This function validates if the --listen-address
// match the format 0.0.0.0
func validateListenAddress(listenAddr string) {
Expand Down

0 comments on commit 416f92a

Please sign in to comment.