/
inletstcpclient_app.go
180 lines (141 loc) · 6.19 KB
/
inletstcpclient_app.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright (c) arkade author(s) 2022. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package apps
import (
"fmt"
"strconv"
"strings"
"github.com/alexellis/arkade/pkg/apps"
"github.com/alexellis/arkade/pkg/config"
"github.com/alexellis/arkade/pkg/k8s"
"github.com/alexellis/arkade/pkg/types"
"github.com/alexellis/arkade/pkg"
"github.com/spf13/cobra"
)
func MakeInstallInletsTcpClient() *cobra.Command {
var inletsProClient = &cobra.Command{
Use: "inlets-tcp-client",
Short: "Install inlets PRO TCP client",
Long: `Install an inlets PRO TCP client to any Kubernetes cluster`,
Example: ` arkade install inlets-tcp-client`,
SilenceUsage: true,
}
inletsProClient.Flags().StringP("namespace", "n", "default", "The namespace used for installation")
inletsProClient.Flags().Bool("update-repo", true, "Update the helm repo")
inletsProClient.Flags().String("url", "", "URL for remote server's control-plane, i.e. wss://127.0.0.1:8123")
inletsProClient.Flags().Bool("auto-tls", true, "Toggle use of automated TLS, fetching CA from the server on start-up. Disable when providing your own TLS termination on the server")
inletsProClient.Flags().String("upstream", "localhost", "Forward traffic from the server here, give a hostname or IP address")
inletsProClient.Flags().IntSlice("ports", []int{}, "Publish a TCP port on the server")
inletsProClient.Flags().String("license", "", "License JWT or Gumroad token")
inletsProClient.Flags().String("license-file", "", "Path to license JWT file or Gumroad token")
inletsProClient.Flags().String("token", "", "Authentication token")
inletsProClient.Flags().String("token-file", "", "Read the authentication token from a file")
inletsProClient.Flags().StringArray("set", []string{}, "Use custom flags or override existing flags \n(example --set image=org/repo:tag)")
inletsProClient.PreRunE = func(command *cobra.Command, args []string) error {
tokenFile, err := command.Flags().GetString("token-file")
if err != nil {
return fmt.Errorf("error with --token-file usage: %s", err)
}
tokenString, err := command.Flags().GetString("token")
if err != nil {
return fmt.Errorf("error with --token usage: %s", err)
}
if tokenString == "" && tokenFile == "" {
return fmt.Errorf("either --token or --token-file is required")
}
licenseFile, err := command.Flags().GetString("license-file")
if err != nil {
return fmt.Errorf("error with --license-file usage: %s", err)
}
licenseString, err := command.Flags().GetString("license")
if err != nil {
return fmt.Errorf("error with --license usage: %s", err)
}
if licenseString == "" && licenseFile == "" {
return fmt.Errorf("either --license or --license-file is required")
}
ports, err := command.Flags().GetIntSlice("ports")
if err != nil {
return fmt.Errorf("error with --ports usage: %s", err)
}
if len(ports) == 0 {
return fmt.Errorf("you must specify at least one remote TCP port with --ports")
}
return nil
}
inletsProClient.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath, _ := command.Flags().GetString("kubeconfig")
if err := config.SetKubeconfig(kubeConfigPath); err != nil {
return err
}
arch := k8s.GetNodeArchitecture()
fmt.Printf("Node architecture: %q\n", arch)
appOpts := types.DefaultInstallOptions()
updateRepo, _ := inletsProClient.Flags().GetBool("update-repo")
namespace, _ := inletsProClient.Flags().GetString("namespace")
overrides := map[string]string{}
url, _ := command.Flags().GetString("url")
autoTLS, _ := command.Flags().GetBool("auto-tls")
upstream, _ := command.Flags().GetString("upstream")
ports, _ := command.Flags().GetIntSlice("ports")
overrides["url"] = url
overrides["autoTLS"] = strings.ToLower(strconv.FormatBool(autoTLS))
overrides["upstream"] = upstream
overrides["ports"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(ports)), ","), "[]")
overrides["tokenSecretName"] = "inlets-pro-token"
tokenFile, _ := command.Flags().GetString("token-file")
tokenString, _ := command.Flags().GetString("token")
if len(tokenFile) > 0 {
secretData := []types.SecretsData{
{Type: types.FromFileSecret, Key: "token", Value: tokenFile},
}
tokenSecret := types.NewGenericSecret("inlets-pro-token", namespace, secretData)
appOpts.WithSecret(tokenSecret)
} else {
secretData := []types.SecretsData{
{Type: types.StringLiteralSecret, Key: "token", Value: tokenString},
}
tokenSecret := types.NewGenericSecret("inlets-pro-token", namespace, secretData)
appOpts.WithSecret(tokenSecret)
}
licenseFile, _ := command.Flags().GetString("license-file")
licenseString, _ := command.Flags().GetString("license")
if len(licenseFile) > 0 {
secretData := []types.SecretsData{
{Type: types.FromFileSecret, Key: "license", Value: licenseFile},
}
licenseSecret := types.NewGenericSecret("inlets-license", namespace, secretData)
appOpts.WithSecret(licenseSecret)
} else {
secretData := []types.SecretsData{
{Type: types.StringLiteralSecret, Key: "license", Value: licenseString},
}
licenseSecret := types.NewGenericSecret("inlets-license", namespace, secretData)
appOpts.WithSecret(licenseSecret)
}
customFlags, _ := command.Flags().GetStringArray("set")
if err := config.MergeFlags(overrides, customFlags); err != nil {
return err
}
options := appOpts.
WithNamespace(namespace).
WithHelmRepo("inlets-pro/inlets-pro-client").
WithHelmURL("https://inlets.github.io/inlets-pro/charts").
WithOverrides(overrides).
WithHelmUpdateRepo(updateRepo).
WithKubeconfigPath(kubeConfigPath)
_, err := apps.MakeInstallChart(options)
if err != nil {
return err
}
fmt.Println(inletsTcpClientInstallMsg)
return nil
}
return inletsProClient
}
const InletsTcpClientInfoMsg = `# Find out more at:
# https://inlets.dev`
const inletsTcpClientInstallMsg = `=======================================================================
= inlets PRO TCP client has been installed. =
=======================================================================` +
"\n\n" + InletsTcpClientInfoMsg + "\n\n" + pkg.SupportMessageShort