Skip to content

Commit a2463e1

Browse files
feat: preflight support for custom lam and kots ports (#1224)
* feat: implement preflight support for custom kots and lam ports kots and lam ports may be customized through command line flags so we need to make preflights to reflect these customizations. * chore: rephrase preflight messages during one of the last rebases i have done i ended up overwriting the changes to the phrasing here, this commit restores it. * feat: make preflight result a list instead of a table make the result of preflight execution a list instead of a table.
1 parent 8081023 commit a2463e1

File tree

10 files changed

+239
-130
lines changed

10 files changed

+239
-130
lines changed

cmd/embedded-cluster/install.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ import (
3434
// necessary data to the screen).
3535
var ErrNothingElseToAdd = fmt.Errorf("")
3636

37+
// ErrPreflightsHaveFail is an error returned when we managed to execute the
38+
// host preflights but they contain failures. We use this to differentiate the
39+
// way we provide user feedback.
40+
var ErrPreflightsHaveFail = fmt.Errorf("host preflight failures detected")
41+
3742
// installAndEnableLocalArtifactMirror installs and enables the local artifact mirror. This
3843
// service is responsible for serving on localhost, through http, all files that are used
3944
// during a cluster upgrade.
@@ -122,16 +127,18 @@ func configureNetworkManager(c *cli.Context) error {
122127
// RunHostPreflights runs the host preflights we found embedded in the binary
123128
// on all configured hosts. We attempt to read HostPreflights from all the
124129
// embedded Helm Charts and from the Kots Application Release files.
125-
func RunHostPreflights(c *cli.Context, applier *addons.Applier, replicatedAPIURL, proxyRegistryURL string, isAirgap bool, proxy *ecv1beta1.ProxySpec) error {
130+
func RunHostPreflights(c *cli.Context, applier *addons.Applier, replicatedAPIURL, proxyRegistryURL string, isAirgap bool, proxy *ecv1beta1.ProxySpec, adminConsolePort int, localArtifactMirrorPort int) error {
126131
hpf, err := applier.HostPreflights()
127132
if err != nil {
128133
return fmt.Errorf("unable to read host preflights: %w", err)
129134
}
130135

131136
data := preflights.TemplateData{
132-
ReplicatedAPIURL: replicatedAPIURL,
133-
ProxyRegistryURL: proxyRegistryURL,
134-
IsAirgap: isAirgap,
137+
ReplicatedAPIURL: replicatedAPIURL,
138+
ProxyRegistryURL: proxyRegistryURL,
139+
IsAirgap: isAirgap,
140+
AdminConsolePort: adminConsolePort,
141+
LocalArtifactMirrorPort: localArtifactMirrorPort,
135142
}
136143
chpfs, err := preflights.GetClusterHostPreflights(c.Context, data)
137144
if err != nil {
@@ -190,7 +197,7 @@ func runHostPreflights(c *cli.Context, hpf *v1beta2.HostPreflightSpec, proxy *ec
190197

191198
pb.CloseWithError()
192199
output.PrintTableWithoutInfo()
193-
return fmt.Errorf("host preflight failures detected")
200+
return ErrPreflightsHaveFail
194201
}
195202

196203
// Warnings found
@@ -697,10 +704,25 @@ var installCommand = &cli.Command{
697704
replicatedAPIURL = license.Spec.Endpoint
698705
proxyRegistryURL = fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
699706
}
700-
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy); err != nil {
707+
708+
adminConsolePort, err := getAdminConsolePortFromFlag(c)
709+
if err != nil {
710+
return fmt.Errorf("unable to parse admin console port: %w", err)
711+
}
712+
713+
localArtifactMirrorPort, err := getLocalArtifactMirrorPortFromFlag(c)
714+
if err != nil {
715+
return fmt.Errorf("unable to parse local artifact mirror port: %w", err)
716+
}
717+
718+
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
701719
metrics.ReportApplyFinished(c, err)
720+
if err == ErrPreflightsHaveFail {
721+
return ErrNothingElseToAdd
722+
}
702723
return err
703724
}
725+
704726
cfg, err := installAndWaitForK0s(c, applier, proxy)
705727
if err != nil {
706728
return err

cmd/embedded-cluster/join.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"os"
10+
"strconv"
1011
"strings"
1112
"time"
1213

@@ -231,9 +232,26 @@ var joinCommand = &cli.Command{
231232
// jcmd.InstallationSpec.MetricsBaseURL is the replicated.app endpoint url
232233
replicatedAPIURL := jcmd.InstallationSpec.MetricsBaseURL
233234
proxyRegistryURL := fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
234-
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy); err != nil {
235-
err := fmt.Errorf("unable to run host preflights locally: %w", err)
235+
236+
urlSlices := strings.Split(c.Args().Get(0), ":")
237+
if len(urlSlices) != 2 {
238+
return fmt.Errorf("unable to get port from url %s", c.Args().Get(0))
239+
}
240+
adminConsolePort, err := strconv.Atoi(urlSlices[1])
241+
if err != nil {
242+
return fmt.Errorf("unable to convert port to int: %w", err)
243+
}
244+
245+
localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
246+
if jcmd.InstallationSpec.LocalArtifactMirror != nil {
247+
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
248+
}
249+
250+
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
236251
metrics.ReportJoinFailed(c.Context, jcmd.InstallationSpec.MetricsBaseURL, jcmd.ClusterID, err)
252+
if err == ErrPreflightsHaveFail {
253+
return ErrNothingElseToAdd
254+
}
237255
return err
238256
}
239257

@@ -265,10 +283,7 @@ var joinCommand = &cli.Command{
265283
}
266284

267285
logrus.Debugf("creating systemd unit files")
268-
localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
269-
if jcmd.InstallationSpec.LocalArtifactMirror != nil && jcmd.InstallationSpec.LocalArtifactMirror.Port > 0 {
270-
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
271-
}
286+
272287
// both controller and worker nodes will have 'worker' in the join command
273288
if err := createSystemdUnitFiles(!strings.Contains(jcmd.K0sJoinCommand, "controller"), jcmd.InstallationSpec.Proxy, localArtifactMirrorPort); err != nil {
274289
err := fmt.Errorf("unable to create systemd unit files: %w", err)

cmd/embedded-cluster/preflights.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"strconv"
7+
"strings"
68

79
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
810
"github.com/replicatedhq/embedded-cluster/pkg/versions"
@@ -33,6 +35,8 @@ var installRunPreflightsCommand = &cli.Command{
3335
Usage: "Disable interactive prompts.",
3436
Value: false,
3537
},
38+
getAdminColsolePortFlag(),
39+
getLocalArtifactMirrorPortFlag(),
3640
},
3741
)),
3842
Before: func(c *cli.Context) error {
@@ -73,7 +77,21 @@ var installRunPreflightsCommand = &cli.Command{
7377
replicatedAPIURL = license.Spec.Endpoint
7478
proxyRegistryURL = fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
7579
}
76-
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy); err != nil {
80+
81+
adminConsolePort, err := getAdminConsolePortFromFlag(c)
82+
if err != nil {
83+
return fmt.Errorf("unable to parse admin console port: %w", err)
84+
}
85+
86+
localArtifactMirrorPort, err := getLocalArtifactMirrorPortFromFlag(c)
87+
if err != nil {
88+
return fmt.Errorf("unable to parse local artifact mirror port: %w", err)
89+
}
90+
91+
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
92+
if err == ErrPreflightsHaveFail {
93+
return ErrNothingElseToAdd
94+
}
7795
return err
7896
}
7997

@@ -152,8 +170,25 @@ var joinRunPreflightsCommand = &cli.Command{
152170
logrus.Debugf("running host preflights")
153171
replicatedAPIURL := jcmd.InstallationSpec.MetricsBaseURL
154172
proxyRegistryURL := fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
155-
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy); err != nil {
156-
err := fmt.Errorf("unable to run host preflights locally: %w", err)
173+
174+
urlSlices := strings.Split(c.Args().Get(0), ":")
175+
if len(urlSlices) != 2 {
176+
return fmt.Errorf("unable to get port from url %s", c.Args().Get(0))
177+
}
178+
adminConsolePort, err := strconv.Atoi(urlSlices[1])
179+
if err != nil {
180+
return fmt.Errorf("unable to convert port to int: %w", err)
181+
}
182+
183+
localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
184+
if jcmd.InstallationSpec.LocalArtifactMirror != nil {
185+
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
186+
}
187+
188+
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
189+
if err == ErrPreflightsHaveFail {
190+
return ErrNothingElseToAdd
191+
}
157192
return err
158193
}
159194

cmd/embedded-cluster/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sort"
77
"strings"
88

9-
"github.com/jedib0t/go-pretty/table"
9+
"github.com/jedib0t/go-pretty/v6/table"
1010
"github.com/urfave/cli/v2"
1111

1212
"github.com/replicatedhq/embedded-cluster/pkg/addons"

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/google/go-github/v62 v62.0.0
2222
github.com/google/uuid v1.6.0
2323
github.com/gosimple/slug v1.14.0
24-
github.com/jedib0t/go-pretty v4.3.0+incompatible
24+
github.com/jedib0t/go-pretty/v6 v6.5.9
2525
github.com/k0sproject/dig v0.2.0
2626
github.com/k0sproject/k0s v1.29.9-0.20240821114611-d76eb6bb05a7
2727
github.com/k0sproject/version v0.6.0
@@ -208,10 +208,8 @@ require (
208208
github.com/go-logr/zapr v1.3.0 // indirect
209209
github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1 // indirect
210210
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
211-
github.com/go-openapi/errors v0.22.0 // indirect
212211
github.com/go-openapi/jsonpointer v0.21.0 // indirect
213212
github.com/go-openapi/jsonreference v0.21.0 // indirect
214-
github.com/go-openapi/strfmt v0.23.0 // indirect
215213
github.com/go-openapi/swag v0.23.0 // indirect
216214
github.com/gogo/protobuf v1.3.2 // indirect
217215
github.com/golang/protobuf v1.5.4 // indirect
@@ -241,7 +239,6 @@ require (
241239
github.com/modern-go/reflect2 v1.0.2 // indirect
242240
github.com/muhlemmer/gu v0.3.1 // indirect
243241
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
244-
github.com/oklog/ulid v1.3.1 // indirect
245242
github.com/pborman/uuid v1.2.1 // indirect
246243
github.com/pkg/errors v0.9.1
247244
github.com/pkg/sftp v1.13.6 // indirect
@@ -254,7 +251,6 @@ require (
254251
github.com/spf13/pflag v1.0.5 // indirect
255252
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
256253
github.com/zitadel/oidc/v2 v2.7.0 // indirect
257-
go.mongodb.org/mongo-driver v1.14.0 // indirect
258254
go.uber.org/zap v1.27.0 // indirect
259255
golang.org/x/net v0.29.0 // indirect
260256
golang.org/x/oauth2 v0.22.0 // indirect

go.sum

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,10 @@ github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1 h1:uvQJoKTHrFFu8zxoaopNK
203203
github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1/go.mod h1:H59IYeChwvD1po3dhGUPvq5na+4NVD7SJlbhGKvslr0=
204204
github.com/go-macaroon-bakery/macaroonpb v1.0.0 h1:It9exBaRMZ9iix1iJ6gwzfwsDE6ExNuwtAJ9e09v6XE=
205205
github.com/go-macaroon-bakery/macaroonpb v1.0.0/go.mod h1:UzrGOcbiwTXISFP2XDLDPjfhMINZa+fX/7A2lMd31zc=
206-
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
207-
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
208206
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
209207
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
210208
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
211209
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
212-
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
213-
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
214210
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
215211
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
216212
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
@@ -315,8 +311,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
315311
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
316312
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
317313
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
318-
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
319-
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
314+
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
315+
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
320316
github.com/jeremija/gosubmit v0.2.7 h1:At0OhGCFGPXyjPYAsCchoBUhE099pcBXmsb4iZqROIc=
321317
github.com/jeremija/gosubmit v0.2.7/go.mod h1:Ui+HS073lCFREXBbdfrJzMB57OI/bdxTiLtrDHHhFPI=
322318
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -431,8 +427,6 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
431427
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
432428
github.com/ohler55/ojg v1.24.1 h1:PaVLelrNgT5/0ppPaUtey54tOVp245z33fkhL2jljjY=
433429
github.com/ohler55/ojg v1.24.1/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
434-
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
435-
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
436430
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
437431
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
438432
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
@@ -582,8 +576,6 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5
582576
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
583577
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
584578
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
585-
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
586-
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
587579
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
588580
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
589581
go.opentelemetry.io/contrib/bridges/prometheus v0.52.0 h1:NNkEjNcUXeNcxDTNLyyAmFHefByhj8YU1AojgcPqbfs=

0 commit comments

Comments
 (0)