Update existing stack installation on `compose up` instead of returning error

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-04-20 11:55:29 +02:00
parent 9279954193
commit bb25812511
2 changed files with 35 additions and 7 deletions

View File

@ -74,7 +74,7 @@ func NewComposeService() (compose.Service, error) {
func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
w := progress.ContextWriter(ctx)
eventName := "Convert to Helm charts"
eventName := "Convert Compose file to Helm charts"
w.Event(progress.CreatingEvent(eventName))
chart, err := helm.GetChartInMemory(project)
@ -83,16 +83,31 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
}
w.Event(progress.NewEvent(eventName, progress.Done, ""))
eventName = "Install Helm charts"
w.Event(progress.CreatingEvent(eventName))
stack, err := s.sdk.Get(project.Name)
if err != nil || stack == nil {
// install stack
eventName = "Install Compose stack"
w.Event(progress.CreatingEvent(eventName))
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
message := fmt.Sprintf(format, v...)
w.Event(progress.NewEvent(eventName, progress.Done, message))
})
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
message := fmt.Sprintf(format, v...)
w.Event(progress.NewEvent(eventName, progress.Done, message))
})
} else {
//update stack
eventName = "Updating Compose stack"
w.Event(progress.CreatingEvent(eventName))
err = s.sdk.UpdateChart(project.Name, chart, func(format string, v ...interface{}) {
message := fmt.Sprintf(format, v...)
w.Event(progress.NewEvent(eventName, progress.Done, message))
})
}
if err != nil {
return err
}
w.Event(progress.NewEvent(eventName, progress.Done, ""))
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{

View File

@ -84,6 +84,19 @@ func (hc *Actions) InstallChart(name string, chart *chart.Chart, logger func(for
return err
}
// UpdateChart upgrades chart
func (hc *Actions) UpdateChart(name string, chart *chart.Chart, logger func(format string, v ...interface{})) error {
err := hc.initialize(logger)
if err != nil {
return err
}
actUpgrade := action.NewUpgrade(hc.Config)
actUpgrade.Namespace = hc.Namespace
_, err = actUpgrade.Run(name, chart, map[string]interface{}{})
return err
}
// Uninstall uninstall chart
func (hc *Actions) Uninstall(name string, logger func(format string, v ...interface{})) error {
err := hc.initialize(logger)