Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
65af37e2
Commit
65af37e2
authored
Oct 11, 2017
by
wackxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor NewCmdJoin function
parent
46c2bfe4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
29 deletions
+40
-29
join.go
cmd/kubeadm/app/cmd/join.go
+40
-29
No files found.
cmd/kubeadm/app/cmd/join.go
View file @
65af37e2
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"github.com/renstrom/dedent"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
flag
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
certutil
"k8s.io/client-go/util/cert"
certutil
"k8s.io/client-go/util/cert"
...
@@ -49,20 +50,8 @@ var (
...
@@ -49,20 +50,8 @@ var (
Run 'kubectl get nodes' on the master to see this machine join.
Run 'kubectl get nodes' on the master to see this machine join.
`
)
`
)
)
// NewCmdJoin returns "kubeadm join" command.
func
NewCmdJoin
(
out
io
.
Writer
)
*
cobra
.
Command
{
cfg
:=
&
kubeadmapiext
.
NodeConfiguration
{}
api
.
Scheme
.
Default
(
cfg
)
var
skipPreFlight
bool
var
cfgPath
string
cmd
:=
&
cobra
.
Command
{
joinLongDescription
=
dedent
.
Dedent
(
`
Use
:
"join <flags> [DiscoveryTokenAPIServers]"
,
Short
:
"Run this on any machine you wish to join an existing cluster"
,
Long
:
dedent
.
Dedent
(
`
When joining a kubeadm initialized cluster, we need to establish
When joining a kubeadm initialized cluster, we need to establish
bidirectional trust. This is split into discovery (having the Node
bidirectional trust. This is split into discovery (having the Node
trust the Kubernetes Master) and TLS bootstrap (having the Kubernetes
trust the Kubernetes Master) and TLS bootstrap (having the Kubernetes
...
@@ -102,7 +91,21 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
...
@@ -102,7 +91,21 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
Often times the same token is used for both parts. In this case, the
Often times the same token is used for both parts. In this case, the
--token flag can be used instead of specifying each token individually.
--token flag can be used instead of specifying each token individually.
`
),
`
)
)
// NewCmdJoin returns "kubeadm join" command.
func
NewCmdJoin
(
out
io
.
Writer
)
*
cobra
.
Command
{
cfg
:=
&
kubeadmapiext
.
NodeConfiguration
{}
api
.
Scheme
.
Default
(
cfg
)
var
skipPreFlight
bool
var
cfgPath
string
cmd
:=
&
cobra
.
Command
{
Use
:
"join [flags]"
,
Short
:
"Run this on any machine you wish to join an existing cluster"
,
Long
:
joinLongDescription
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
cfg
.
DiscoveryTokenAPIServers
=
args
cfg
.
DiscoveryTokenAPIServers
=
args
...
@@ -117,39 +120,47 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
...
@@ -117,39 +120,47 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
},
},
}
}
cmd
.
PersistentFlags
()
.
StringVar
(
AddJoinConfigFlags
(
cmd
.
PersistentFlags
(),
cfg
)
&
cfgPath
,
"config"
,
cfgPath
,
AddJoinOtherFlags
(
cmd
.
PersistentFlags
(),
&
cfgPath
,
&
skipPreFlight
)
"Path to kubeadm config file."
)
cmd
.
PersistentFlags
()
.
StringVar
(
return
cmd
}
// AddJoinConfigFlags adds join flags bound to the config to the specified flagset
func
AddJoinConfigFlags
(
flagSet
*
flag
.
FlagSet
,
cfg
*
kubeadmapiext
.
NodeConfiguration
)
{
flagSet
.
StringVar
(
&
cfg
.
DiscoveryFile
,
"discovery-file"
,
""
,
&
cfg
.
DiscoveryFile
,
"discovery-file"
,
""
,
"A file or url from which to load cluster information."
)
"A file or url from which to load cluster information."
)
cmd
.
PersistentFlags
()
.
StringVar
(
flagSet
.
StringVar
(
&
cfg
.
DiscoveryToken
,
"discovery-token"
,
""
,
&
cfg
.
DiscoveryToken
,
"discovery-token"
,
""
,
"A token used to validate cluster information fetched from the master."
)
"A token used to validate cluster information fetched from the master."
)
cmd
.
PersistentFlags
()
.
StringVar
(
flagSet
.
StringVar
(
&
cfg
.
NodeName
,
"node-name"
,
""
,
&
cfg
.
NodeName
,
"node-name"
,
""
,
"Specify the node name."
)
"Specify the node name."
)
cmd
.
PersistentFlags
()
.
StringVar
(
flagSet
.
StringVar
(
&
cfg
.
TLSBootstrapToken
,
"tls-bootstrap-token"
,
""
,
&
cfg
.
TLSBootstrapToken
,
"tls-bootstrap-token"
,
""
,
"A token used for TLS bootstrapping."
)
"A token used for TLS bootstrapping."
)
cmd
.
PersistentFlags
()
.
StringSliceVar
(
flagSet
.
StringSliceVar
(
&
cfg
.
DiscoveryTokenCACertHashes
,
"discovery-token-ca-cert-hash"
,
[]
string
{},
&
cfg
.
DiscoveryTokenCACertHashes
,
"discovery-token-ca-cert-hash"
,
[]
string
{},
"For token-based discovery, validate that the root CA public key matches this hash (format:
\"
<type>:<value>
\"
)."
)
"For token-based discovery, validate that the root CA public key matches this hash (format:
\"
<type>:<value>
\"
)."
)
cmd
.
PersistentFlags
()
.
BoolVar
(
flagSet
.
BoolVar
(
&
cfg
.
DiscoveryTokenUnsafeSkipCAVerification
,
"discovery-token-unsafe-skip-ca-verification"
,
false
,
&
cfg
.
DiscoveryTokenUnsafeSkipCAVerification
,
"discovery-token-unsafe-skip-ca-verification"
,
false
,
"For token-based discovery, allow joining without --discovery-token-ca-cert-hash pinning."
)
"For token-based discovery, allow joining without --discovery-token-ca-cert-hash pinning."
)
flagSet
.
StringVar
(
cmd
.
PersistentFlags
()
.
StringVar
(
&
cfg
.
Token
,
"token"
,
""
,
&
cfg
.
Token
,
"token"
,
""
,
"Use this token for both discovery-token and tls-bootstrap-token."
)
"Use this token for both discovery-token and tls-bootstrap-token."
)
}
cmd
.
PersistentFlags
()
.
BoolVar
(
// AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset
&
skipPreFlight
,
"skip-preflight-checks"
,
false
,
func
AddJoinOtherFlags
(
flagSet
*
flag
.
FlagSet
,
cfgPath
*
string
,
skipPreFlight
*
bool
)
{
flagSet
.
StringVar
(
cfgPath
,
"config"
,
*
cfgPath
,
"Path to kubeadm config file."
)
flagSet
.
BoolVar
(
skipPreFlight
,
"skip-preflight-checks"
,
false
,
"Skip preflight checks normally run before modifying the system."
,
"Skip preflight checks normally run before modifying the system."
,
)
)
return
cmd
}
}
// Join defines struct used by kubeadm join command
// Join defines struct used by kubeadm join command
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment