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
4d922682
Commit
4d922682
authored
Nov 02, 2015
by
Janet Kuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better error handling for output format when "kubectl config view"
parent
f64f2a73
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
19 deletions
+38
-19
view.go
pkg/kubectl/cmd/config/view.go
+9
-2
parser.go
pkg/util/jsonpath/parser.go
+5
-1
parser_test.go
pkg/util/jsonpath/parser_test.go
+24
-16
No files found.
pkg/kubectl/cmd/config/view.go
View file @
4d922682
...
...
@@ -18,6 +18,7 @@ package config
import
(
"errors"
"fmt"
"io"
"github.com/golang/glog"
...
...
@@ -52,6 +53,8 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2
func
NewCmdConfigView
(
out
io
.
Writer
,
ConfigAccess
ConfigAccess
)
*
cobra
.
Command
{
options
:=
&
ViewOptions
{
ConfigAccess
:
ConfigAccess
}
// Default to yaml
defaultOutputFormat
:=
"yaml"
cmd
:=
&
cobra
.
Command
{
Use
:
"view"
,
...
...
@@ -60,6 +63,11 @@ func NewCmdConfigView(out io.Writer, ConfigAccess ConfigAccess) *cobra.Command {
Example
:
view_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
options
.
Complete
()
outputFormat
:=
cmdutil
.
GetFlagString
(
cmd
,
"output"
)
if
outputFormat
==
"wide"
{
fmt
.
Printf
(
"--output wide is not available in kubectl config view; reset to default output format (%s)
\n\n
"
,
defaultOutputFormat
)
cmd
.
Flags
()
.
Set
(
"output"
,
defaultOutputFormat
)
}
printer
,
_
,
err
:=
cmdutil
.
PrinterForCommand
(
cmd
)
if
err
!=
nil
{
...
...
@@ -76,8 +84,7 @@ func NewCmdConfigView(out io.Writer, ConfigAccess ConfigAccess) *cobra.Command {
}
cmdutil
.
AddPrinterFlags
(
cmd
)
// Default to yaml
cmd
.
Flags
()
.
Set
(
"output"
,
"yaml"
)
cmd
.
Flags
()
.
Set
(
"output"
,
defaultOutputFormat
)
options
.
Merge
.
Default
(
true
)
cmd
.
Flags
()
.
Var
(
&
options
.
Merge
,
"merge"
,
"merge together the full hierarchy of kubeconfig files"
)
...
...
pkg/util/jsonpath/parser.go
View file @
4d922682
...
...
@@ -63,8 +63,12 @@ func NewParser(name string) *Parser {
// parseAction parsed the expression inside delimiter
func
parseAction
(
name
,
text
string
)
(
*
Parser
,
error
)
{
p
,
err
:=
Parse
(
name
,
fmt
.
Sprintf
(
"%s%s%s"
,
leftDelim
,
text
,
rightDelim
))
// when error happens, p will be nil, so we need to return here
if
err
!=
nil
{
return
p
,
err
}
p
.
Root
=
p
.
Root
.
Nodes
[
0
]
.
(
*
ListNode
)
return
p
,
err
return
p
,
nil
}
func
(
p
*
Parser
)
Parse
(
text
string
)
error
{
...
...
pkg/util/jsonpath/parser_test.go
View file @
4d922682
...
...
@@ -21,44 +21,46 @@ import (
)
type
parserTest
struct
{
name
string
text
string
nodes
[]
Node
name
string
text
string
nodes
[]
Node
shouldError
bool
}
var
parserTests
=
[]
parserTest
{
{
"plain"
,
`hello jsonpath`
,
[]
Node
{
newText
(
"hello jsonpath"
)}},
{
"plain"
,
`hello jsonpath`
,
[]
Node
{
newText
(
"hello jsonpath"
)}
,
false
},
{
"variable"
,
`hello {.jsonpath}`
,
[]
Node
{
newText
(
"hello "
),
newList
(),
newField
(
"jsonpath"
)}},
[]
Node
{
newText
(
"hello "
),
newList
(),
newField
(
"jsonpath"
)}
,
false
},
{
"arrayfiled"
,
`hello {['jsonpath']}`
,
[]
Node
{
newText
(
"hello "
),
newList
(),
newField
(
"jsonpath"
)}},
{
"quote"
,
`{"{"}`
,
[]
Node
{
newList
(),
newText
(
"{"
)}},
[]
Node
{
newText
(
"hello "
),
newList
(),
newField
(
"jsonpath"
)}
,
false
},
{
"quote"
,
`{"{"}`
,
[]
Node
{
newList
(),
newText
(
"{"
)}
,
false
},
{
"array"
,
`{[1:3]}`
,
[]
Node
{
newList
(),
newArray
([
3
]
ParamsEntry
{{
1
,
true
},
{
3
,
true
},
{
0
,
false
}})}},
newArray
([
3
]
ParamsEntry
{{
1
,
true
},
{
3
,
true
},
{
0
,
false
}})}
,
false
},
{
"allarray"
,
`{.book[*].author}`
,
[]
Node
{
newList
(),
newField
(
"book"
),
newArray
([
3
]
ParamsEntry
{{
0
,
false
},
{
0
,
false
},
{
0
,
false
}}),
newField
(
"author"
)}},
newArray
([
3
]
ParamsEntry
{{
0
,
false
},
{
0
,
false
},
{
0
,
false
}}),
newField
(
"author"
)}
,
false
},
{
"wildcard"
,
`{.bicycle.*}`
,
[]
Node
{
newList
(),
newField
(
"bicycle"
),
newWildcard
()}},
[]
Node
{
newList
(),
newField
(
"bicycle"
),
newWildcard
()}
,
false
},
{
"filter"
,
`{[?(@.price<3)]}`
,
[]
Node
{
newList
(),
newFilter
(
newList
(),
newList
(),
"<"
),
newList
(),
newField
(
"price"
),
newList
(),
newInt
(
3
)}},
{
"recursive"
,
`{..}`
,
[]
Node
{
newList
(),
newRecursive
()}},
newList
(),
newField
(
"price"
),
newList
(),
newInt
(
3
)}
,
false
},
{
"recursive"
,
`{..}`
,
[]
Node
{
newList
(),
newRecursive
()}
,
false
},
{
"recurField"
,
`{..price}`
,
[]
Node
{
newList
(),
newRecursive
(),
newField
(
"price"
)}},
[]
Node
{
newList
(),
newRecursive
(),
newField
(
"price"
)}
,
false
},
{
"arraydict"
,
`{['book.price']}`
,
[]
Node
{
newList
(),
newField
(
"book"
),
newField
(
"price"
),
}},
}
,
false
},
{
"union"
,
`{['bicycle.price', 3, 'book.price']}`
,
[]
Node
{
newList
(),
newUnion
([]
*
ListNode
{}),
newList
(),
newField
(
"bicycle"
),
newField
(
"price"
),
newList
(),
newArray
([
3
]
ParamsEntry
{{
3
,
true
},
{
4
,
true
},
{
0
,
false
}}),
newList
(),
newField
(
"book"
),
newField
(
"price"
),
}},
}
,
false
},
{
"range"
,
`{range .items}{.name},{end}`
,
[]
Node
{
newList
(),
newIdentifier
(
"range"
),
newField
(
"items"
),
newList
(),
newField
(
"name"
),
newText
(
","
),
newList
(),
newIdentifier
(
"end"
),
}},
},
false
},
{
"malformat input"
,
`{\\\}`
,
[]
Node
{},
true
},
}
func
collectNode
(
nodes
[]
Node
,
cur
Node
)
[]
Node
{
...
...
@@ -82,6 +84,12 @@ func collectNode(nodes []Node, cur Node) []Node {
func
TestParser
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
parserTests
{
parser
,
err
:=
Parse
(
test
.
name
,
test
.
text
)
if
test
.
shouldError
{
if
err
==
nil
{
t
.
Errorf
(
"unexpected non-error when parsing %s"
,
test
.
name
)
}
continue
}
if
err
!=
nil
{
t
.
Errorf
(
"parse %s error %v"
,
test
.
name
,
err
)
}
...
...
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