WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 594b782

Browse files
committed
Publish userdata code for use in inlets-operator
Updated to take a version for inlets OSS / PRO Tested e2e with DigitalOcean with PRO + OSS, unit tests updated Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 3e9ed9c commit 594b782

File tree

4 files changed

+129
-99
lines changed

4 files changed

+129
-99
lines changed

cmd/create.go

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
const inletsControlPort = 8080
23+
const inletsOSSVersion = "2.7.4"
24+
const inletsPROVersion = "0.7.0"
25+
26+
const inletsOSSControlPort = 8080
2427
const inletsProControlPort = 8123
2528

2629
func init() {
@@ -185,27 +188,26 @@ func runCreate(cmd *cobra.Command, _ []string) error {
185188
if err != nil {
186189
return err
187190
}
188-
189-
remoteTCP, _ := cmd.Flags().GetString("remote-tcp")
190191
var pro bool
191-
if len(remoteTCP) > 0 {
192-
pro = true
193-
}
194192

195193
if v, _ := cmd.Flags().GetBool("pro"); v {
196194
pro = true
197195
}
198196

199197
name := strings.Replace(names.GetRandomName(10), "_", "-", -1)
200-
userData := makeUserdata(inletsToken, inletsControlPort, pro)
198+
userData := provision.MakeExitServerUserdata(inletsOSSControlPort,
199+
inletsToken,
200+
inletsOSSVersion,
201+
inletsPROVersion,
202+
pro)
201203

202204
hostReq, err := createHost(provider,
203205
name,
204206
region,
205207
zone,
206208
projectID,
207209
userData,
208-
strconv.Itoa(inletsControlPort),
210+
strconv.Itoa(inletsOSSControlPort),
209211
vpcID,
210212
subnetID,
211213
pro)
@@ -241,7 +243,7 @@ func runCreate(cmd *cobra.Command, _ []string) error {
241243

242244
if hostStatus.Status == "active" {
243245
if !pro {
244-
fmt.Printf(`inlets OSS exit-server summary:
246+
fmt.Printf(`inlets OSS (`+inletsOSSVersion+`) exit-server summary:
245247
IP: %s
246248
Auth-token: %s
247249
@@ -254,11 +256,17 @@ Command:
254256
To Delete:
255257
inletsctl delete --provider %s --id "%s"
256258
`,
257-
hostStatus.IP, inletsToken, hostStatus.IP, inletsControlPort, inletsToken, provider, hostStatus.ID)
259+
hostStatus.IP,
260+
inletsToken,
261+
hostStatus.IP,
262+
inletsOSSControlPort,
263+
inletsToken,
264+
provider,
265+
hostStatus.ID)
258266
return nil
259267
}
260268

261-
fmt.Printf(`inlets PRO (0.7.0) exit-server summary:
269+
fmt.Printf(`inlets PRO (`+inletsPROVersion+`) exit-server summary:
262270
IP: %s
263271
Auth-token: %s
264272
@@ -276,7 +284,13 @@ Command:
276284
To Delete:
277285
inletsctl delete --provider %s --id "%s"
278286
`,
279-
hostStatus.IP, inletsToken, hostStatus.IP, inletsProControlPort, inletsToken, provider, hostStatus.ID)
287+
hostStatus.IP,
288+
inletsToken,
289+
hostStatus.IP,
290+
inletsProControlPort,
291+
inletsToken,
292+
provider,
293+
hostStatus.ID)
280294

281295
return nil
282296
}
@@ -446,37 +460,3 @@ func createHost(provider, name, region, zone, projectID, userData, inletsPort st
446460

447461
return nil, fmt.Errorf("no provisioner for provider: %q", provider)
448462
}
449-
450-
func makeUserdata(authToken string, inletsControlPort int, pro bool) string {
451-
452-
controlPort := fmt.Sprintf("%d", inletsControlPort)
453-
454-
if !pro {
455-
return `#!/bin/bash
456-
export AUTHTOKEN="` + authToken + `"
457-
export CONTROLPORT="` + controlPort + `"
458-
curl -sLS https://get.inlets.dev | sh
459-
460-
curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets-operator.service && \
461-
mv inlets-operator.service /etc/systemd/system/inlets.service && \
462-
echo "AUTHTOKEN=$AUTHTOKEN" > /etc/default/inlets && \
463-
echo "CONTROLPORT=$CONTROLPORT" >> /etc/default/inlets && \
464-
systemctl start inlets && \
465-
systemctl enable inlets`
466-
}
467-
468-
return `#!/bin/bash
469-
export AUTHTOKEN="` + authToken + `"
470-
export IP=$(curl -sfSL https://checkip.amazonaws.com)
471-
472-
curl -SLsf https://github.com/inlets/inlets-pro/releases/download/0.7.0/inlets-pro > /tmp/inlets-pro && \
473-
chmod +x /tmp/inlets-pro && \
474-
mv /tmp/inlets-pro /usr/local/bin/inlets-pro
475-
476-
curl -sLO https://raw.githubusercontent.com/inlets/inlets-pro/master/artifacts/inlets-pro.service && \
477-
mv inlets-pro.service /etc/systemd/system/inlets-pro.service && \
478-
echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \
479-
echo "IP=$IP" >> /etc/default/inlets-pro && \
480-
systemctl start inlets-pro && \
481-
systemctl enable inlets-pro`
482-
}

cmd/create_test.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

pkg/provision/userdata.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package provision
2+
3+
import "fmt"
4+
5+
// MakeExitServerUserdata makes a user-data script in bash to setup inlets
6+
// using the OSS or PRO version with a systemd service
7+
func MakeExitServerUserdata(ossControlPort int, authToken, ossVersion, proVersion string, pro bool) string {
8+
if pro {
9+
return `#!/bin/bash
10+
export AUTHTOKEN="` + authToken + `"
11+
export IP=$(curl -sfSL https://checkip.amazonaws.com)
12+
13+
curl -SLsf https://github.com/inlets/inlets-pro/releases/download/` + proVersion + `/inlets-pro > /tmp/inlets-pro && \
14+
chmod +x /tmp/inlets-pro && \
15+
mv /tmp/inlets-pro /usr/local/bin/inlets-pro
16+
17+
curl -sLO https://raw.githubusercontent.com/inlets/inlets-pro/master/artifacts/inlets-pro.service && \
18+
mv inlets-pro.service /etc/systemd/system/inlets-pro.service && \
19+
echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \
20+
echo "IP=$IP" >> /etc/default/inlets-pro && \
21+
systemctl start inlets-pro && \
22+
systemctl enable inlets-pro
23+
`
24+
}
25+
26+
controlPort := fmt.Sprintf("%d", ossControlPort)
27+
28+
return `#!/bin/bash
29+
export AUTHTOKEN="` + authToken + `"
30+
export CONTROLPORT="` + controlPort + `"
31+
32+
curl -SLsf https://github.com/inlets/inlets/releases/download/` + ossVersion + `/inlets > /tmp/inlets && \
33+
chmod +x /tmp/inlets && \
34+
mv /tmp/inlets /usr/local/bin/inlets
35+
36+
curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets.service && \
37+
mv inlets-operator.service /etc/systemd/system/inlets.service && \
38+
echo "AUTHTOKEN=$AUTHTOKEN" > /etc/default/inlets && \
39+
echo "CONTROLPORT=$CONTROLPORT" >> /etc/default/inlets && \
40+
systemctl start inlets && \
41+
systemctl enable inlets
42+
`
43+
}

pkg/provision/userdata_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Inlets Author(s) 2020. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package provision
5+
6+
import (
7+
"io/ioutil"
8+
"testing"
9+
)
10+
11+
func Test_makeUserdata_InletsOSS(t *testing.T) {
12+
userData := MakeExitServerUserdata(8080, "auth", "2.7.4", "0.7.0", false)
13+
14+
wantUserdata := `#!/bin/bash
15+
export AUTHTOKEN="auth"
16+
export CONTROLPORT="8080"
17+
18+
curl -SLsf https://github.com/inlets/inlets/releases/download/2.7.4/inlets > /tmp/inlets && \
19+
chmod +x /tmp/inlets && \
20+
mv /tmp/inlets /usr/local/bin/inlets
21+
22+
curl -sLO https://raw.githubusercontent.com/inlets/inlets/master/hack/inlets.service && \
23+
mv inlets-operator.service /etc/systemd/system/inlets.service && \
24+
echo "AUTHTOKEN=$AUTHTOKEN" > /etc/default/inlets && \
25+
echo "CONTROLPORT=$CONTROLPORT" >> /etc/default/inlets && \
26+
systemctl start inlets && \
27+
systemctl enable inlets
28+
`
29+
30+
ioutil.WriteFile("/tmp/oss", []byte(userData), 0600)
31+
32+
if userData != wantUserdata {
33+
t.Errorf("want:\n%s\nbut got:\n%s", wantUserdata, userData)
34+
}
35+
}
36+
37+
func Test_makeUserdata_InletsPro(t *testing.T) {
38+
userData := MakeExitServerUserdata(8080, "auth", "2.7.4", "0.7.0", true)
39+
40+
wantUserdata := `#!/bin/bash
41+
export AUTHTOKEN="auth"
42+
export IP=$(curl -sfSL https://checkip.amazonaws.com)
43+
44+
curl -SLsf https://github.com/inlets/inlets-pro/releases/download/0.7.0/inlets-pro > /tmp/inlets-pro && \
45+
chmod +x /tmp/inlets-pro && \
46+
mv /tmp/inlets-pro /usr/local/bin/inlets-pro
47+
48+
curl -sLO https://raw.githubusercontent.com/inlets/inlets-pro/master/artifacts/inlets-pro.service && \
49+
mv inlets-pro.service /etc/systemd/system/inlets-pro.service && \
50+
echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \
51+
echo "IP=$IP" >> /etc/default/inlets-pro && \
52+
systemctl start inlets-pro && \
53+
systemctl enable inlets-pro
54+
`
55+
56+
// ioutil.WriteFile("/tmp/pro", []byte(userData), 0600)
57+
if userData != wantUserdata {
58+
t.Errorf("want: %s, but got: %s", wantUserdata, userData)
59+
}
60+
}

0 commit comments

Comments
 (0)