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

Commit 65bf916

Browse files
committed
Merge branch 'master' of github.com:replicatedcom/ship into kustomize-merged-overlays
2 parents e2180cb + f43ca56 commit 65bf916

File tree

202 files changed

+23137
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+23137
-50
lines changed

Gopkg.lock

+110-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@
7575
[[constraint]]
7676
name = "k8s.io/client-go"
7777
version = "7.0.0"
78+
79+
[[constraint]]
80+
name = "k8s.io/helm"
81+
version = "2.9.1"

pkg/cli/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func RootCmd() *cobra.Command {
3838
cmd.PersistentFlags().IntP("api-port", "p", 8800, "port to start the API server on.")
3939
cmd.PersistentFlags().BoolP("headless", "", false, "run ship in headless mode")
4040
cmd.PersistentFlags().Bool("no-open", false, "skip opening the ship console in the default browser--does not disable the UI, has no effect if `headless` is set to true.")
41-
4241
cmd.PersistentFlags().String("state-file", "", "path to the state file to read from, defaults to .ship/state.json")
42+
cmd.PersistentFlags().String("resource-type", "", "upstream application resource type")
4343

4444
cmd.AddCommand(Init())
4545
cmd.AddCommand(Watch())

pkg/lifecycle/daemon/actions.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package daemon
22

3-
import "github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
3+
import (
4+
"github.com/replicatedhq/ship/pkg/lifecycle/daemon/daemontypes"
5+
)
46

57
func MessageActions() []daemontypes.Action {
68
return []daemontypes.Action{

pkg/lifecycle/daemon/routes_v1.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package daemon
22

33
import (
4+
"fmt"
45
"net/http"
56
"sync"
67

8+
"k8s.io/helm/pkg/lint/rules"
9+
"k8s.io/helm/pkg/lint/support"
10+
11+
"github.com/replicatedhq/ship/pkg/constants"
12+
713
"github.com/gin-gonic/gin"
814
"github.com/go-kit/kit/log"
915
"github.com/go-kit/kit/log/level"
@@ -234,13 +240,33 @@ func (d *V1Routes) saveHelmValues(c *gin.Context) {
234240
level.Error(d.Logger).Log("event", "unmarshal request body failed", "err", err)
235241
}
236242

237-
debug.Log("event", "serialize.helmValues")
243+
debug.Log("event", "validate")
244+
linter := support.Linter{ChartDir: constants.KustomizeHelmPath}
245+
rules.Templates(&linter, []byte(request.Values), "", false)
246+
247+
if len(linter.Messages) > 0 {
248+
var formattedErrors []string
249+
for _, message := range linter.Messages {
250+
formattedErrors = append(formattedErrors, message.Error())
251+
}
252+
253+
debug.Log(
254+
"event", "validate.fail",
255+
"errors", fmt.Sprintf("%+v", formattedErrors),
256+
)
257+
c.JSON(http.StatusBadRequest, map[string]interface{}{
258+
"errors": formattedErrors,
259+
})
260+
return
261+
}
262+
263+
debug.Log("event", "serialize")
238264
err := d.StateManager.SerializeHelmValues(request.Values)
239265
if err != nil {
240-
level.Error(d.Logger).Log("event", "seralize.helmValues.fail", "err", err)
241-
c.AbortWithError(500, errors.New("internal_server_error"))
266+
debug.Log("event", "seralize.fail", "err", err)
267+
c.AbortWithError(http.StatusInternalServerError, errors.New("internal_server_error"))
242268
}
243-
c.String(200, "")
269+
c.String(http.StatusOK, "")
244270
}
245271

246272
func (d *V1Routes) getChannel(release *api.Release) gin.HandlerFunc {

pkg/lifecycle/daemon/routes_v2_getstep.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package daemon
22

33
import (
4+
"fmt"
5+
46
"github.com/gin-gonic/gin"
57
"github.com/go-kit/kit/log"
68
"github.com/go-kit/kit/log/level"
@@ -31,6 +33,7 @@ func (d *V2Routes) getStep(c *gin.Context) {
3133
}
3234

3335
func (d *V2Routes) hydrateStep(step daemontypes.Step, isCurrent bool) (*daemontypes.StepResponse, error) {
36+
3437
if step.Kustomize != nil {
3538
// TODO(Robert): move this into TreeLoader, duplicated in V1 routes
3639
currentState, err := d.StateManager.TryLoad()
@@ -78,12 +81,40 @@ func (d *V2Routes) hydrateStep(step daemontypes.Step, isCurrent bool) (*daemonty
7881
result := &daemontypes.StepResponse{
7982
CurrentStep: step,
8083
Phase: step.Source.ShortName(),
81-
Actions: []daemontypes.Action{}, //todo actions
8284
}
8385

8486
if progress, ok := d.StepProgress.Load(step.Source.Shared().ID); ok {
8587
result.Progress = &progress
8688
}
8789

90+
actions := d.getActions(result.CurrentStep)
91+
result.Actions = actions
92+
8893
return result, nil
8994
}
95+
96+
func (d *V2Routes) getActions(step daemontypes.Step) []daemontypes.Action {
97+
if step.Message != nil {
98+
progress, ok := d.StepProgress.Load(step.Source.Shared().ID)
99+
100+
shouldAddActions := ok && progress.Detail != "success"
101+
102+
if shouldAddActions {
103+
return nil
104+
}
105+
106+
return []daemontypes.Action{
107+
{
108+
ButtonType: "primary",
109+
Text: "Confirm",
110+
LoadingText: "Confirming",
111+
OnClick: daemontypes.ActionRequest{
112+
URI: fmt.Sprintf("/api/v2/lifecycle/step/%s", step.Source.Shared().ID),
113+
Method: "POST",
114+
Body: "",
115+
},
116+
},
117+
}
118+
}
119+
return nil
120+
}

0 commit comments

Comments
 (0)