Skip to content

Commit b5fd843

Browse files
Merge pull request #1651 from aaron-prindle/configurable-service-wait
Added wait and interval time flags to minikube service command
2 parents 32316ac + 79b9e10 commit b5fd843

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

cmd/minikube/cmd/config/open.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/spf13/cobra"
2525
"k8s.io/minikube/pkg/minikube/assets"
2626
"k8s.io/minikube/pkg/minikube/cluster"
27+
"k8s.io/minikube/pkg/minikube/constants"
2728
"k8s.io/minikube/pkg/minikube/machine"
2829
"k8s.io/minikube/pkg/minikube/service"
2930
)
@@ -34,6 +35,8 @@ var (
3435
addonsURLMode bool
3536
addonsURLFormat string
3637
addonsURLTemplate *template.Template
38+
wait int
39+
interval int
3740
)
3841

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

106110
}
107111
},
@@ -110,7 +114,8 @@ You can add one by annotating a service with the label %s:%s
110114
func init() {
111115
addonsOpenCmd.Flags().BoolVar(&addonsURLMode, "url", false, "Display the kubernetes addons URL in the CLI instead of opening it in the default browser")
112116
addonsOpenCmd.Flags().BoolVar(&https, "https", false, "Open the addons URL with https instead of http")
113-
117+
addonsOpenCmd.Flags().IntVar(&wait, "wait", constants.DefaultWait, "Amount of time to wait for service in seconds")
118+
addonsOpenCmd.Flags().IntVar(&interval, "interval", constants.DefaultInterval, "The time interval for each check that wait performs in seconds")
114119
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.")
115120
AddonsCmd.AddCommand(addonsOpenCmd)
116121
}

cmd/minikube/cmd/service.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/spf13/cobra"
2525
"k8s.io/minikube/pkg/minikube/cluster"
26+
"k8s.io/minikube/pkg/minikube/constants"
2627
"k8s.io/minikube/pkg/minikube/machine"
2728
"k8s.io/minikube/pkg/minikube/service"
2829
)
@@ -35,6 +36,8 @@ var (
3536
serviceURLMode bool
3637
serviceURLFormat string
3738
serviceURLTemplate *template.Template
39+
wait int
40+
interval int
3841
)
3942

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

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

8490
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.")
8591

pkg/minikube/constants/constants.go

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const (
9696
DefaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"
9797
GithubMinikubeReleasesURL = "https://storage.googleapis.com/minikube/releases.json"
9898
KubernetesVersionGCSURL = "https://storage.googleapis.com/minikube/k8s_releases.json"
99+
DefaultWait = 20
100+
DefaultInterval = 6
99101
)
100102

101103
var DefaultIsoUrl = fmt.Sprintf("https://storage.googleapis.com/%s/minikube-%s.iso", minikubeVersion.GetIsoPath(), minikubeVersion.GetIsoVersion())

pkg/minikube/service/service.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ func checkEndpointReady(endpoints corev1.EndpointsInterface, service string) err
217217
return nil
218218
}
219219

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

0 commit comments

Comments
 (0)