mirror of https://github.com/docker/compose.git
add timeout for up/down
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
48928811df
commit
b3d39931b3
|
@ -118,8 +118,8 @@ func (kc *KubeClient) GetLogs(ctx context.Context, projectName string, consumer
|
|||
// WaitForRunningPodState blocks until pods are in running state
|
||||
func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOptions) error {
|
||||
var timeout time.Duration = time.Duration(60) * time.Second
|
||||
if opts.Timeout > 0 {
|
||||
timeout = time.Duration(opts.Timeout) * time.Second
|
||||
if opts.Timeout != nil {
|
||||
timeout = *opts.Timeout
|
||||
}
|
||||
|
||||
selector := fmt.Sprintf("%s=%s", compose.ProjectTag, opts.ProjectName)
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
@ -40,6 +42,6 @@ type WaitForStatusOptions struct {
|
|||
ProjectName string
|
||||
Services []string
|
||||
Status string
|
||||
Timeout int
|
||||
Timeout *time.Duration
|
||||
Log LogFunc
|
||||
}
|
||||
|
|
|
@ -92,20 +92,17 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||
|
||||
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
||||
|
||||
logF := func(pod string, stateReached bool, message string) {
|
||||
state := progress.Done
|
||||
if !stateReached {
|
||||
state = progress.Working
|
||||
}
|
||||
w.Event(progress.NewEvent(pod, state, message))
|
||||
}
|
||||
|
||||
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
||||
ProjectName: project.Name,
|
||||
Services: project.ServiceNames(),
|
||||
Status: compose.RUNNING,
|
||||
Timeout: 60,
|
||||
Log: logF,
|
||||
Log: func(pod string, stateReached bool, message string) {
|
||||
state := progress.Done
|
||||
if !stateReached {
|
||||
state = progress.Working
|
||||
}
|
||||
w.Event(progress.NewEvent(pod, state, message))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -133,23 +130,21 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
|
|||
}
|
||||
|
||||
events := []string{}
|
||||
logF := func(pod string, stateReached bool, message string) {
|
||||
state := progress.Done
|
||||
if !stateReached {
|
||||
state = progress.Working
|
||||
}
|
||||
w.Event(progress.NewEvent(pod, state, message))
|
||||
if !utils.StringContains(events, pod) {
|
||||
events = append(events, pod)
|
||||
}
|
||||
}
|
||||
|
||||
err = s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
||||
ProjectName: projectName,
|
||||
Services: nil,
|
||||
Status: compose.REMOVING,
|
||||
Timeout: 60,
|
||||
Log: logF,
|
||||
Timeout: options.Timeout,
|
||||
Log: func(pod string, stateReached bool, message string) {
|
||||
state := progress.Done
|
||||
if !stateReached {
|
||||
state = progress.Working
|
||||
}
|
||||
w.Event(progress.NewEvent(pod, state, message))
|
||||
if !utils.StringContains(events, pod) {
|
||||
events = append(events, pod)
|
||||
}
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue