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
807338e9
Commit
807338e9
authored
Nov 15, 2018
by
fabriziopandini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix validateMixedArgs for phases
parent
4fdac196
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 @
807338e9
...
...
@@ -178,7 +178,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
// sets the data builder function, that will be used by the runner
// 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
)
})
...
...
cmd/kubeadm/app/cmd/phases/workflow/doc_test.go
View file @
807338e9
...
...
@@ -19,6 +19,8 @@ package workflow
import
(
"errors"
"fmt"
"github.com/spf13/cobra"
)
var
myWorkflowRunner
=
NewRunner
()
...
...
@@ -100,7 +102,7 @@ func ExampleRunner_Run() {
// Defines the method that creates the runtime data shared
// 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
})
...
...
cmd/kubeadm/app/cmd/phases/workflow/runner.go
View file @
807338e9
...
...
@@ -53,13 +53,17 @@ type Runner struct {
// runDataInitializer defines a function that creates the runtime data shared
// 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
// a singleton in the InitData methods (thus avoiding to initialize data
// more than one time)
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
// for phases. Flags could be inherited from the parent command too or added directly to each phase
cmdAdditionalFlags
*
pflag
.
FlagSet
...
...
@@ -166,7 +170,8 @@ func (e *Runner) computePhaseRunFlags() (map[string]bool, error) {
// SetDataInitializer allows to setup a function that initialize the runtime data shared
// 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
}
...
...
@@ -176,7 +181,7 @@ func (e *Runner) SetDataInitializer(builder func() (RunData, error)) {
func
(
e
*
Runner
)
InitData
()
(
RunData
,
error
)
{
if
e
.
runData
==
nil
&&
e
.
runDataInitializer
!=
nil
{
var
err
error
if
e
.
runData
,
err
=
e
.
runDataInitializer
();
err
!=
nil
{
if
e
.
runData
,
err
=
e
.
runDataInitializer
(
e
.
runCmd
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -315,6 +320,8 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
Example
:
p
.
Example
,
Aliases
:
p
.
Aliases
,
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
}
if
err
:=
e
.
Run
();
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
...
...
@@ -360,6 +367,9 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
// adds phase related flags to the main command
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
)
{
...
...
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