@@ -26,6 +26,7 @@ import (
26
26
"github.com/sirupsen/logrus"
27
27
"github.com/spf13/cobra"
28
28
"gopkg.in/yaml.v2"
29
+ "k8s.io/client-go/kubernetes"
29
30
"sigs.k8s.io/controller-runtime/pkg/client"
30
31
k8syaml "sigs.k8s.io/yaml"
31
32
)
@@ -40,9 +41,7 @@ type JoinCmdFlags struct {
40
41
ignoreHostPreflights bool
41
42
}
42
43
43
- // This is the upcoming version of join without the operator and where
44
- // join does all of the work. This is a hidden command until it's tested
45
- // and ready.
44
+ // JoinCmd returns a cobra command for joining a node to the cluster.
46
45
func JoinCmd (ctx context.Context , name string ) * cobra.Command {
47
46
var flags JoinCmdFlags
48
47
@@ -171,21 +170,6 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
171
170
return fmt .Errorf ("unable to get kube client: %w" , err )
172
171
}
173
172
174
- airgapChartsPath := ""
175
- if flags .isAirgap {
176
- airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
177
- }
178
-
179
- hcli , err := helm .NewClient (helm.HelmOptions {
180
- KubeConfig : runtimeconfig .PathToKubeConfig (),
181
- K0sVersion : versions .K0sVersion ,
182
- AirgapPath : airgapChartsPath ,
183
- })
184
- if err != nil {
185
- return fmt .Errorf ("unable to create helm client: %w" , err )
186
- }
187
- defer hcli .Close ()
188
-
189
173
hostname , err := os .Hostname ()
190
174
if err != nil {
191
175
return fmt .Errorf ("unable to get hostname: %w" , err )
@@ -196,7 +180,27 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
196
180
}
197
181
198
182
if flags .enableHighAvailability {
199
- if err := maybeEnableHA (ctx , kcli , hcli , flags .isAirgap , cidrCfg .ServiceCIDR , jcmd .InstallationSpec .Proxy , jcmd .InstallationSpec .Config ); err != nil {
183
+ kclient , err := kubeutils .GetClientset ()
184
+ if err != nil {
185
+ return fmt .Errorf ("unable to create kubernetes client: %w" , err )
186
+ }
187
+
188
+ airgapChartsPath := ""
189
+ if flags .isAirgap {
190
+ airgapChartsPath = runtimeconfig .EmbeddedClusterChartsSubDir ()
191
+ }
192
+
193
+ hcli , err := helm .NewClient (helm.HelmOptions {
194
+ KubeConfig : runtimeconfig .PathToKubeConfig (),
195
+ K0sVersion : versions .K0sVersion ,
196
+ AirgapPath : airgapChartsPath ,
197
+ })
198
+ if err != nil {
199
+ return fmt .Errorf ("unable to create helm client: %w" , err )
200
+ }
201
+ defer hcli .Close ()
202
+
203
+ if err := maybeEnableHA (ctx , kcli , kclient , hcli , flags .isAirgap , cidrCfg .ServiceCIDR , jcmd .InstallationSpec .Proxy , jcmd .InstallationSpec .Config ); err != nil {
200
204
return fmt .Errorf ("unable to enable high availability: %w" , err )
201
205
}
202
206
}
@@ -460,8 +464,8 @@ func waitForNode(ctx context.Context, kcli client.Client, hostname string) error
460
464
return nil
461
465
}
462
466
463
- func maybeEnableHA (ctx context.Context , kcli client.Client , hcli helm.Client , isAirgap bool , serviceCIDR string , proxy * ecv1beta1.ProxySpec , cfgspec * ecv1beta1.ConfigSpec ) error {
464
- canEnableHA , err := addons .CanEnableHA (ctx , kcli )
467
+ 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 {
468
+ canEnableHA , _ , err := addons .CanEnableHA (ctx , kcli )
465
469
if err != nil {
466
470
return fmt .Errorf ("unable to check if HA can be enabled: %w" , err )
467
471
}
@@ -476,5 +480,5 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, hcli helm.Client, is
476
480
return nil
477
481
}
478
482
logrus .Info ("" )
479
- return addons .EnableHA (ctx , kcli , hcli , isAirgap , serviceCIDR , proxy , cfgspec )
483
+ return addons .EnableHA (ctx , kcli , kclient , hcli , isAirgap , serviceCIDR , proxy , cfgspec )
480
484
}
0 commit comments