Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-02-23 13:26:45 +01:00
Родитель 48928811df
Коммит b3d39931b3
3 изменённых файлов: 23 добавлений и 26 удалений

Просмотреть файл

@ -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