Skip to content

Commit

Permalink
feat: preflight support for custom lam and kots ports (#1224)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ricardomaraschini authored Sep 26, 2024
1 parent 8081023 commit a2463e1
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 130 deletions.
34 changes: 28 additions & 6 deletions cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import (
// necessary data to the screen).
var ErrNothingElseToAdd = fmt.Errorf("")

// ErrPreflightsHaveFail is an error returned when we managed to execute the
// host preflights but they contain failures. We use this to differentiate the
// way we provide user feedback.
var ErrPreflightsHaveFail = fmt.Errorf("host preflight failures detected")

// installAndEnableLocalArtifactMirror installs and enables the local artifact mirror. This
// service is responsible for serving on localhost, through http, all files that are used
// during a cluster upgrade.
Expand Down Expand Up @@ -122,16 +127,18 @@ func configureNetworkManager(c *cli.Context) error {
// RunHostPreflights runs the host preflights we found embedded in the binary
// on all configured hosts. We attempt to read HostPreflights from all the
// embedded Helm Charts and from the Kots Application Release files.
func RunHostPreflights(c *cli.Context, applier *addons.Applier, replicatedAPIURL, proxyRegistryURL string, isAirgap bool, proxy *ecv1beta1.ProxySpec) error {
func RunHostPreflights(c *cli.Context, applier *addons.Applier, replicatedAPIURL, proxyRegistryURL string, isAirgap bool, proxy *ecv1beta1.ProxySpec, adminConsolePort int, localArtifactMirrorPort int) error {
hpf, err := applier.HostPreflights()
if err != nil {
return fmt.Errorf("unable to read host preflights: %w", err)
}

data := preflights.TemplateData{
ReplicatedAPIURL: replicatedAPIURL,
ProxyRegistryURL: proxyRegistryURL,
IsAirgap: isAirgap,
ReplicatedAPIURL: replicatedAPIURL,
ProxyRegistryURL: proxyRegistryURL,
IsAirgap: isAirgap,
AdminConsolePort: adminConsolePort,
LocalArtifactMirrorPort: localArtifactMirrorPort,
}
chpfs, err := preflights.GetClusterHostPreflights(c.Context, data)
if err != nil {
Expand Down Expand Up @@ -190,7 +197,7 @@ func runHostPreflights(c *cli.Context, hpf *v1beta2.HostPreflightSpec, proxy *ec

pb.CloseWithError()
output.PrintTableWithoutInfo()
return fmt.Errorf("host preflight failures detected")
return ErrPreflightsHaveFail
}

// Warnings found
Expand Down Expand Up @@ -697,10 +704,25 @@ var installCommand = &cli.Command{
replicatedAPIURL = license.Spec.Endpoint
proxyRegistryURL = fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
}
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy); err != nil {

adminConsolePort, err := getAdminConsolePortFromFlag(c)
if err != nil {
return fmt.Errorf("unable to parse admin console port: %w", err)
}

localArtifactMirrorPort, err := getLocalArtifactMirrorPortFromFlag(c)
if err != nil {
return fmt.Errorf("unable to parse local artifact mirror port: %w", err)
}

if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
metrics.ReportApplyFinished(c, err)
if err == ErrPreflightsHaveFail {
return ErrNothingElseToAdd
}
return err
}

cfg, err := installAndWaitForK0s(c, applier, proxy)
if err != nil {
return err
Expand Down
27 changes: 21 additions & 6 deletions cmd/embedded-cluster/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -231,9 +232,26 @@ var joinCommand = &cli.Command{
// jcmd.InstallationSpec.MetricsBaseURL is the replicated.app endpoint url
replicatedAPIURL := jcmd.InstallationSpec.MetricsBaseURL
proxyRegistryURL := fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy); err != nil {
err := fmt.Errorf("unable to run host preflights locally: %w", err)

urlSlices := strings.Split(c.Args().Get(0), ":")
if len(urlSlices) != 2 {
return fmt.Errorf("unable to get port from url %s", c.Args().Get(0))
}
adminConsolePort, err := strconv.Atoi(urlSlices[1])
if err != nil {
return fmt.Errorf("unable to convert port to int: %w", err)
}

localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
if jcmd.InstallationSpec.LocalArtifactMirror != nil {
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
}

if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
metrics.ReportJoinFailed(c.Context, jcmd.InstallationSpec.MetricsBaseURL, jcmd.ClusterID, err)
if err == ErrPreflightsHaveFail {
return ErrNothingElseToAdd
}
return err
}

Expand Down Expand Up @@ -265,10 +283,7 @@ var joinCommand = &cli.Command{
}

logrus.Debugf("creating systemd unit files")
localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
if jcmd.InstallationSpec.LocalArtifactMirror != nil && jcmd.InstallationSpec.LocalArtifactMirror.Port > 0 {
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
}

// both controller and worker nodes will have 'worker' in the join command
if err := createSystemdUnitFiles(!strings.Contains(jcmd.K0sJoinCommand, "controller"), jcmd.InstallationSpec.Proxy, localArtifactMirrorPort); err != nil {
err := fmt.Errorf("unable to create systemd unit files: %w", err)
Expand Down
41 changes: 38 additions & 3 deletions cmd/embedded-cluster/preflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"os"
"strconv"
"strings"

"github.com/replicatedhq/embedded-cluster/pkg/defaults"
"github.com/replicatedhq/embedded-cluster/pkg/versions"
Expand Down Expand Up @@ -33,6 +35,8 @@ var installRunPreflightsCommand = &cli.Command{
Usage: "Disable interactive prompts.",
Value: false,
},
getAdminColsolePortFlag(),
getLocalArtifactMirrorPortFlag(),
},
)),
Before: func(c *cli.Context) error {
Expand Down Expand Up @@ -73,7 +77,21 @@ var installRunPreflightsCommand = &cli.Command{
replicatedAPIURL = license.Spec.Endpoint
proxyRegistryURL = fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
}
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy); err != nil {

adminConsolePort, err := getAdminConsolePortFromFlag(c)
if err != nil {
return fmt.Errorf("unable to parse admin console port: %w", err)
}

localArtifactMirrorPort, err := getLocalArtifactMirrorPortFromFlag(c)
if err != nil {
return fmt.Errorf("unable to parse local artifact mirror port: %w", err)
}

if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
if err == ErrPreflightsHaveFail {
return ErrNothingElseToAdd
}
return err
}

Expand Down Expand Up @@ -152,8 +170,25 @@ var joinRunPreflightsCommand = &cli.Command{
logrus.Debugf("running host preflights")
replicatedAPIURL := jcmd.InstallationSpec.MetricsBaseURL
proxyRegistryURL := fmt.Sprintf("https://%s", defaults.ProxyRegistryAddress)
if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy); err != nil {
err := fmt.Errorf("unable to run host preflights locally: %w", err)

urlSlices := strings.Split(c.Args().Get(0), ":")
if len(urlSlices) != 2 {
return fmt.Errorf("unable to get port from url %s", c.Args().Get(0))
}
adminConsolePort, err := strconv.Atoi(urlSlices[1])
if err != nil {
return fmt.Errorf("unable to convert port to int: %w", err)
}

localArtifactMirrorPort := defaults.LocalArtifactMirrorPort
if jcmd.InstallationSpec.LocalArtifactMirror != nil {
localArtifactMirrorPort = jcmd.InstallationSpec.LocalArtifactMirror.Port
}

if err := RunHostPreflights(c, applier, replicatedAPIURL, proxyRegistryURL, isAirgap, jcmd.InstallationSpec.Proxy, adminConsolePort, localArtifactMirrorPort); err != nil {
if err == ErrPreflightsHaveFail {
return ErrNothingElseToAdd
}
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"strings"

"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/urfave/cli/v2"

"github.com/replicatedhq/embedded-cluster/pkg/addons"
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/google/go-github/v62 v62.0.0
github.com/google/uuid v1.6.0
github.com/gosimple/slug v1.14.0
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/k0sproject/dig v0.2.0
github.com/k0sproject/k0s v1.29.9-0.20240821114611-d76eb6bb05a7
github.com/k0sproject/version v0.6.0
Expand Down Expand Up @@ -208,10 +208,8 @@ require (
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1 // indirect
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand Down Expand Up @@ -241,7 +239,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.13.6 // indirect
Expand All @@ -254,7 +251,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/zitadel/oidc/v2 v2.7.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
Expand Down
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1 h1:uvQJoKTHrFFu8zxoaopNK
github.com/go-macaroon-bakery/macaroon-bakery/v3 v3.0.1/go.mod h1:H59IYeChwvD1po3dhGUPvq5na+4NVD7SJlbhGKvslr0=
github.com/go-macaroon-bakery/macaroonpb v1.0.0 h1:It9exBaRMZ9iix1iJ6gwzfwsDE6ExNuwtAJ9e09v6XE=
github.com/go-macaroon-bakery/macaroonpb v1.0.0/go.mod h1:UzrGOcbiwTXISFP2XDLDPjfhMINZa+fX/7A2lMd31zc=
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
Expand Down Expand Up @@ -315,8 +311,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jeremija/gosubmit v0.2.7 h1:At0OhGCFGPXyjPYAsCchoBUhE099pcBXmsb4iZqROIc=
github.com/jeremija/gosubmit v0.2.7/go.mod h1:Ui+HS073lCFREXBbdfrJzMB57OI/bdxTiLtrDHHhFPI=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
Expand Down Expand Up @@ -431,8 +427,6 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/ohler55/ojg v1.24.1 h1:PaVLelrNgT5/0ppPaUtey54tOVp245z33fkhL2jljjY=
github.com/ohler55/ojg v1.24.1/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
Expand Down Expand Up @@ -582,8 +576,6 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/bridges/prometheus v0.52.0 h1:NNkEjNcUXeNcxDTNLyyAmFHefByhj8YU1AojgcPqbfs=
Expand Down
Loading

0 comments on commit a2463e1

Please sign in to comment.