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
a5f06fdd
Unverified
Commit
a5f06fdd
authored
Nov 16, 2018
by
k8s-ci-robot
Committed by
GitHub
Nov 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71066 from fabriziopandini/kubeadm-fix-validateMixedArgs
Kubeadm - Fix validateMixedArgs for phases
parents
0908af5e
807338e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
init.go
cmd/kubeadm/app/cmd/init.go
+1
-1
doc_test.go
cmd/kubeadm/app/cmd/phases/workflow/doc_test.go
+3
-1
runner.go
cmd/kubeadm/app/cmd/phases/workflow/runner.go
+13
-3
No files found.
cmd/kubeadm/app/cmd/init.go
View file @
a5f06fdd
...
@@ -177,7 +177,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
...
@@ -177,7 +177,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// sets the data builder function, that will be used by the runner
// sets the data builder function, that will be used by the runner
// both when running the entire workflow or single phases
// both when running the entire workflow or single phases
initRunner
.
SetDataInitializer
(
func
()
(
workflow
.
RunData
,
error
)
{
initRunner
.
SetDataInitializer
(
func
(
cmd
*
cobra
.
Command
)
(
workflow
.
RunData
,
error
)
{
return
newInitData
(
cmd
,
initOptions
,
out
)
return
newInitData
(
cmd
,
initOptions
,
out
)
})
})
...
...
cmd/kubeadm/app/cmd/phases/workflow/doc_test.go
View file @
a5f06fdd
...
@@ -19,6 +19,8 @@ package workflow
...
@@ -19,6 +19,8 @@ package workflow
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"github.com/spf13/cobra"
)
)
var
myWorkflowRunner
=
NewRunner
()
var
myWorkflowRunner
=
NewRunner
()
...
@@ -100,7 +102,7 @@ func ExampleRunner_Run() {
...
@@ -100,7 +102,7 @@ func ExampleRunner_Run() {
// Defines the method that creates the runtime data shared
// Defines the method that creates the runtime data shared
// among all the phases included in the workflow
// among all the phases included in the workflow
myWorkflowRunner
.
SetDataInitializer
(
func
()
(
RunData
,
error
)
{
myWorkflowRunner
.
SetDataInitializer
(
func
(
cmd
*
cobra
.
Command
)
(
RunData
,
error
)
{
return
myWorkflowData
{
data
:
"some data"
},
nil
return
myWorkflowData
{
data
:
"some data"
},
nil
})
})
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner.go
View file @
a5f06fdd
...
@@ -53,13 +53,17 @@ type Runner struct {
...
@@ -53,13 +53,17 @@ type Runner struct {
// runDataInitializer defines a function that creates the runtime data shared
// runDataInitializer defines a function that creates the runtime data shared
// among all the phases included in the workflow
// among all the phases included in the workflow
runDataInitializer
func
()
(
RunData
,
error
)
runDataInitializer
func
(
*
cobra
.
Command
)
(
RunData
,
error
)
// runData is part of the internal state of the runner and it is used for implementing
// runData is part of the internal state of the runner and it is used for implementing
// a singleton in the InitData methods (thus avoiding to initialize data
// a singleton in the InitData methods (thus avoiding to initialize data
// more than one time)
// more than one time)
runData
RunData
runData
RunData
// runCmd is part of the internal state of the runner and it is used to track the
// command that will trigger the runner (only if the runner is BindToCommand).
runCmd
*
cobra
.
Command
// cmdAdditionalFlags holds additional, shared flags that could be added to the subcommands generated
// 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
// for phases. Flags could be inherited from the parent command too or added directly to each phase
cmdAdditionalFlags
*
pflag
.
FlagSet
cmdAdditionalFlags
*
pflag
.
FlagSet
...
@@ -166,7 +170,8 @@ func (e *Runner) computePhaseRunFlags() (map[string]bool, error) {
...
@@ -166,7 +170,8 @@ func (e *Runner) computePhaseRunFlags() (map[string]bool, error) {
// SetDataInitializer allows to setup a function that initialize the runtime data shared
// SetDataInitializer allows to setup a function that initialize the runtime data shared
// among all the phases included in the workflow.
// among all the phases included in the workflow.
func
(
e
*
Runner
)
SetDataInitializer
(
builder
func
()
(
RunData
,
error
))
{
// The method will receive in input the cmd that triggers the Runner (only if the runner is BindToCommand)
func
(
e
*
Runner
)
SetDataInitializer
(
builder
func
(
cmd
*
cobra
.
Command
)
(
RunData
,
error
))
{
e
.
runDataInitializer
=
builder
e
.
runDataInitializer
=
builder
}
}
...
@@ -176,7 +181,7 @@ func (e *Runner) SetDataInitializer(builder func() (RunData, error)) {
...
@@ -176,7 +181,7 @@ func (e *Runner) SetDataInitializer(builder func() (RunData, error)) {
func
(
e
*
Runner
)
InitData
()
(
RunData
,
error
)
{
func
(
e
*
Runner
)
InitData
()
(
RunData
,
error
)
{
if
e
.
runData
==
nil
&&
e
.
runDataInitializer
!=
nil
{
if
e
.
runData
==
nil
&&
e
.
runDataInitializer
!=
nil
{
var
err
error
var
err
error
if
e
.
runData
,
err
=
e
.
runDataInitializer
();
err
!=
nil
{
if
e
.
runData
,
err
=
e
.
runDataInitializer
(
e
.
runCmd
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
}
}
...
@@ -315,6 +320,8 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
...
@@ -315,6 +320,8 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
Example
:
p
.
Example
,
Example
:
p
.
Example
,
Aliases
:
p
.
Aliases
,
Aliases
:
p
.
Aliases
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// overrides the command triggering the Runner using the phaseCmd
e
.
runCmd
=
cmd
e
.
Options
.
FilterPhases
=
[]
string
{
p
.
generatedName
}
e
.
Options
.
FilterPhases
=
[]
string
{
p
.
generatedName
}
if
err
:=
e
.
Run
();
err
!=
nil
{
if
err
:=
e
.
Run
();
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
...
@@ -360,6 +367,9 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
...
@@ -360,6 +367,9 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
// adds phase related flags to the main command
// adds phase related flags to the main command
cmd
.
Flags
()
.
StringSliceVar
(
&
e
.
Options
.
SkipPhases
,
"skip-phases"
,
nil
,
"List of phases to be skipped"
)
cmd
.
Flags
()
.
StringSliceVar
(
&
e
.
Options
.
SkipPhases
,
"skip-phases"
,
nil
,
"List of phases to be skipped"
)
// keep tracks of the command triggering the runner
e
.
runCmd
=
cmd
}
}
func
inheritsFlags
(
sourceFlags
,
targetFlags
*
pflag
.
FlagSet
,
cmdFlags
[]
string
)
{
func
inheritsFlags
(
sourceFlags
,
targetFlags
*
pflag
.
FlagSet
,
cmdFlags
[]
string
)
{
...
...
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