@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/AlecAivazis/survey/v2/terminal"
1212 k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
13+ "github.com/replicatedhq/embedded-cluster/cmd/installer/goods"
1314 ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1415 "github.com/replicatedhq/embedded-cluster/kinds/types/join"
1516 "github.com/replicatedhq/embedded-cluster/pkg/addons"
@@ -27,6 +28,7 @@ import (
2728 "github.com/replicatedhq/embedded-cluster/pkg/release"
2829 "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
2930 "github.com/replicatedhq/embedded-cluster/pkg/spinner"
31+ "github.com/replicatedhq/embedded-cluster/pkg/support"
3032 "github.com/replicatedhq/embedded-cluster/pkg/versions"
3133 "github.com/sirupsen/logrus"
3234 "github.com/spf13/cobra"
@@ -36,8 +38,6 @@ import (
3638)
3739
3840type JoinCmdFlags struct {
39- airgapBundle string
40- isAirgap bool
4141 noHA bool
4242 networkInterface string
4343 assumeYes bool
@@ -60,8 +60,6 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
6060 return err
6161 }
6262
63- flags .isAirgap = flags .airgapBundle != ""
64-
6563 return nil
6664 },
6765 PostRun : func (cmd * cobra.Command , args []string ) {
@@ -84,7 +82,7 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
8482 metricsReporter .ReportSignalAborted (ctx , sig )
8583 })
8684
87- if err := runJoin (cmd .Context (), name , flags , jcmd , metricsReporter ); err != nil {
85+ if err := runJoin (cmd .Context (), name , flags , jcmd , args [ 0 ], metricsReporter ); err != nil {
8886 // Check if this is an interrupt error from the terminal
8987 if errors .Is (err , terminal .InterruptErr ) {
9088 metricsReporter .ReportSignalAborted (ctx , syscall .SIGINT )
@@ -114,8 +112,6 @@ func preRunJoin(flags *JoinCmdFlags) error {
114112 return fmt .Errorf ("join command must be run as root" )
115113 }
116114
117- flags .isAirgap = flags .airgapBundle != ""
118-
119115 // if a network interface flag was not provided, attempt to discover it
120116 if flags .networkInterface == "" {
121117 autoInterface , err := determineBestNetworkInterface ()
@@ -128,7 +124,11 @@ func preRunJoin(flags *JoinCmdFlags) error {
128124}
129125
130126func addJoinFlags (cmd * cobra.Command , flags * JoinCmdFlags ) error {
131- cmd .Flags ().StringVar (& flags .airgapBundle , "airgap-bundle" , "" , "Path to the air gap bundle. If set, the installation will complete without internet access." )
127+ cmd .Flags ().String ("airgap-bundle" , "" , "Path to the air gap bundle. If set, the installation will complete without internet access." )
128+ if err := cmd .Flags ().MarkDeprecated ("airgap-bundle" , "This flag is deprecated (ignored) and will be removed in a future version. The cluster will automatically determine if it's in airgap mode and fetch the necessary artifacts from other nodes." ); err != nil {
129+ return err
130+ }
131+
132132 cmd .Flags ().StringVar (& flags .networkInterface , "network-interface" , "" , "The network interface to use for the cluster" )
133133 cmd .Flags ().BoolVar (& flags .ignoreHostPreflights , "ignore-host-preflights" , false , "Run host preflight checks, but prompt the user to continue if they fail instead of exiting." )
134134 cmd .Flags ().BoolVar (& flags .noHA , "no-ha" , false , "Do not prompt for or enable high availability." )
@@ -147,7 +147,7 @@ func addJoinFlags(cmd *cobra.Command, flags *JoinCmdFlags) error {
147147 return nil
148148}
149149
150- func runJoin (ctx context.Context , name string , flags JoinCmdFlags , jcmd * join.JoinCommandResponse , metricsReporter preflights.MetricsReporter ) error {
150+ func runJoin (ctx context.Context , name string , flags JoinCmdFlags , jcmd * join.JoinCommandResponse , kotsAPIAddress string , metricsReporter preflights.MetricsReporter ) error {
151151 // both controller and worker nodes will have 'worker' in the join command
152152 isWorker := ! strings .Contains (jcmd .K0sJoinCommand , "controller" )
153153 if ! isWorker {
@@ -158,7 +158,7 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *join.Jo
158158 return err
159159 }
160160
161- cidrCfg , err := initializeJoin (ctx , name , flags , jcmd )
161+ cidrCfg , err := initializeJoin (ctx , name , jcmd , kotsAPIAddress )
162162 if err != nil {
163163 return fmt .Errorf ("unable to initialize join: %w" , err )
164164 }
@@ -221,18 +221,6 @@ func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, jcmd *join.JoinComm
221221 return err
222222 }
223223
224- err = verifyChannelRelease ("join" , flags .isAirgap , flags .assumeYes )
225- if err != nil {
226- return err
227- }
228-
229- if flags .isAirgap {
230- logrus .Debugf ("checking airgap bundle matches binary" )
231- if err := checkAirgapMatches (flags .airgapBundle ); err != nil {
232- return err // we want the user to see the error message without a prefix
233- }
234- }
235-
236224 runtimeconfig .Set (jcmd .InstallationSpec .RuntimeConfig )
237225 isWorker := ! strings .Contains (jcmd .K0sJoinCommand , "controller" )
238226 if isWorker {
@@ -282,7 +270,7 @@ func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, jcmd *join.JoinComm
282270 return nil
283271}
284272
285- func initializeJoin (ctx context.Context , name string , flags JoinCmdFlags , jcmd * join.JoinCommandResponse ) (cidrCfg * CIDRConfig , err error ) {
273+ func initializeJoin (ctx context.Context , name string , jcmd * join.JoinCommandResponse , kotsAPIAddress string ) (cidrCfg * CIDRConfig , err error ) {
286274 logrus .Info ("" )
287275 spinner := spinner .Start ()
288276 spinner .Infof ("Initializing" )
@@ -305,8 +293,8 @@ func initializeJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *
305293 }
306294
307295 logrus .Debugf ("materializing %s binaries" , name )
308- if err := materializeFiles ( flags . airgapBundle ); err != nil {
309- return nil , err
296+ if err := materializeFilesForJoin ( ctx , jcmd , kotsAPIAddress ); err != nil {
297+ return nil , fmt . Errorf ( "failed to materialize files: %w" , err )
310298 }
311299
312300 logrus .Debugf ("configuring sysctl" )
@@ -337,6 +325,24 @@ func initializeJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *
337325 return cidrCfg , nil
338326}
339327
328+ func materializeFilesForJoin (ctx context.Context , jcmd * join.JoinCommandResponse , kotsAPIAddress string ) error {
329+ materializer := goods .NewMaterializer ()
330+ if err := materializer .Materialize (); err != nil {
331+ return fmt .Errorf ("materialize binaries: %w" , err )
332+ }
333+ if err := support .MaterializeSupportBundleSpec (); err != nil {
334+ return fmt .Errorf ("materialize support bundle spec: %w" , err )
335+ }
336+
337+ if jcmd .InstallationSpec .AirGap {
338+ if err := airgap .FetchAndWriteArtifacts (ctx , kotsAPIAddress ); err != nil {
339+ return fmt .Errorf ("failed to fetch artifacts: %w" , err )
340+ }
341+ }
342+
343+ return nil
344+ }
345+
340346func getJoinCIDRConfig (jcmd * join.JoinCommandResponse ) (* CIDRConfig , error ) {
341347 podCIDR , serviceCIDR , err := netutils .SplitNetworkCIDR (ecv1beta1 .DefaultNetworkCIDR )
342348 if err != nil {
@@ -400,7 +406,7 @@ func installAndJoinCluster(ctx context.Context, jcmd *join.JoinCommandResponse,
400406 return fmt .Errorf ("unable to join node to cluster: %w" , err )
401407 }
402408
403- if err := startAndWaitForK0s (ctx , name , jcmd ); err != nil {
409+ if err := startAndWaitForK0s (name ); err != nil {
404410 return err
405411 }
406412
@@ -464,7 +470,7 @@ func applyNetworkConfiguration(networkInterface string, jcmd *join.JoinCommandRe
464470}
465471
466472// startAndWaitForK0s starts the k0s service and waits for the node to be ready.
467- func startAndWaitForK0s (ctx context. Context , name string , jcmd * join. JoinCommandResponse ) error {
473+ func startAndWaitForK0s (name string ) error {
468474 logrus .Debugf ("starting %s service" , name )
469475 if _ , err := helpers .RunCommand (runtimeconfig .K0sBinaryPath (), "start" ); err != nil {
470476 return fmt .Errorf ("unable to start service: %w" , err )
@@ -600,7 +606,7 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, flags JoinCmdFlags,
600606 }
601607
602608 airgapChartsPath := ""
603- if flags . isAirgap {
609+ if jcmd . InstallationSpec . AirGap {
604610 airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
605611 }
606612 hcli , err := helm .NewClient (helm.HelmOptions {
0 commit comments