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
3c865e45
Commit
3c865e45
authored
Jun 03, 2016
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove an empty line being output when exposing annotations and
labels via downward api volume
parent
d93ebd0e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
30 deletions
+25
-30
fieldpath.go
pkg/fieldpath/fieldpath.go
+5
-3
fieldpath_test.go
pkg/fieldpath/fieldpath_test.go
+3
-3
downwardapi_test.go
pkg/volume/downwardapi/downwardapi_test.go
+17
-24
No files found.
pkg/fieldpath/fieldpath.go
View file @
3c865e45
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"fmt"
"fmt"
"math"
"math"
"strconv"
"strconv"
"strings"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
...
@@ -27,10 +28,11 @@ import (
...
@@ -27,10 +28,11 @@ import (
)
)
// formatMap formats map[string]string to a string.
// formatMap formats map[string]string to a string.
func
f
ormatMap
(
m
map
[
string
]
string
)
(
fmtStr
string
)
{
func
F
ormatMap
(
m
map
[
string
]
string
)
(
fmtStr
string
)
{
for
key
,
value
:=
range
m
{
for
key
,
value
:=
range
m
{
fmtStr
+=
fmt
.
Sprintf
(
"%v=%q
\n
"
,
key
,
value
)
fmtStr
+=
fmt
.
Sprintf
(
"%v=%q
\n
"
,
key
,
value
)
}
}
fmtStr
=
strings
.
TrimSuffix
(
fmtStr
,
"
\n
"
)
return
return
}
}
...
@@ -51,9 +53,9 @@ func ExtractFieldPathAsString(obj interface{}, fieldPath string) (string, error)
...
@@ -51,9 +53,9 @@ func ExtractFieldPathAsString(obj interface{}, fieldPath string) (string, error)
switch
fieldPath
{
switch
fieldPath
{
case
"metadata.annotations"
:
case
"metadata.annotations"
:
return
f
ormatMap
(
accessor
.
GetAnnotations
()),
nil
return
F
ormatMap
(
accessor
.
GetAnnotations
()),
nil
case
"metadata.labels"
:
case
"metadata.labels"
:
return
f
ormatMap
(
accessor
.
GetLabels
()),
nil
return
F
ormatMap
(
accessor
.
GetLabels
()),
nil
case
"metadata.name"
:
case
"metadata.name"
:
return
accessor
.
GetName
(),
nil
return
accessor
.
GetName
(),
nil
case
"metadata.namespace"
:
case
"metadata.namespace"
:
...
...
pkg/fieldpath/fieldpath_test.go
View file @
3c865e45
...
@@ -65,7 +65,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
...
@@ -65,7 +65,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
Labels
:
map
[
string
]
string
{
"key"
:
"value"
},
Labels
:
map
[
string
]
string
{
"key"
:
"value"
},
},
},
},
},
expectedValue
:
"key=
\"
value
\"
\n
"
,
expectedValue
:
"key=
\"
value
\"
"
,
},
},
{
{
name
:
"ok - labels bslash n"
,
name
:
"ok - labels bslash n"
,
...
@@ -75,7 +75,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
...
@@ -75,7 +75,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
Labels
:
map
[
string
]
string
{
"key"
:
"value
\n
"
},
Labels
:
map
[
string
]
string
{
"key"
:
"value
\n
"
},
},
},
},
},
expectedValue
:
"key=
\"
value
\\
n
\"
\n
"
,
expectedValue
:
"key=
\"
value
\\
n
\"
"
,
},
},
{
{
name
:
"ok - annotations"
,
name
:
"ok - annotations"
,
...
@@ -85,7 +85,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
...
@@ -85,7 +85,7 @@ func TestExtractFieldPathAsString(t *testing.T) {
Annotations
:
map
[
string
]
string
{
"builder"
:
"john-doe"
},
Annotations
:
map
[
string
]
string
{
"builder"
:
"john-doe"
},
},
},
},
},
expectedValue
:
"builder=
\"
john-doe
\"
\n
"
,
expectedValue
:
"builder=
\"
john-doe
\"
"
,
},
},
{
{
...
...
pkg/volume/downwardapi/downwardapi_test.go
View file @
3c865e45
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/fieldpath"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/types"
utiltesting
"k8s.io/kubernetes/pkg/util/testing"
utiltesting
"k8s.io/kubernetes/pkg/util/testing"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume"
...
@@ -35,14 +36,6 @@ import (
...
@@ -35,14 +36,6 @@ import (
const
downwardAPIDir
=
"..data"
const
downwardAPIDir
=
"..data"
func
formatMap
(
m
map
[
string
]
string
)
(
fmtstr
string
)
{
for
key
,
value
:=
range
m
{
fmtstr
+=
fmt
.
Sprintf
(
"%v=%q
\n
"
,
key
,
value
)
}
return
}
func
newTestHost
(
t
*
testing
.
T
,
clientset
clientset
.
Interface
)
(
string
,
volume
.
VolumeHost
)
{
func
newTestHost
(
t
*
testing
.
T
,
clientset
clientset
.
Interface
)
(
string
,
volume
.
VolumeHost
)
{
tempDir
,
err
:=
utiltesting
.
MkTmpdir
(
"downwardApi_volume_test."
)
tempDir
,
err
:=
utiltesting
.
MkTmpdir
(
"downwardApi_volume_test."
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -155,8 +148,8 @@ func TestLabels(t *testing.T) {
...
@@ -155,8 +148,8 @@ func TestLabels(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
labels
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
...
@@ -222,8 +215,8 @@ func TestAnnotations(t *testing.T) {
...
@@ -222,8 +215,8 @@ func TestAnnotations(t *testing.T) {
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
annotations
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
annotations
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
annotations
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
annotations
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
...
@@ -433,8 +426,8 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
...
@@ -433,8 +426,8 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
labels
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
...
@@ -503,8 +496,8 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
...
@@ -503,8 +496,8 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
labels
))
}
}
newLabels
:=
map
[
string
]
string
{
newLabels
:=
map
[
string
]
string
{
...
@@ -534,8 +527,8 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
...
@@ -534,8 +527,8 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
newLabels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
newLabels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
newLabels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
newLabels
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
}
}
...
@@ -606,16 +599,16 @@ func TestWriteWithUnixPath(t *testing.T) {
...
@@ -606,16 +599,16 @@ func TestWriteWithUnixPath(t *testing.T) {
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
labels
))
}
}
data
,
err
=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
"this/is/yours/annotations"
))
data
,
err
=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
"this/is/yours/annotations"
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
annotations
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
annotations
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
annotations
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
annotations
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
}
}
...
@@ -687,7 +680,7 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
...
@@ -687,7 +680,7 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
f
ieldpath
.
F
ormatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
f
ieldpath
.
F
ormatMap
(
labels
))
}
}
}
}
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