mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
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
|
// WaitForRunningPodState blocks until pods are in running state
|
||||||
func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOptions) error {
|
func (kc KubeClient) WaitForPodState(ctx context.Context, opts WaitForStatusOptions) error {
|
||||||
var timeout time.Duration = time.Duration(60) * time.Second
|
var timeout time.Duration = time.Duration(60) * time.Second
|
||||||
if opts.Timeout > 0 {
|
if opts.Timeout != nil {
|
||||||
timeout = time.Duration(opts.Timeout) * time.Second
|
timeout = *opts.Timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
selector := fmt.Sprintf("%s=%s", compose.ProjectTag, opts.ProjectName)
|
selector := fmt.Sprintf("%s=%s", compose.ProjectTag, opts.ProjectName)
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
@ -40,6 +42,6 @@ type WaitForStatusOptions struct {
|
|||||||
ProjectName string
|
ProjectName string
|
||||||
Services []string
|
Services []string
|
||||||
Status string
|
Status string
|
||||||
Timeout int
|
Timeout *time.Duration
|
||||||
Log LogFunc
|
Log LogFunc
|
||||||
}
|
}
|
||||||
|
@ -92,20 +92,17 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
|
|
||||||
w.Event(progress.NewEvent(eventName, progress.Done, ""))
|
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{
|
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
||||||
ProjectName: project.Name,
|
ProjectName: project.Name,
|
||||||
Services: project.ServiceNames(),
|
Services: project.ServiceNames(),
|
||||||
Status: compose.RUNNING,
|
Status: compose.RUNNING,
|
||||||
Timeout: 60,
|
Log: func(pod string, stateReached bool, message string) {
|
||||||
Log: logF,
|
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{}
|
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{
|
err = s.client.WaitForPodState(ctx, client.WaitForStatusOptions{
|
||||||
ProjectName: projectName,
|
ProjectName: projectName,
|
||||||
Services: nil,
|
Services: nil,
|
||||||
Status: compose.REMOVING,
|
Status: compose.REMOVING,
|
||||||
Timeout: 60,
|
Timeout: options.Timeout,
|
||||||
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))
|
||||||
|
if !utils.StringContains(events, pod) {
|
||||||
|
events = append(events, pod)
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user