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

Added wait and interval time flags to minikube service command #1651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/service"
)
Expand All @@ -34,6 +35,8 @@ var (
addonsURLMode bool
addonsURLFormat string
addonsURLTemplate *template.Template
wait int
interval int
)

const defaultAddonsFormatTemplate = "http://{{.IP}}:{{.Port}}"
Expand Down Expand Up @@ -101,7 +104,8 @@ You can add one by annotating a service with the label %s:%s
}
for i := range serviceList.Items {
svc := serviceList.Items[i].ObjectMeta.Name
service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate, addonsURLMode, https)
service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate,
addonsURLMode, https, wait, interval)

}
},
Expand All @@ -110,7 +114,8 @@ You can add one by annotating a service with the label %s:%s
func init() {
addonsOpenCmd.Flags().BoolVar(&addonsURLMode, "url", false, "Display the kubernetes addons URL in the CLI instead of opening it in the default browser")
addonsOpenCmd.Flags().BoolVar(&https, "https", false, "Open the addons URL with https instead of http")

addonsOpenCmd.Flags().IntVar(&wait, "wait", constants.DefaultWait, "Amount of time to wait for service in seconds")
addonsOpenCmd.Flags().IntVar(&interval, "interval", constants.DefaultInterval, "The time interval for each check that wait performs in seconds")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the wait flag, but interval seems a bit overkill. Any reason to not just try every 1-2 seconds, no matter what wait is?

Copy link
Contributor Author

@aaron-prindle aaron-prindle Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that, for users, I tested the timing (w/ 6 second interval) so that there were only ~3-6 outputs "waiting" if a user waited for a sensible service to come up (single pod service). For something automated, there is no real reason to have the wait be so high. I am fine with removing it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, simply using the wait flag will have a 6 second default, "minikube service --wait 300 nginx"

addonsOpenCmd.PersistentFlags().StringVar(&addonsURLFormat, "format", defaultAddonsFormatTemplate, "Format to output addons URL in. This format will be applied to each url individually and they will be printed one at a time.")
AddonsCmd.AddCommand(addonsOpenCmd)
}
8 changes: 7 additions & 1 deletion cmd/minikube/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/service"
)
Expand All @@ -35,6 +36,8 @@ var (
serviceURLMode bool
serviceURLFormat string
serviceURLTemplate *template.Template
wait int
interval int
)

// serviceCmd represents the service command
Expand Down Expand Up @@ -68,7 +71,8 @@ var serviceCmd = &cobra.Command{
defer api.Close()

cluster.EnsureMinikubeRunningOrExit(api, 1)
err = service.WaitAndMaybeOpenService(api, namespace, svc, serviceURLTemplate, serviceURLMode, https)
err = service.WaitAndMaybeOpenService(api, namespace, svc,
serviceURLTemplate, serviceURLMode, https, wait, interval)
if err != nil {
fmt.Fprintf(os.Stderr, "Error opening service: %s\n", err)
os.Exit(1)
Expand All @@ -80,6 +84,8 @@ func init() {
serviceCmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "The service namespace")
serviceCmd.Flags().BoolVar(&serviceURLMode, "url", false, "Display the kubernetes service URL in the CLI instead of opening it in the default browser")
serviceCmd.Flags().BoolVar(&https, "https", false, "Open the service URL with https instead of http")
serviceCmd.Flags().IntVar(&wait, "wait", constants.DefaultWait, "Amount of time to wait for a service in seconds")
serviceCmd.Flags().IntVar(&interval, "interval", constants.DefaultWait, "The time interval for each check that wait performs in seconds")

serviceCmd.PersistentFlags().StringVar(&serviceURLFormat, "format", defaultServiceFormatTemplate, "Format to output service URL in. This format will be applied to each url individually and they will be printed one at a time.")

Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const (
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
KubernetesVersionGCSURL = "https://storage.googleapis.com/minikube/k8s_releases.json"
DefaultWait = 20
DefaultInterval = 6
)

var DefaultIsoUrl = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetIsoPath(), minikubeVersion.GetIsoVersion())
Expand Down
5 changes: 3 additions & 2 deletions pkg/minikube/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ func checkEndpointReady(endpoints corev1.EndpointsInterface, service string) err
return nil
}

func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool) error {
if err := util.RetryAfter(20, func() error { return CheckService(namespace, service) }, 6*time.Second); err != nil {
func WaitAndMaybeOpenService(api libmachine.API, namespace string, service string, urlTemplate *template.Template, urlMode bool, https bool,
wait int, interval int) error {
if err := util.RetryAfter(wait, func() error { return CheckService(namespace, service) }, time.Duration(interval)*time.Second); err != nil {
return errors.Wrapf(err, "Could not find finalized endpoint being pointed to by %s", service)
}

Expand Down