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
d4969ff0
Unverified
Commit
d4969ff0
authored
May 11, 2016
by
Ed Robinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows Secret & ConfigMap Keys to look like Environment Variables
This makes environment variable style keys (uppercase with underscores) valid in Secrets and ConfigMap.
parent
897d2770
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
10 deletions
+22
-10
validation_test.go
pkg/api/validation/validation_test.go
+2
-2
etcd_test.go
pkg/registry/configmap/etcd/etcd_test.go
+1
-1
validation.go
pkg/util/validation/validation.go
+11
-4
validation_test.go
pkg/util/validation/validation_test.go
+8
-3
No files found.
pkg/api/validation/validation_test.go
View file @
d4969ff0
...
...
@@ -5695,7 +5695,7 @@ func TestValidateSecret(t *testing.T) {
overMaxSize
.
Data
=
map
[
string
][]
byte
{
"over"
:
make
([]
byte
,
api
.
MaxSecretSize
+
1
),
}
invalidKey
.
Data
[
"a
..
b"
]
=
[]
byte
(
"whoops"
)
invalidKey
.
Data
[
"a
*
b"
]
=
[]
byte
(
"whoops"
)
leadingDotKey
.
Data
[
".key"
]
=
[]
byte
(
"bar"
)
dotKey
.
Data
[
"."
]
=
[]
byte
(
"bar"
)
doubleDotKey
.
Data
[
".."
]
=
[]
byte
(
"bar"
)
...
...
@@ -6300,7 +6300,7 @@ func TestValidateConfigMap(t *testing.T) {
invalidName
=
newConfigMap
(
"NoUppercaseOrSpecialCharsLike=Equals"
,
"validns"
,
nil
)
emptyNs
=
newConfigMap
(
"validname"
,
""
,
nil
)
invalidNs
=
newConfigMap
(
"validname"
,
"NoUppercaseOrSpecialCharsLike=Equals"
,
nil
)
invalidKey
=
newConfigMap
(
"validname"
,
"validns"
,
map
[
string
]
string
{
"a
..
b"
:
"value"
})
invalidKey
=
newConfigMap
(
"validname"
,
"validns"
,
map
[
string
]
string
{
"a
*
b"
:
"value"
})
leadingDotKey
=
newConfigMap
(
"validname"
,
"validns"
,
map
[
string
]
string
{
".ab"
:
"value"
})
dotKey
=
newConfigMap
(
"validname"
,
"validns"
,
map
[
string
]
string
{
"."
:
"value"
})
doubleDotKey
=
newConfigMap
(
"validname"
,
"validns"
,
map
[
string
]
string
{
".."
:
"value"
})
...
...
pkg/registry/configmap/etcd/etcd_test.go
View file @
d4969ff0
...
...
@@ -93,7 +93,7 @@ func TestUpdate(t *testing.T) {
// invalid updateFunc
func
(
obj
runtime
.
Object
)
runtime
.
Object
{
cfg
:=
obj
.
(
*
api
.
ConfigMap
)
cfg
.
Data
[
"badKey"
]
=
"value"
cfg
.
Data
[
"bad
*
Key"
]
=
"value"
return
cfg
},
)
...
...
pkg/util/validation/validation.go
View file @
d4969ff0
...
...
@@ -247,19 +247,26 @@ func IsHTTPHeaderName(value string) []string {
return
nil
}
const
configMapKeyFmt
=
"
\\
.?"
+
dns1123SubdomainFmt
const
configMapKeyFmt
=
`[-._a-zA-Z0-9]+`
var
configMapKeyRegexp
=
regexp
.
MustCompile
(
"^"
+
configMapKeyFmt
+
"$"
)
// IsConfigMapKey tests for a string that conforms to the definition of a
// subdomain in DNS (RFC 1123), except that a leading dot is allowed
// IsConfigMapKey tests for a string that is a valid key for a ConfigMap or Secret
func
IsConfigMapKey
(
value
string
)
[]
string
{
var
errs
[]
string
if
len
(
value
)
>
DNS1123SubdomainMaxLength
{
errs
=
append
(
errs
,
MaxLenError
(
DNS1123SubdomainMaxLength
))
}
if
!
configMapKeyRegexp
.
MatchString
(
value
)
{
errs
=
append
(
errs
,
RegexError
(
configMapKeyFmt
,
"key.name"
))
errs
=
append
(
errs
,
RegexError
(
configMapKeyFmt
,
"key.name"
,
"KEY_NAME"
,
"key-name"
))
}
if
value
==
"."
{
errs
=
append
(
errs
,
`must not be '.'`
)
}
if
value
==
".."
{
errs
=
append
(
errs
,
`must not be '..'`
)
}
else
if
strings
.
HasPrefix
(
value
,
".."
)
{
errs
=
append
(
errs
,
`must not start with '..'`
)
}
return
errs
}
...
...
pkg/util/validation/validation_test.go
View file @
d4969ff0
...
...
@@ -377,11 +377,14 @@ func TestIsValidPercent(t *testing.T) {
func
TestIsConfigMapKey
(
t
*
testing
.
T
)
{
successCases
:=
[]
string
{
"a"
,
"good"
,
"good-good"
,
"still.good"
,
"this.is.also.good"
,
".so.is.this"
,
"THIS_IS_GOOD"
,
"so_is_this_17"
,
}
for
i
:=
range
successCases
{
...
...
@@ -391,14 +394,16 @@ func TestIsConfigMapKey(t *testing.T) {
}
failureCases
:=
[]
string
{
"bad_bad"
,
"."
,
".."
,
"..bad"
,
"bad."
,
"b*d"
,
"bad!&bad"
,
}
for
i
:=
range
failureCases
{
if
errs
:=
IsConfigMapKey
(
failureCases
[
i
]);
len
(
errs
)
==
0
{
t
.
Errorf
(
"[%d] expected
success
"
,
i
)
t
.
Errorf
(
"[%d] expected
failure
"
,
i
)
}
}
}
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