-
Notifications
You must be signed in to change notification settings - Fork 23
/
channel_attributes.go
114 lines (92 loc) · 2.7 KB
/
channel_attributes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package print
import (
"encoding/json"
"fmt"
"os"
"text/tabwriter"
"text/template"
"github.com/replicatedhq/replicated/pkg/types"
)
var channelAttrsTmplSrc = `ID: {{ .Chan.ID }}
NAME: {{ .Chan.Name }}
DESCRIPTION: {{ .Chan.Description }}
RELEASE: {{ if ge .Chan.ReleaseSequence 1 }}{{ .Chan.ReleaseSequence }}{{else}} {{end}}
VERSION: {{ .Chan.ReleaseLabel }}{{ with .Existing }}
EXISTING:
{{ . }}
{{end}}{{with .Embedded}}
EMBEDDED:
{{ . }}
{{end}}{{with .Airgap}}
AIRGAP:
{{ . }}
{{end}}
`
var channelAttrsTmpl = template.Must(template.New("ChannelAttributes").Parse(channelAttrsTmplSrc))
func ChannelAttrs(outputFormat string,
w *tabwriter.Writer,
appType string,
appSlug string,
appChan *types.Channel,
) error {
if outputFormat == "text" {
attrs := struct {
Existing string
Embedded string
Airgap string
Chan *types.Channel
}{
Chan: appChan,
}
if appType == "kots" {
attrs.Existing = existingInstallCommand(appSlug, appChan.Slug)
attrs.Embedded = embeddedInstallCommand(appSlug, appChan.Slug)
attrs.Airgap = embeddedAirgapInstallCommand(appSlug, appChan.Slug)
}
if err := channelAttrsTmpl.Execute(w, attrs); err != nil {
return err
}
} else if outputFormat == "json" {
cAsByte, _ := json.MarshalIndent(appChan, "", " ")
if _, err := fmt.Fprintln(w, string(cAsByte)); err != nil {
return err
}
}
return w.Flush()
}
const embeddedInstallBaseURL = "https://k8s.kurl.sh"
var embeddedInstallOverrideURL = os.Getenv("EMBEDDED_INSTALL_BASE_URL")
func embeddedInstallCommand(appSlug, chanSlug string) string {
kurlBaseURL := embeddedInstallBaseURL
if embeddedInstallOverrideURL != "" {
kurlBaseURL = embeddedInstallOverrideURL
}
kurlURL := fmt.Sprintf("%s/%s-%s", kurlBaseURL, appSlug, chanSlug)
if chanSlug == "stable" {
kurlURL = fmt.Sprintf("%s/%s", kurlBaseURL, appSlug)
}
return fmt.Sprintf(` curl -fsSL %s | sudo bash`, kurlURL)
}
func embeddedAirgapInstallCommand(appSlug, chanSlug string) string {
kurlBaseURL := embeddedInstallBaseURL
if embeddedInstallOverrideURL != "" {
kurlBaseURL = embeddedInstallOverrideURL
}
slug := fmt.Sprintf("%s-%s", appSlug, chanSlug)
if chanSlug == "stable" {
slug = appSlug
}
kurlURL := fmt.Sprintf("%s/bundle/%s.tar.gz", kurlBaseURL, slug)
return fmt.Sprintf(` curl -fSL -o %s.tar.gz %s
# ... scp or sneakernet %s.tar.gz to airgapped machine, then
tar xvf %s.tar.gz
sudo bash ./install.sh airgap`, slug, kurlURL, slug, slug)
}
func existingInstallCommand(appSlug, chanSlug string) string {
slug := appSlug
if chanSlug != "stable" {
slug = fmt.Sprintf("%s/%s", appSlug, chanSlug)
}
return fmt.Sprintf(` curl -fsSL https://kots.io/install | bash
kubectl kots install %s`, slug)
}