@@ -20,6 +20,7 @@ package join
20
20
import (
21
21
"fmt"
22
22
"io"
23
+ "os"
23
24
"strings"
24
25
25
26
"github.com/pkg/errors"
@@ -35,6 +36,7 @@ import (
35
36
"github.com/openyurtio/openyurt/pkg/util/kubernetes/kubeadm/app/util/apiclient"
36
37
"github.com/openyurtio/openyurt/pkg/yurtadm/cmd/join/joindata"
37
38
yurtphases "github.com/openyurtio/openyurt/pkg/yurtadm/cmd/join/phases"
39
+ "github.com/openyurtio/openyurt/pkg/yurtadm/constants"
38
40
yurtconstants "github.com/openyurtio/openyurt/pkg/yurtadm/constants"
39
41
"github.com/openyurtio/openyurt/pkg/yurtadm/util/edgenode"
40
42
yurtadmutil "github.com/openyurtio/openyurt/pkg/yurtadm/util/kubernetes"
@@ -52,6 +54,8 @@ type joinOptions struct {
52
54
organizations string
53
55
pauseImage string
54
56
yurthubImage string
57
+ yurthubBinary string
58
+ hostControlPlaneAddr string // hostControlPlaneAddr is the address (ip:port) of host kubernetes cluster that used for yurthub local mode.
55
59
namespace string
56
60
caCertHashes []string
57
61
unsafeSkipCAVerification bool
@@ -124,7 +128,7 @@ func addJoinConfigFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
124
128
)
125
129
flagSet .StringVar (
126
130
& joinOptions .nodeType , yurtconstants .NodeType , joinOptions .nodeType ,
127
- "Sets the node is edge or cloud " ,
131
+ "Sets the node is edge, cloud or local " ,
128
132
)
129
133
flagSet .StringVar (
130
134
& joinOptions .nodeName , yurtconstants .NodeName , joinOptions .nodeName ,
@@ -154,6 +158,14 @@ func addJoinConfigFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
154
158
& joinOptions .yurthubImage , yurtconstants .YurtHubImage , joinOptions .yurthubImage ,
155
159
"Sets the image version of yurthub component" ,
156
160
)
161
+ flagSet .StringVar (
162
+ & joinOptions .yurthubBinary , yurtconstants .YurtHubBinary , joinOptions .yurthubBinary ,
163
+ "Sets the binary path of yurthub, this is used for deploying local mode yurthub in systemd" ,
164
+ )
165
+ flagSet .StringVar (
166
+ & joinOptions .hostControlPlaneAddr , yurtconstants .HostControlPlaneAddr , joinOptions .hostControlPlaneAddr ,
167
+ "Sets the address of hostControlPlaneAddr, which is the address (ip:port) of host kubernetes cluster that used for yurthub local mode" ,
168
+ )
157
169
flagSet .StringSliceVar (
158
170
& joinOptions .caCertHashes , yurtconstants .TokenDiscoveryCAHash , joinOptions .caCertHashes ,
159
171
"For token-based discovery, validate that the root CA public key matches this hash (format: \" <type>:<value>\" )." ,
@@ -227,6 +239,8 @@ type joinData struct {
227
239
organizations string
228
240
pauseImage string
229
241
yurthubImage string
242
+ yurthubBinary string
243
+ hostControlPlaneAddr string
230
244
yurthubTemplate string
231
245
yurthubManifest string
232
246
kubernetesVersion string
@@ -257,6 +271,25 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {
257
271
apiServerEndpoint = args [0 ]
258
272
}
259
273
274
+ if opt .nodeType == constants .LocalNode {
275
+ // in local mode, it is necessary to prepare yurthub binary file for deploying systemd yurthub.
276
+ if len (opt .yurthubBinary ) == 0 {
277
+ return nil , errors .New ("yurthub binary filepath is empty, so unable to run systemd yurthub in local mode." )
278
+ }
279
+ _ , err := os .Stat (opt .yurthubBinary )
280
+ if err != nil {
281
+ if os .IsNotExist (err ) {
282
+ return nil , errors .New ("yurthub binary file does not exist." )
283
+ }
284
+ return nil , errors .Wrapf (err , "stat yurthub binary file %s fail" , opt .yurthubBinary )
285
+ }
286
+
287
+ // in local mode, hostControlPlaneAddr is needed for systemd yurthub accessing host kubernetes cluster.
288
+ if len (opt .hostControlPlaneAddr ) == 0 {
289
+ return nil , errors .New ("host control plane address is empty, so unable to run systemd yurthub in local mode." )
290
+ }
291
+ }
292
+
260
293
if len (opt .token ) == 0 {
261
294
return nil , errors .New ("join token is empty, so unable to bootstrap worker node." )
262
295
}
@@ -265,8 +298,8 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {
265
298
return nil , errors .Errorf ("the bootstrap token %s was not of the form %s" , opt .token , yurtconstants .BootstrapTokenPattern )
266
299
}
267
300
268
- if opt .nodeType != yurtconstants .EdgeNode && opt .nodeType != yurtconstants .CloudNode {
269
- return nil , errors .Errorf ("node type(%s) is invalid, only \" edge and cloud \" are supported" , opt .nodeType )
301
+ if opt .nodeType != yurtconstants .EdgeNode && opt .nodeType != yurtconstants .CloudNode && opt . nodeType != yurtconstants . LocalNode {
302
+ return nil , errors .Errorf ("node type(%s) is invalid, only \" edge, cloud and local \" are supported" , opt .nodeType )
270
303
}
271
304
272
305
if opt .unsafeSkipCAVerification && len (opt .caCertHashes ) != 0 {
@@ -298,6 +331,8 @@ func newJoinData(args []string, opt *joinOptions) (*joinData, error) {
298
331
ignorePreflightErrors : ignoreErrors ,
299
332
pauseImage : opt .pauseImage ,
300
333
yurthubImage : opt .yurthubImage ,
334
+ yurthubBinary : opt .yurthubBinary ,
335
+ hostControlPlaneAddr : opt .hostControlPlaneAddr ,
301
336
yurthubServer : opt .yurthubServer ,
302
337
caCertHashes : opt .caCertHashes ,
303
338
organizations : opt .organizations ,
@@ -439,6 +474,15 @@ func (j *joinData) YurtHubImage() string {
439
474
return j .yurthubImage
440
475
}
441
476
477
+ // YurtHubBinary returns the YurtHub binary.
478
+ func (j * joinData ) YurtHubBinary () string {
479
+ return j .yurthubBinary
480
+ }
481
+
482
+ func (j * joinData ) HostControlPlaneAddr () string {
483
+ return j .hostControlPlaneAddr
484
+ }
485
+
442
486
// YurtHubServer returns the YurtHub server addr.
443
487
func (j * joinData ) YurtHubServer () string {
444
488
return j .yurthubServer
0 commit comments