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

Fix the ship icon #845

Merged
merged 8 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ReleaseMetadata struct {
GithubContents []GithubContent `json:"githubContents" yaml:"githubContents" hcl:"githubContents" meta:"githubContents"`
ShipAppMetadata ShipAppMetadata `json:"shipAppMetadata" yaml:"shipAppMetadata" hcl:"shipAppMetadata" meta:"shipAppMetadata"`
Entitlements Entitlements `json:"entitlements" yaml:"entitlements" hcl:"entitlements" meta:"entitlements"`
Type string `json:"type" yaml:"type" hcl:"type" meta:"type"`
}

func (r ReleaseMetadata) ReleaseName() string {
Expand Down
8 changes: 5 additions & 3 deletions pkg/lifecycle/daemon/daemon_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestDaemonChannel(t *testing.T) {
name: "test_channel_noicon",
release: &api.Release{
Metadata: api.ReleaseMetadata{
Type: "replicated.app",
ChannelName: "Application",
ChannelIcon: "",
},
Expand All @@ -45,6 +46,7 @@ func TestDaemonChannel(t *testing.T) {
name: "test_channel_withicon",
release: &api.Release{
Metadata: api.ReleaseMetadata{
Type: "replicated.app",
ChannelName: "Clubhouse Enterprise",
ChannelIcon: "https://frontend-production-cdn.clubhouse.io/v0.5.20180509155736/images/logos/clubhouse_mascot_180x180.png",
},
Expand Down Expand Up @@ -93,7 +95,7 @@ func TestDaemonChannel(t *testing.T) {
// sigh. Give the server a second to start up
time.Sleep(500 * time.Millisecond)

resp, err := http.Get(fmt.Sprintf("http://localhost:%d/api/v1/channel", port))
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/api/v1/metadata", port))
require.NoError(t, err)

body, err := ioutil.ReadAll(resp.Body)
Expand All @@ -104,8 +106,8 @@ func TestDaemonChannel(t *testing.T) {
err = json.Unmarshal(body, &unmarshalled)
require.NoError(t, err)

require.Equal(t, test.expectName, unmarshalled["channelName"])
require.Equal(t, test.expectIcon, unmarshalled["channelIcon"])
require.Equal(t, test.expectName, unmarshalled["name"])
require.Equal(t, test.expectIcon, unmarshalled["icon"])
})
}
}
1 change: 1 addition & 0 deletions pkg/lifecycle/daemon/routes_navcycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type NavcycleRoutes struct {
func (d *NavcycleRoutes) Register(group *gin.RouterGroup, release *api.Release) {
d.Release = release
v1 := group.Group("/api/v1")
v1.GET("/metadata", d.getMetadata(release))
v1.GET("/navcycle", d.getNavcycle)
v1.GET("/navcycle/step/:step", d.getStep)
v1.POST("/navcycle/step/:step", d.completeStep)
Expand Down
28 changes: 28 additions & 0 deletions pkg/lifecycle/daemon/routes_navcycle_getmetadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package daemon

import (
"github.com/gin-gonic/gin"
"github.com/replicatedhq/ship/pkg/api"
)

func (d *NavcycleRoutes) getMetadata(release *api.Release) gin.HandlerFunc {
return func(c *gin.Context) {
switch release.Metadata.Type {
case "helm":
fallthrough
case "k8s":
c.JSON(200, release.Metadata.ShipAppMetadata)
return
case "runbook.replicated.app":
fallthrough
case "replicated.app":
fallthrough
case "inline.replicated.app":
c.JSON(200, map[string]interface{}{
"name": release.Metadata.ChannelName,
"icon": release.Metadata.ChannelIcon,
})
return
}
}
}
23 changes: 0 additions & 23 deletions pkg/lifecycle/daemon/routes_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func (d *V1Routes) Register(g *gin.RouterGroup, release *api.Release) {
mesg.POST("confirm", d.postConfirmMessage)
mesg.GET("get", d.getCurrentMessage)

v1.GET("/channel", d.getChannel(release))

v1.GET("/helm-metadata", d.getHelmMetadata(release))
v1.POST("/helm-values", d.saveHelmValues)
}

Expand All @@ -87,16 +84,6 @@ func (d *V1Routes) ClearProgress() {
d.stepProgress = nil
}

func (d *V1Routes) getHelmMetadata(release *api.Release) gin.HandlerFunc {
debug := level.Debug(log.With(d.Logger, "handler", "getHelmMetadata"))
debug.Log("event", "response.metadata")
return func(c *gin.Context) {
c.JSON(200, map[string]interface{}{
"metadata": release.Metadata.ShipAppMetadata,
})
}
}

type SaveValuesRequest struct {
Values string `json:"values"`
ReleaseName string `json:"releaseName"`
Expand Down Expand Up @@ -188,16 +175,6 @@ func (d *V1Routes) validateValuesOrAbort(c *gin.Context, request SaveValuesReque
return true
}

func (d *V1Routes) getChannel(release *api.Release) gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(200, map[string]interface{}{
"channelName": release.Metadata.ChannelName,
"channelIcon": release.Metadata.ChannelIcon,
})
}

}

func (d *V1Routes) getLoadingStep(c *gin.Context) {
c.JSON(200, map[string]interface{}{
"currentStep": map[string]interface{}{
Expand Down
4 changes: 3 additions & 1 deletion pkg/ship/ship.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func (s *Ship) Execute(ctx context.Context) error {
ReleaseSemver: s.ReleaseSemver,
InstallationID: s.InstallationID,
}
release, err := s.AppResolver.ResolveAppRelease(ctx, selector)

localAppCopy := apptype.NewLocalAppCopy("replicated.app", "", "")
release, err := s.AppResolver.ResolveAppRelease(ctx, selector, localAppCopy)
if err != nil {
return errors.Wrap(err, "resolve specs")
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/specs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (r *Resolver) ResolveRelease(ctx context.Context, upstream string) (*api.Re
return nil, errors.Wrapf(err, "parse url %s", upstream)
}
selector := (&replicatedapp.Selector{}).UnmarshalFrom(parsed)
return r.AppResolver.ResolveAppRelease(ctx, selector)
return r.AppResolver.ResolveAppRelease(ctx, selector, app)

case "inline.replicated.app":
return r.resolveInlineShipYAMLRelease(
Expand Down Expand Up @@ -451,6 +451,7 @@ func (r *Resolver) resolveRelease(
release := &api.Release{
Metadata: api.ReleaseMetadata{
ShipAppMetadata: *metadata,
Type: app.GetType(),
},
Spec: *spec,
}
Expand Down Expand Up @@ -523,6 +524,7 @@ func (r *Resolver) resolveInlineShipYAMLRelease(
release := &api.Release{
Metadata: api.ReleaseMetadata{
ShipAppMetadata: *metadata,
Type: app.GetType(),
},
Spec: *spec,
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/specs/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ icon: https://kfbr.392/x5.png
expectRelease: &api.Release{
Spec: viperResolver.DefaultHelmRelease("fake-tmp", "github.com/helm/charts/stable/x5"),
Metadata: api.ReleaseMetadata{
Type: "helm",
ShipAppMetadata: api.ShipAppMetadata{
Version: "0.1.0",
URL: "github.com/helm/charts/stable/x5",
Expand Down Expand Up @@ -148,7 +149,7 @@ icon: https://kfbr.392/x5.png
mockAppResolver.EXPECT().ResolveAppRelease(ctx, &replicatedapp2.Selector{
CustomerID: "12345",
InstallationID: "67890",
}).Return(&api.Release{
}, localApp).Return(&api.Release{
Metadata: api.ReleaseMetadata{
ChannelName: "appgraph-coolci",
},
Expand Down Expand Up @@ -206,6 +207,7 @@ icon: https://kfbr.392/x5.png
expectRelease: &api.Release{
Spec: viperResolver.DefaultRawRelease("base"),
Metadata: api.ReleaseMetadata{
Type: "k8s",
ShipAppMetadata: api.ShipAppMetadata{
URL: "github.com/replicatedhq/test-charts/plain-k8s",
Readme: "its the readme",
Expand Down Expand Up @@ -245,7 +247,7 @@ icon: https://kfbr.392/x5.png
CustomerID: "123",
InstallationID: "456",
ReleaseSemver: "789",
}).Return(&api.Release{
}, localApp).Return(&api.Release{
Metadata: api.ReleaseMetadata{
ChannelName: "appgraph-coolci",
},
Expand Down
7 changes: 6 additions & 1 deletion pkg/specs/replicatedapp/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"path/filepath"

"github.com/replicatedhq/ship/pkg/specs/apptype"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
Expand Down Expand Up @@ -63,6 +65,7 @@ type Resolver interface {
ResolveAppRelease(
ctx context.Context,
selector *Selector,
app apptype.LocalAppCopy,
) (*api.Release, error)
FetchRelease(
ctx context.Context,
Expand All @@ -80,7 +83,7 @@ type Resolver interface {

// ResolveAppRelease uses the passed config options to get specs from pg.replicated.com or
// from a local runbook if so configured
func (r *resolver) ResolveAppRelease(ctx context.Context, selector *Selector) (*api.Release, error) {
func (r *resolver) ResolveAppRelease(ctx context.Context, selector *Selector, app apptype.LocalAppCopy) (*api.Release, error) {
debug := level.Debug(log.With(r.Logger, "method", "ResolveAppRelease"))
release, err := r.FetchRelease(ctx, selector)
if err != nil {
Expand All @@ -100,6 +103,8 @@ func (r *resolver) ResolveAppRelease(ctx context.Context, selector *Selector) (*
return nil, errors.Wrap(err, "persist and deserialize release")
}

result.Metadata.Type = app.GetType()

return result, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/test-mocks/apptype/determine_type_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/test-mocks/config/resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading