Skip to content

Commit 69580e0

Browse files
authored
Inconsistent channel info 63010 (#230)
* checkpoint: de-couple client.GetClient() from v1 api * Move install commands from client to cli The commands are presentation-layer strings, derived from the app and channel. * fix channel test to use new type * only include install commands for kots apps
1 parent 34acc1f commit 69580e0

File tree

14 files changed

+149
-142
lines changed

14 files changed

+149
-142
lines changed

cli/cmd/channel_counts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (r *runners) channelCounts(cmd *cobra.Command, args []string) error {
2525
chanID := args[0]
2626

2727
if r.appType == "platform" {
28-
appChan, _, err := r.api.GetChannel(r.appID, r.appType, chanID)
28+
appChan, _, err := r.platformAPI.GetChannel(r.appID, chanID)
2929
if err != nil {
3030
return err
3131
}

cli/cmd/channel_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (r *runners) InitChannelCreate(parent *cobra.Command) {
2424
}
2525

2626
func (r *runners) channelCreate(cmd *cobra.Command, args []string) error {
27-
allChannels, err := r.api.CreateChannel(r.appID, r.appType, r.appSlug, r.args.channelCreateName, r.args.channelCreateDescription)
27+
allChannels, err := r.api.CreateChannel(r.appID, r.appType, r.args.channelCreateName, r.args.channelCreateDescription)
2828
if err != nil {
2929
return err
3030
}

cli/cmd/channel_inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ func (r *runners) channelInspect(_ *cobra.Command, args []string) error {
2525
}
2626

2727
channelNameOrID := args[0]
28-
appChan, err := r.api.GetChannelByName(r.appID, r.appType, r.appSlug, channelNameOrID)
28+
appChan, err := r.api.GetChannelByName(r.appID, r.appType, channelNameOrID)
2929
if err != nil {
3030
return err
3131
}
3232

33-
if err = print.ChannelAttrs(r.w, appChan); err != nil {
33+
if err = print.ChannelAttrs(r.w, r.appType, r.appSlug, appChan); err != nil {
3434
return err
3535
}
3636

cli/cmd/channel_ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *runners) InitChannelList(parent *cobra.Command) {
1717
}
1818

1919
func (r *runners) channelList(cmd *cobra.Command, args []string) error {
20-
channels, err := r.api.ListChannels(r.appID, r.appType, r.appSlug, "")
20+
channels, err := r.api.ListChannels(r.appID, r.appType, "")
2121
if err != nil {
2222
return err
2323
}

cli/cmd/channel_releases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (r *runners) channelReleases(cmd *cobra.Command, args []string) error {
2626

2727
if r.appType == "platform" {
2828

29-
_, releases, err := r.api.GetChannel(r.appID, r.appType, chanID)
29+
_, releases, err := r.platformAPI.GetChannel(r.appID, chanID)
3030
if err != nil {
3131
return err
3232
}

cli/cmd/customer_create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (r *runners) createCustomer(_ *cobra.Command, _ []string) error {
3131
channel, err := r.api.GetOrCreateChannelByName(
3232
r.appID,
3333
r.appType,
34-
r.appSlug,
3534
r.args.customerCreateChannel,
3635
"",
3736
r.args.customerCreateEnsureChannel,

cli/cmd/release_create.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ func (r *runners) getOrCreateChannelForPromotion(channelName string, createIfAbs
320320
channel, err := r.api.GetOrCreateChannelByName(
321321
r.appID,
322322
r.appType,
323-
r.appSlug,
324323
channelName,
325324
description,
326325
createIfAbsent,

cli/cmd/release_promote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (r *runners) releasePromote(cmd *cobra.Command, args []string) error {
4141

4242
if r.appType != "ship" {
4343
// try to turn chanID into an actual id if it was a channel name
44-
channelID, err := r.api.GetOrCreateChannelByName(r.appID, r.appType, r.appSlug, channelName, "", false)
44+
channelID, err := r.api.GetOrCreateChannelByName(r.appID, r.appType, channelName, "", false)
4545
if err != nil {
4646
return errors.Wrapf(err, "unable to get channel ID from name")
4747
}

cli/print/channel_attributes.go

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,106 @@
11
package print
22

33
import (
4-
"github.com/replicatedhq/replicated/pkg/types"
4+
"fmt"
5+
"os"
56
"text/tabwriter"
67
"text/template"
8+
9+
"github.com/replicatedhq/replicated/pkg/types"
710
)
811

9-
var channelAttrsTmplSrc = `ID: {{ .ID }}
10-
NAME: {{ .Name }}
11-
DESCRIPTION: {{ .Description }}
12-
RELEASE: {{ if ge .ReleaseSequence 1 }}{{ .ReleaseSequence }}{{else}} {{end}}
13-
VERSION: {{ .ReleaseLabel }}{{ with .InstallCommands }}
12+
var channelAttrsTmplSrc = `ID: {{ .Chan.ID }}
13+
NAME: {{ .Chan.Name }}
14+
DESCRIPTION: {{ .Chan.Description }}
15+
RELEASE: {{ if ge .Chan.ReleaseSequence 1 }}{{ .Chan.ReleaseSequence }}{{else}} {{end}}
16+
VERSION: {{ .Chan.ReleaseLabel }}{{ with .Existing }}
1417
EXISTING:
1518
16-
{{ .Existing }}
17-
19+
{{ . }}
20+
{{end}}{{with .Embedded}}
1821
EMBEDDED:
1922
20-
{{ .Embedded }}
21-
23+
{{ . }}
24+
{{end}}{{with .Airgap}}
2225
AIRGAP:
2326
24-
{{ .Airgap }}
27+
{{ . }}
2528
{{end}}
2629
`
2730

2831
var channelAttrsTmpl = template.Must(template.New("ChannelAttributes").Parse(channelAttrsTmplSrc))
2932

30-
func ChannelAttrs(w *tabwriter.Writer, appChan *types.Channel) error {
31-
if err := channelAttrsTmpl.Execute(w, appChan); err != nil {
33+
func ChannelAttrs(
34+
w *tabwriter.Writer,
35+
appType string,
36+
appSlug string,
37+
appChan *types.Channel,
38+
) error {
39+
attrs := struct {
40+
Existing string
41+
Embedded string
42+
Airgap string
43+
Chan *types.Channel
44+
}{
45+
Chan: appChan,
46+
}
47+
if appType == "kots" {
48+
attrs.Existing = existingInstallCommand(appSlug, appChan.Slug)
49+
attrs.Embedded = embeddedInstallCommand(appSlug, appChan.Slug)
50+
attrs.Airgap = embeddedAirgapInstallCommand(appSlug, appChan.Slug)
51+
}
52+
if err := channelAttrsTmpl.Execute(w, attrs); err != nil {
3253
return err
3354
}
3455
return w.Flush()
3556
}
57+
58+
const embeddedInstallBaseURL = "https://k8s.kurl.sh"
59+
60+
var embeddedInstallOverrideURL = os.Getenv("EMBEDDED_INSTALL_BASE_URL")
61+
62+
func embeddedInstallCommand(appSlug, chanSlug string) string {
63+
64+
kurlBaseURL := embeddedInstallBaseURL
65+
if embeddedInstallOverrideURL != "" {
66+
kurlBaseURL = embeddedInstallOverrideURL
67+
}
68+
69+
kurlURL := fmt.Sprintf("%s/%s-%s", kurlBaseURL, appSlug, chanSlug)
70+
if chanSlug == "stable" {
71+
kurlURL = fmt.Sprintf("%s/%s", kurlBaseURL, appSlug)
72+
}
73+
return fmt.Sprintf(` curl -fsSL %s | sudo bash`, kurlURL)
74+
75+
}
76+
77+
func embeddedAirgapInstallCommand(appSlug, chanSlug string) string {
78+
79+
kurlBaseURL := embeddedInstallBaseURL
80+
if embeddedInstallOverrideURL != "" {
81+
kurlBaseURL = embeddedInstallOverrideURL
82+
}
83+
84+
slug := fmt.Sprintf("%s-%s", appSlug, chanSlug)
85+
if chanSlug == "stable" {
86+
slug = appSlug
87+
}
88+
kurlURL := fmt.Sprintf("%s/bundle/%s.tar.gz", kurlBaseURL, slug)
89+
90+
return fmt.Sprintf(` curl -fSL -o %s.tar.gz %s
91+
# ... scp or sneakernet %s.tar.gz to airgapped machine, then
92+
tar xvf %s.tar.gz
93+
sudo bash ./install.sh airgap`, slug, kurlURL, slug, slug)
94+
95+
}
96+
97+
func existingInstallCommand(appSlug, chanSlug string) string {
98+
99+
slug := appSlug
100+
if chanSlug != "stable" {
101+
slug = fmt.Sprintf("%s/%s", appSlug, chanSlug)
102+
}
103+
104+
return fmt.Sprintf(` curl -fsSL https://kots.io/install | bash
105+
kubectl kots install %s`, slug)
106+
}

client/channel.go

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import (
55
"strings"
66

77
"github.com/pkg/errors"
8-
channels "github.com/replicatedhq/replicated/gen/go/v1"
98
"github.com/replicatedhq/replicated/pkg/platformclient"
109
"github.com/replicatedhq/replicated/pkg/types"
1110
)
1211

13-
func (c *Client) ListChannels(appID string, appType string, appSlug string, channelName string) ([]types.Channel, error) {
12+
func (c *Client) ListChannels(appID string, appType string, channelName string) ([]types.Channel, error) {
1413

1514
if appType == "platform" {
1615
platformChannels, err := c.PlatformClient.ListChannels(appID)
@@ -35,22 +34,32 @@ func (c *Client) ListChannels(appID string, appType string, appSlug string, chan
3534
} else if appType == "ship" {
3635
return c.ShipClient.ListChannels(appID)
3736
} else if appType == "kots" {
38-
return c.KotsClient.ListChannels(appID, appSlug, channelName)
37+
return c.KotsClient.ListChannels(appID, channelName)
3938
}
4039

4140
return nil, errors.New("unknown app type")
4241
}
4342

44-
func (c *Client) GetChannel(appID string, appType string, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error) {
43+
func (c *Client) GetChannel(appID string, appType string, channelID string) (*types.Channel, error) {
4544
if appType == "platform" {
46-
return c.PlatformClient.GetChannel(appID, channelID)
45+
platformChannel, _, err := c.PlatformClient.GetChannel(appID, channelID)
46+
if err != nil {
47+
return nil, err
48+
}
49+
channel := types.Channel{
50+
ID: platformChannel.Id,
51+
Name: platformChannel.Name,
52+
Description: platformChannel.Description,
53+
ReleaseSequence: platformChannel.ReleaseSequence,
54+
ReleaseLabel: platformChannel.ReleaseLabel,
55+
}
56+
return &channel, nil
4757
} else if appType == "ship" {
4858
return c.ShipClient.GetChannel(appID, channelID)
4959
} else if appType == "kots" {
5060
return c.KotsClient.GetChannel(appID, channelID)
5161
}
52-
return nil, nil, errors.New("unknown app type")
53-
62+
return nil, errors.New("unknown app type")
5463
}
5564

5665
func (c *Client) ArchiveChannel(appID string, appType string, channelID string) error {
@@ -65,13 +74,13 @@ func (c *Client) ArchiveChannel(appID string, appType string, channelID string)
6574

6675
}
6776

68-
func (c *Client) CreateChannel(appID string, appType string, appSlug string, name string, description string) ([]types.Channel, error) {
77+
func (c *Client) CreateChannel(appID string, appType string, name string, description string) ([]types.Channel, error) {
6978

7079
if appType == "platform" {
7180
if err := c.PlatformClient.CreateChannel(appID, name, description); err != nil {
7281
return nil, err
7382
}
74-
return c.ListChannels(appID, appType, appSlug, name)
83+
return c.ListChannels(appID, appType, name)
7584
} else if appType == "ship" {
7685
if _, err := c.ShipClient.CreateChannel(appID, name, description); err != nil {
7786
return nil, err
@@ -81,36 +90,30 @@ func (c *Client) CreateChannel(appID string, appType string, appSlug string, nam
8190
if _, err := c.KotsClient.CreateChannel(appID, name, description); err != nil {
8291
return nil, err
8392
}
84-
return c.KotsClient.ListChannels(appID, appSlug, name)
93+
return c.KotsClient.ListChannels(appID, name)
8594
}
8695

8796
return nil, errors.New("unknown app type")
8897
}
8998

90-
func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug string, nameOrID string, description string, createIfAbsent bool) (*types.Channel, error) {
99+
func (c *Client) GetOrCreateChannelByName(appID string, appType string, nameOrID string, description string, createIfAbsent bool) (*types.Channel, error) {
91100
gqlNotFoundErr := fmt.Sprintf("channel %s not found", nameOrID)
92-
channel, _, err := c.GetChannel(appID, appType, nameOrID)
101+
channel, err := c.GetChannel(appID, appType, nameOrID)
93102
if err == nil {
94-
return &types.Channel{
95-
ID: channel.Id,
96-
Name: channel.Name,
97-
Description: channel.Description,
98-
ReleaseSequence: channel.ReleaseSequence,
99-
ReleaseLabel: channel.ReleaseLabel,
100-
}, nil
103+
return channel, nil
101104
} else if !strings.Contains(err.Error(), gqlNotFoundErr) && !errors.Is(err, platformclient.ErrNotFound) {
102105
return nil, errors.Wrap(err, "get channel")
103106
}
104107

105-
allChannels, err := c.ListChannels(appID, appType, appSlug, nameOrID)
108+
allChannels, err := c.ListChannels(appID, appType, nameOrID)
106109
if err != nil {
107110
return nil, err
108111
}
109112

110113
foundChannel, numMatching, err := c.findChannel(allChannels, nameOrID)
111114

112115
if numMatching == 0 && createIfAbsent {
113-
updatedListOfChannels, err := c.CreateChannel(appID, appType, appSlug, nameOrID, description)
116+
updatedListOfChannels, err := c.CreateChannel(appID, appType, nameOrID, description)
114117
if err != nil {
115118
return nil, errors.Wrapf(err, "create channel %q ", nameOrID)
116119
}
@@ -123,8 +126,8 @@ func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug
123126
return foundChannel, errors.Wrapf(err, "find channel %q", nameOrID)
124127
}
125128

126-
func (c *Client) GetChannelByName(appID string, appType string, appSlug string, name string) (*types.Channel, error) {
127-
return c.GetOrCreateChannelByName(appID, appType, appSlug, name, "", false)
129+
func (c *Client) GetChannelByName(appID string, appType string, name string) (*types.Channel, error) {
130+
return c.GetOrCreateChannelByName(appID, appType, name, "", false)
128131
}
129132

130133
func (c *Client) findChannel(channels []types.Channel, name string) (*types.Channel, int, error) {
@@ -150,7 +153,7 @@ func (c *Client) UpdateSemanticVersioningForChannel(appType string, appID string
150153
} else if appType == "ship" {
151154
return errors.New("This feature is not currently supported for Ship applications.")
152155
} else if appType == "kots" {
153-
channel, _, err := c.KotsClient.GetChannel(appID, chanID)
156+
channel, err := c.KotsClient.GetChannel(appID, chanID)
154157
if err != nil {
155158
return err
156159
}

0 commit comments

Comments
 (0)