diff --git a/kube/compose.go b/kube/compose.go index 389c7eae8..d998915a3 100644 --- a/kube/compose.go +++ b/kube/compose.go @@ -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{ diff --git a/kube/helm/helm.go b/kube/helm/helm.go index a8eeb1358..fd04f7879 100644 --- a/kube/helm/helm.go +++ b/kube/helm/helm.go @@ -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)