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
1b9986b2
Commit
1b9986b2
authored
Nov 14, 2018
by
fabriziopandini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kubeadm phases - add local flags
parent
ba7d3c3b
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
109 additions
and
71 deletions
+109
-71
init.go
cmd/kubeadm/app/cmd/init.go
+1
-1
addons.go
cmd/kubeadm/app/cmd/phases/addons.go
+13
-13
bootstraptoken.go
cmd/kubeadm/app/cmd/phases/bootstraptoken.go
+1
-1
certs.go
cmd/kubeadm/app/cmd/phases/certs.go
+7
-7
controlplane.go
cmd/kubeadm/app/cmd/phases/controlplane.go
+6
-6
etcd.go
cmd/kubeadm/app/cmd/phases/etcd.go
+6
-6
kubeconfig.go
cmd/kubeadm/app/cmd/phases/kubeconfig.go
+7
-7
kubelet.go
cmd/kubeadm/app/cmd/phases/kubelet.go
+1
-1
markcontrolplane.go
cmd/kubeadm/app/cmd/phases/markcontrolplane.go
+1
-1
preflight.go
cmd/kubeadm/app/cmd/phases/preflight.go
+1
-1
uploadconfig.go
cmd/kubeadm/app/cmd/phases/uploadconfig.go
+12
-12
phase.go
cmd/kubeadm/app/cmd/phases/workflow/phase.go
+12
-4
runner.go
cmd/kubeadm/app/cmd/phases/workflow/runner.go
+15
-7
runner_test.go
cmd/kubeadm/app/cmd/phases/workflow/runner_test.go
+26
-4
No files found.
cmd/kubeadm/app/cmd/init.go
View file @
1b9986b2
...
...
@@ -155,7 +155,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// defines additional flag that are not used by the init command but that could be eventually used
// by the sub-commands automatically generated for phases
initRunner
.
Set
PhaseSubcommands
AdditionalFlags
(
func
(
flags
*
flag
.
FlagSet
)
{
initRunner
.
SetAdditionalFlags
(
func
(
flags
*
flag
.
FlagSet
)
{
options
.
AddImageMetaFlags
(
flags
,
&
initOptions
.
externalcfg
.
ImageRepository
)
options
.
AddKubeConfigFlag
(
flags
,
&
initOptions
.
kubeconfigPath
)
options
.
AddKubeConfigDirFlag
(
flags
,
&
initOptions
.
kubeconfigDir
)
...
...
cmd/kubeadm/app/cmd/phases/addons.go
View file @
1b9986b2
...
...
@@ -47,23 +47,23 @@ type addonData interface {
// NewAddonPhase returns the addon Cobra command
func
NewAddonPhase
()
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
"addon"
,
Short
:
"Installs required addons for passing Conformance tests"
,
Cmd
Flags
:
getAddonPhaseFlags
(
"all"
),
Name
:
"addon"
,
Short
:
"Installs required addons for passing Conformance tests"
,
Inherit
Flags
:
getAddonPhaseFlags
(
"all"
),
Phases
:
[]
workflow
.
Phase
{
{
Name
:
"coredns"
,
Short
:
"Installs the CoreDNS addon to a Kubernetes cluster"
,
Long
:
coreDNSAddonLongDesc
,
Cmd
Flags
:
getAddonPhaseFlags
(
"coredns"
),
Run
:
runCoreDNSAddon
,
Name
:
"coredns"
,
Short
:
"Installs the CoreDNS addon to a Kubernetes cluster"
,
Long
:
coreDNSAddonLongDesc
,
Inherit
Flags
:
getAddonPhaseFlags
(
"coredns"
),
Run
:
runCoreDNSAddon
,
},
{
Name
:
"kube-proxy"
,
Short
:
"Installs the kube-proxy addon to a Kubernetes cluster"
,
Long
:
kubeProxyAddonLongDesc
,
Cmd
Flags
:
getAddonPhaseFlags
(
"kube-proxy"
),
Run
:
runKubeProxyAddon
,
Name
:
"kube-proxy"
,
Short
:
"Installs the kube-proxy addon to a Kubernetes cluster"
,
Long
:
kubeProxyAddonLongDesc
,
Inherit
Flags
:
getAddonPhaseFlags
(
"kube-proxy"
),
Run
:
runKubeProxyAddon
,
},
},
}
...
...
cmd/kubeadm/app/cmd/phases/bootstraptoken.go
View file @
1b9986b2
...
...
@@ -64,7 +64,7 @@ func NewBootstrapTokenPhase() workflow.Phase {
Short
:
"Generates bootstrap tokens used to join a node to a cluster"
,
Example
:
bootstrapTokenExamples
,
Long
:
bootstrapTokenLongDesc
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
KubeconfigDir
,
options
.
SkipTokenPrint
,
...
...
cmd/kubeadm/app/cmd/phases/certs.go
View file @
1b9986b2
...
...
@@ -60,11 +60,11 @@ type certsData interface {
// NewCertsPhase returns the phase for the certs
func
NewCertsPhase
()
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
"certs"
,
Short
:
"Certificate generation"
,
Phases
:
newCertSubPhases
(),
Run
:
runCerts
,
Cmd
Flags
:
getCertPhaseFlags
(
"all"
),
Name
:
"certs"
,
Short
:
"Certificate generation"
,
Phases
:
newCertSubPhases
(),
Run
:
runCerts
,
Inherit
Flags
:
getCertPhaseFlags
(
"all"
),
}
}
...
...
@@ -107,8 +107,8 @@ func newCertSubPhase(certSpec *certsphase.KubeadmCert, run func(c workflow.RunDa
certSpec
.
BaseName
,
getSANDescription
(
certSpec
),
),
Run
:
run
,
Cmd
Flags
:
getCertPhaseFlags
(
certSpec
.
Name
),
Run
:
run
,
Inherit
Flags
:
getCertPhaseFlags
(
certSpec
.
Name
),
}
return
phase
}
...
...
cmd/kubeadm/app/cmd/phases/controlplane.go
View file @
1b9986b2
...
...
@@ -77,18 +77,18 @@ func NewControlPlanePhase() workflow.Phase {
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeControllerManager
),
newControlPlaneSubPhase
(
kubeadmconstants
.
KubeScheduler
),
},
Run
:
runControlPlanePhase
,
Cmd
Flags
:
getControlPlanePhaseFlags
(
"all"
),
Run
:
runControlPlanePhase
,
Inherit
Flags
:
getControlPlanePhaseFlags
(
"all"
),
}
return
phase
}
func
newControlPlaneSubPhase
(
component
string
)
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
Name
:
controlPlanePhaseProperties
[
component
]
.
name
,
Short
:
controlPlanePhaseProperties
[
component
]
.
short
,
Run
:
runControlPlaneSubPhase
(
component
),
Cmd
Flags
:
getControlPlanePhaseFlags
(
component
),
Name
:
controlPlanePhaseProperties
[
component
]
.
name
,
Short
:
controlPlanePhaseProperties
[
component
]
.
short
,
Run
:
runControlPlaneSubPhase
(
component
),
Inherit
Flags
:
getControlPlanePhaseFlags
(
component
),
}
return
phase
}
...
...
cmd/kubeadm/app/cmd/phases/etcd.go
View file @
1b9986b2
...
...
@@ -54,18 +54,18 @@ func NewEtcdPhase() workflow.Phase {
Phases
:
[]
workflow
.
Phase
{
newEtcdLocalSubPhase
(),
},
Cmd
Flags
:
getEtcdPhaseFlags
(),
Inherit
Flags
:
getEtcdPhaseFlags
(),
}
return
phase
}
func
newEtcdLocalSubPhase
()
workflow
.
Phase
{
phase
:=
workflow
.
Phase
{
Name
:
"local"
,
Short
:
"Generates the static Pod manifest file for a local, single-node local etcd instance."
,
Example
:
etcdLocalExample
,
Run
:
runEtcdPhaseLocal
(),
Cmd
Flags
:
getEtcdPhaseFlags
(),
Name
:
"local"
,
Short
:
"Generates the static Pod manifest file for a local, single-node local etcd instance."
,
Example
:
etcdLocalExample
,
Run
:
runEtcdPhaseLocal
(),
Inherit
Flags
:
getEtcdPhaseFlags
(),
}
return
phase
}
...
...
cmd/kubeadm/app/cmd/phases/kubeconfig.go
View file @
1b9986b2
...
...
@@ -83,19 +83,19 @@ func NewKubeConfigPhase() workflow.Phase {
NewKubeConfigFilePhase
(
kubeadmconstants
.
ControllerManagerKubeConfigFileName
),
NewKubeConfigFilePhase
(
kubeadmconstants
.
SchedulerKubeConfigFileName
),
},
Run
:
runKubeConfig
,
Cmd
Flags
:
getKubeConfigPhaseFlags
(
"all"
),
Run
:
runKubeConfig
,
Inherit
Flags
:
getKubeConfigPhaseFlags
(
"all"
),
}
}
// NewKubeConfigFilePhase creates a kubeadm workflow phase that creates a kubeconfig file.
func
NewKubeConfigFilePhase
(
kubeConfigFileName
string
)
workflow
.
Phase
{
return
workflow
.
Phase
{
Name
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
name
,
Short
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
short
,
Long
:
fmt
.
Sprintf
(
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
long
,
kubeConfigFileName
),
Run
:
runKubeConfigFile
(
kubeConfigFileName
),
Cmd
Flags
:
getKubeConfigPhaseFlags
(
kubeConfigFileName
),
Name
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
name
,
Short
:
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
short
,
Long
:
fmt
.
Sprintf
(
kubeconfigFilePhaseProperties
[
kubeConfigFileName
]
.
long
,
kubeConfigFileName
),
Run
:
runKubeConfigFile
(
kubeConfigFileName
),
Inherit
Flags
:
getKubeConfigPhaseFlags
(
kubeConfigFileName
),
}
}
...
...
cmd/kubeadm/app/cmd/phases/kubelet.go
View file @
1b9986b2
...
...
@@ -50,7 +50,7 @@ func NewKubeletStartPhase() workflow.Phase {
Long
:
"Writes a file with KubeletConfiguration and an environment file with node specific kubelet settings, and then (re)starts kubelet."
,
Example
:
kubeletStartPhaseExample
,
Run
:
runKubeletStart
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
NodeCRISocket
,
options
.
NodeName
,
...
...
cmd/kubeadm/app/cmd/phases/markcontrolplane.go
View file @
1b9986b2
...
...
@@ -48,7 +48,7 @@ func NewMarkControlPlanePhase() workflow.Phase {
Name
:
"mark-control-plane"
,
Short
:
"Mark a node as a control-plane"
,
Example
:
markControlPlaneExample
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
NodeName
,
},
Run
:
runMarkControlPlane
,
...
...
cmd/kubeadm/app/cmd/phases/preflight.go
View file @
1b9986b2
...
...
@@ -53,7 +53,7 @@ func NewPreflightMasterPhase() workflow.Phase {
Long
:
"Run master pre-flight checks, functionally equivalent to what implemented by kubeadm init."
,
Example
:
masterPreflightExample
,
Run
:
runPreflightMaster
,
Cmd
Flags
:
[]
string
{
Inherit
Flags
:
[]
string
{
options
.
CfgPath
,
options
.
IgnorePreflightErrors
,
},
...
...
cmd/kubeadm/app/cmd/phases/uploadconfig.go
View file @
1b9986b2
...
...
@@ -72,20 +72,20 @@ func NewUploadConfigPhase() workflow.Phase {
Long
:
cmdutil
.
MacroCommandLongDescription
,
Phases
:
[]
workflow
.
Phase
{
{
Name
:
"kubeadm"
,
Short
:
"Uploads the kubeadm ClusterConfiguration to a ConfigMap"
,
Long
:
uploadKubeadmConfigLongDesc
,
Example
:
uploadKubeadmConfigExample
,
Run
:
runUploadKubeadmConfig
,
Cmd
Flags
:
getUploadConfigPhaseFlags
(),
Name
:
"kubeadm"
,
Short
:
"Uploads the kubeadm ClusterConfiguration to a ConfigMap"
,
Long
:
uploadKubeadmConfigLongDesc
,
Example
:
uploadKubeadmConfigExample
,
Run
:
runUploadKubeadmConfig
,
Inherit
Flags
:
getUploadConfigPhaseFlags
(),
},
{
Name
:
"kubelet"
,
Short
:
"Uploads the kubelet component config to a ConfigMap"
,
Long
:
uploadKubeletConfigLongDesc
,
Example
:
uploadKubeletConfigExample
,
Run
:
runUploadKubeletConfig
,
Cmd
Flags
:
getUploadConfigPhaseFlags
(),
Name
:
"kubelet"
,
Short
:
"Uploads the kubelet component config to a ConfigMap"
,
Long
:
uploadKubeletConfigLongDesc
,
Example
:
uploadKubeletConfigExample
,
Run
:
runUploadKubeletConfig
,
Inherit
Flags
:
getUploadConfigPhaseFlags
(),
},
},
}
...
...
cmd/kubeadm/app/cmd/phases/workflow/phase.go
View file @
1b9986b2
...
...
@@ -16,6 +16,8 @@ limitations under the License.
package
workflow
import
"github.com/spf13/pflag"
// Phase provides an implementation of a workflow phase that allows
// creation of new phases by simply instantiating a variable of this type.
type
Phase
struct
{
...
...
@@ -53,11 +55,17 @@ type Phase struct {
// If this function return nil, the phase action is always executed.
RunIf
func
(
data
RunData
)
(
bool
,
error
)
//
CmdFlags defines the list of flags that should be assigned to the cobra command generated
// f
or this phase; flags are inherited from the parent command or defined as additional flags
//
in the phase runner.
If the values is not set or empty, no flags will be assigned to the command
//
InheritFlags defines the list of flags that the cobra command generated for this phase should Inherit
// f
rom local flags defined in the parent command / or additional flags defined in the phase runner.
// If the values is not set or empty, no flags will be assigned to the command
// Nb. global flags are automatically inherited by nested cobra command
CmdFlags
[]
string
InheritFlags
[]
string
// LocalFlags defines the list of flags that should be assigned to the cobra command generated
// for this phase.
// Nb. if two or phases have the same local flags, please consider using local flags in the parent command
// or additional flags defined in the phase runner.
LocalFlags
*
pflag
.
FlagSet
}
// AppendPhase adds the given phase to the nested, ordered sequence of phases.
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner.go
View file @
1b9986b2
...
...
@@ -60,8 +60,8 @@ type Runner struct {
// more than one time)
runData
RunData
// cmdAdditionalFlags holds additional flags that could be added to the subcommands generated
// for
each phase. Flags could be inherited from the parent command too
// cmdAdditionalFlags holds additional
, shared
flags that could be added to the subcommands generated
// for
phases. Flags could be inherited from the parent command too or added directly to each phase
cmdAdditionalFlags
*
pflag
.
FlagSet
// phaseRunners is part of the internal state of the runner and provides
...
...
@@ -269,10 +269,11 @@ func (e *Runner) Help(cmdUse string) string {
return
line
}
// Set
PhaseSubcommands
AdditionalFlags allows to define flags to be added
// SetAdditionalFlags allows to define flags to be added
// to the subcommands generated for each phase (but not existing in the parent command).
// Please note that this command needs to be done before BindToCommand.
func
(
e
*
Runner
)
SetPhaseSubcommandsAdditionalFlags
(
fn
func
(
*
pflag
.
FlagSet
))
{
// Nb. if a flag is used only by one phase, please consider using phase LocalFlags.
func
(
e
*
Runner
)
SetAdditionalFlags
(
fn
func
(
*
pflag
.
FlagSet
))
{
// creates a new NewFlagSet
e
.
cmdAdditionalFlags
=
pflag
.
NewFlagSet
(
"phaseAdditionalFlags"
,
pflag
.
ContinueOnError
)
// invokes the function that sets additional flags
...
...
@@ -325,11 +326,18 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
// makes the new command inherits local flags from the parent command
// Nb. global flags will be inherited automatically
inheritsFlags
(
cmd
.
Flags
(),
phaseCmd
.
Flags
(),
p
.
Cmd
Flags
)
inheritsFlags
(
cmd
.
Flags
(),
phaseCmd
.
Flags
(),
p
.
Inherit
Flags
)
//
If defined, additional flags for phases should be added as well
//
makes the new command inherits additional flags for phases
if
e
.
cmdAdditionalFlags
!=
nil
{
inheritsFlags
(
e
.
cmdAdditionalFlags
,
phaseCmd
.
Flags
(),
p
.
CmdFlags
)
inheritsFlags
(
e
.
cmdAdditionalFlags
,
phaseCmd
.
Flags
(),
p
.
InheritFlags
)
}
// If defined, added phase local flags
if
p
.
LocalFlags
!=
nil
{
p
.
LocalFlags
.
VisitAll
(
func
(
f
*
pflag
.
Flag
)
{
phaseCmd
.
Flags
()
.
AddFlag
(
f
)
})
}
// adds the command to parent
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner_test.go
View file @
1b9986b2
...
...
@@ -284,14 +284,25 @@ func TestHelp(t *testing.T) {
func
phaseBuilder4
(
name
string
,
cmdFlags
[]
string
,
phases
...
Phase
)
Phase
{
return
Phase
{
Name
:
name
,
Phases
:
phases
,
CmdFlags
:
cmdFlags
,
Name
:
name
,
Phases
:
phases
,
InheritFlags
:
cmdFlags
,
}
}
func
phaseBuilder5
(
name
string
,
flags
*
pflag
.
FlagSet
)
Phase
{
return
Phase
{
Name
:
name
,
LocalFlags
:
flags
,
}
}
func
TestBindToCommand
(
t
*
testing
.
T
)
{
var
dummy
string
localFlags
:=
pflag
.
NewFlagSet
(
"dummy"
,
pflag
.
ContinueOnError
)
localFlags
.
StringVarP
(
&
dummy
,
"flag4"
,
"d"
,
"d"
,
"d"
)
var
usecases
=
[]
struct
{
name
string
runner
Runner
...
...
@@ -340,12 +351,22 @@ func TestBindToCommand(t *testing.T) {
},
},
{
name
:
"it should be possible to apply custom flags to single phases"
,
runner
:
Runner
{
Phases
:
[]
Phase
{
phaseBuilder5
(
"foo"
,
localFlags
)},
},
expectedCmdAndFlags
:
map
[
string
][]
string
{
"phase foo"
:
{
"flag4"
},
},
},
{
name
:
"all the above applies to nested phases too"
,
runner
:
Runner
{
Phases
:
[]
Phase
{
phaseBuilder4
(
"foo"
,
[]
string
{
"flag3"
},
phaseBuilder4
(
"bar"
,
[]
string
{
"flag1"
,
"flag2"
,
"flag3"
}),
phaseBuilder4
(
"baz"
,
[]
string
{
"flag1"
}),
//test if additional flags are filtered too
phaseBuilder5
(
"qux"
,
localFlags
),
),
},
},
...
...
@@ -357,6 +378,7 @@ func TestBindToCommand(t *testing.T) {
"phase foo"
:
{
"flag3"
},
"phase foo bar"
:
{
"flag1"
,
"flag2"
,
"flag3"
},
"phase foo baz"
:
{
"flag1"
},
"phase foo qux"
:
{
"flag4"
},
},
},
}
...
...
@@ -372,7 +394,7 @@ func TestBindToCommand(t *testing.T) {
cmd
.
Flags
()
.
StringVarP
(
&
dummy2
,
"flag2"
,
"b"
,
"b"
,
"b"
)
if
rt
.
setAdditionalFlags
!=
nil
{
rt
.
runner
.
Set
PhaseSubcommands
AdditionalFlags
(
rt
.
setAdditionalFlags
)
rt
.
runner
.
SetAdditionalFlags
(
rt
.
setAdditionalFlags
)
}
rt
.
runner
.
BindToCommand
(
cmd
)
...
...
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