Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit bb25812

Browse files
author
aiordache
committed
Update existing stack installation on compose up instead of returning error
Signed-off-by: aiordache <[email protected]>
1 parent 9279954 commit bb25812

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

kube/compose.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func NewComposeService() (compose.Service, error) {
7474
func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {
7575
w := progress.ContextWriter(ctx)
7676

77-
eventName := "Convert to Helm charts"
77+
eventName := "Convert Compose file to Helm charts"
7878
w.Event(progress.CreatingEvent(eventName))
7979

8080
chart, err := helm.GetChartInMemory(project)
@@ -83,16 +83,31 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
8383
}
8484
w.Event(progress.NewEvent(eventName, progress.Done, ""))
8585

86-
eventName = "Install Helm charts"
87-
w.Event(progress.CreatingEvent(eventName))
88-
89-
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
90-
message := fmt.Sprintf(format, v...)
91-
w.Event(progress.NewEvent(eventName, progress.Done, message))
92-
})
86+
stack, err := s.sdk.Get(project.Name)
87+
if err != nil || stack == nil {
88+
// install stack
89+
eventName = "Install Compose stack"
90+
w.Event(progress.CreatingEvent(eventName))
91+
92+
err = s.sdk.InstallChart(project.Name, chart, func(format string, v ...interface{}) {
93+
message := fmt.Sprintf(format, v...)
94+
w.Event(progress.NewEvent(eventName, progress.Done, message))
95+
})
96+
97+
} else {
98+
//update stack
99+
eventName = "Updating Compose stack"
100+
w.Event(progress.CreatingEvent(eventName))
101+
102+
err = s.sdk.UpdateChart(project.Name, chart, func(format string, v ...interface{}) {
103+
message := fmt.Sprintf(format, v...)
104+
w.Event(progress.NewEvent(eventName, progress.Done, message))
105+
})
106+
}
93107
if err != nil {
94108
return err
95109
}
110+
96111
w.Event(progress.NewEvent(eventName, progress.Done, ""))
97112

98113
return s.client.WaitForPodState(ctx, client.WaitForStatusOptions{

kube/helm/helm.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ func (hc *Actions) InstallChart(name string, chart *chart.Chart, logger func(for
8484
return err
8585
}
8686

87+
// UpdateChart upgrades chart
88+
func (hc *Actions) UpdateChart(name string, chart *chart.Chart, logger func(format string, v ...interface{})) error {
89+
err := hc.initialize(logger)
90+
if err != nil {
91+
return err
92+
}
93+
94+
actUpgrade := action.NewUpgrade(hc.Config)
95+
actUpgrade.Namespace = hc.Namespace
96+
_, err = actUpgrade.Run(name, chart, map[string]interface{}{})
97+
return err
98+
}
99+
87100
// Uninstall uninstall chart
88101
func (hc *Actions) Uninstall(name string, logger func(format string, v ...interface{})) error {
89102
err := hc.initialize(logger)

0 commit comments

Comments
 (0)