@@ -27,6 +27,7 @@ import (
2727 "github.com/sirupsen/logrus"
2828 "github.com/spf13/cobra"
2929 "gopkg.in/yaml.v2"
30+ "k8s.io/client-go/kubernetes"
3031 "sigs.k8s.io/controller-runtime/pkg/client"
3132 k8syaml "sigs.k8s.io/yaml"
3233)
@@ -41,9 +42,7 @@ type JoinCmdFlags struct {
4142 ignoreHostPreflights bool
4243}
4344
44- // This is the upcoming version of join without the operator and where
45- // join does all of the work. This is a hidden command until it's tested
46- // and ready.
45+ // JoinCmd returns a cobra command for joining a node to the cluster.
4746func JoinCmd (ctx context.Context , name string ) * cobra.Command {
4847 var flags JoinCmdFlags
4948
@@ -202,23 +201,28 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
202201 return nil
203202 }
204203
205- airgapChartsPath := ""
206- if flags .isAirgap {
207- airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
208- }
204+ if flags .enableHighAvailability {
205+ kclient , err := kubeutils .GetClientset ()
206+ if err != nil {
207+ return fmt .Errorf ("unable to create kubernetes client: %w" , err )
208+ }
209209
210- hcli , err := helm .NewClient (helm.HelmOptions {
211- KubeConfig : runtimeconfig .PathToKubeConfig (),
212- K0sVersion : versions .K0sVersion ,
213- AirgapPath : airgapChartsPath ,
214- })
215- if err != nil {
216- return fmt .Errorf ("unable to create helm client: %w" , err )
217- }
218- defer hcli .Close ()
210+ airgapChartsPath := ""
211+ if flags .isAirgap {
212+ airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
213+ }
219214
220- if flags .enableHighAvailability {
221- if err := maybeEnableHA (ctx , kcli , hcli , flags .isAirgap , cidrCfg .ServiceCIDR , jcmd .InstallationSpec .Proxy , jcmd .InstallationSpec .Config ); err != nil {
215+ hcli , err := helm .NewClient (helm.HelmOptions {
216+ KubeConfig : runtimeconfig .PathToKubeConfig (),
217+ K0sVersion : versions .K0sVersion ,
218+ AirgapPath : airgapChartsPath ,
219+ })
220+ if err != nil {
221+ return fmt .Errorf ("unable to create helm client: %w" , err )
222+ }
223+ defer hcli .Close ()
224+
225+ if err := maybeEnableHA (ctx , kcli , kclient , hcli , flags .isAirgap , cidrCfg .ServiceCIDR , jcmd .InstallationSpec .Proxy , jcmd .InstallationSpec .Config ); err != nil {
222226 return fmt .Errorf ("unable to enable high availability: %w" , err )
223227 }
224228 }
@@ -493,8 +497,8 @@ func waitForNodeToJoin(ctx context.Context, kcli client.Client, hostname string,
493497 return nil
494498}
495499
496- func maybeEnableHA (ctx context.Context , kcli client.Client , hcli helm.Client , isAirgap bool , serviceCIDR string , proxy * ecv1beta1.ProxySpec , cfgspec * ecv1beta1.ConfigSpec ) error {
497- canEnableHA , err := addons .CanEnableHA (ctx , kcli )
500+ func maybeEnableHA (ctx context.Context , kcli client.Client , kclient kubernetes. Interface , hcli helm.Client , isAirgap bool , serviceCIDR string , proxy * ecv1beta1.ProxySpec , cfgspec * ecv1beta1.ConfigSpec ) error {
501+ canEnableHA , _ , err := addons .CanEnableHA (ctx , kcli )
498502 if err != nil {
499503 return fmt .Errorf ("unable to check if HA can be enabled: %w" , err )
500504 }
@@ -509,5 +513,5 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, hcli helm.Client, is
509513 return nil
510514 }
511515 logrus .Info ("" )
512- return addons .EnableHA (ctx , kcli , hcli , isAirgap , serviceCIDR , proxy , cfgspec )
516+ return addons .EnableHA (ctx , kcli , kclient , hcli , isAirgap , serviceCIDR , proxy , cfgspec )
513517}
0 commit comments