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
b56e0ece
Commit
b56e0ece
authored
Jan 06, 2015
by
Satnam Singh
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3241 from thockin/dns_for_files
Enable DNS for pods from files
parents
ee2f63a8
1ec3457f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
181 additions
and
60 deletions
+181
-60
conversion.go
pkg/api/conversion.go
+4
-0
validation.go
pkg/api/validation/validation.go
+17
-18
validation_test.go
pkg/api/validation/validation_test.go
+158
-42
config_test.go
pkg/kubelet/config/config_test.go
+1
-0
http_test.go
pkg/kubelet/config/http_test.go
+1
-0
No files found.
pkg/api/conversion.go
View file @
b56e0ece
...
@@ -32,6 +32,7 @@ func init() {
...
@@ -32,6 +32,7 @@ func init() {
out
.
Spec
.
Containers
=
in
.
Containers
out
.
Spec
.
Containers
=
in
.
Containers
out
.
Spec
.
Volumes
=
in
.
Volumes
out
.
Spec
.
Volumes
=
in
.
Volumes
out
.
Spec
.
RestartPolicy
=
in
.
RestartPolicy
out
.
Spec
.
RestartPolicy
=
in
.
RestartPolicy
out
.
Spec
.
DNSPolicy
=
in
.
DNSPolicy
out
.
Name
=
in
.
ID
out
.
Name
=
in
.
ID
out
.
UID
=
in
.
UUID
out
.
UID
=
in
.
UUID
// TODO(dchen1107): Move this conversion to pkg/api/v1beta[123]/conversion.go
// TODO(dchen1107): Move this conversion to pkg/api/v1beta[123]/conversion.go
...
@@ -48,6 +49,7 @@ func init() {
...
@@ -48,6 +49,7 @@ func init() {
out
.
Containers
=
in
.
Spec
.
Containers
out
.
Containers
=
in
.
Spec
.
Containers
out
.
Volumes
=
in
.
Spec
.
Volumes
out
.
Volumes
=
in
.
Spec
.
Volumes
out
.
RestartPolicy
=
in
.
Spec
.
RestartPolicy
out
.
RestartPolicy
=
in
.
Spec
.
RestartPolicy
out
.
DNSPolicy
=
in
.
Spec
.
DNSPolicy
out
.
Version
=
"v1beta2"
out
.
Version
=
"v1beta2"
out
.
ID
=
in
.
Name
out
.
ID
=
in
.
Name
out
.
UUID
=
in
.
UID
out
.
UUID
=
in
.
UID
...
@@ -104,6 +106,7 @@ func init() {
...
@@ -104,6 +106,7 @@ func init() {
if
err
:=
s
.
Convert
(
&
in
.
RestartPolicy
,
&
out
.
RestartPolicy
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
RestartPolicy
,
&
out
.
RestartPolicy
,
0
);
err
!=
nil
{
return
err
return
err
}
}
out
.
DNSPolicy
=
in
.
DNSPolicy
out
.
Version
=
"v1beta2"
out
.
Version
=
"v1beta2"
return
nil
return
nil
},
},
...
@@ -117,6 +120,7 @@ func init() {
...
@@ -117,6 +120,7 @@ func init() {
if
err
:=
s
.
Convert
(
&
in
.
RestartPolicy
,
&
out
.
RestartPolicy
,
0
);
err
!=
nil
{
if
err
:=
s
.
Convert
(
&
in
.
RestartPolicy
,
&
out
.
RestartPolicy
,
0
);
err
!=
nil
{
return
err
return
err
}
}
out
.
DNSPolicy
=
in
.
DNSPolicy
return
nil
return
nil
},
},
)
)
...
...
pkg/api/validation/validation.go
View file @
b56e0ece
...
@@ -370,8 +370,12 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
...
@@ -370,8 +370,12 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
if
len
(
pod
.
Name
)
==
0
{
if
len
(
pod
.
Name
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
pod
.
Name
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
pod
.
Name
))
}
else
if
!
util
.
IsDNSSubdomain
(
pod
.
Name
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"name"
,
pod
.
Name
,
""
))
}
}
if
!
util
.
IsDNSSubdomain
(
pod
.
Namespace
)
{
if
len
(
pod
.
Namespace
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"namespace"
,
pod
.
Namespace
))
}
else
if
!
util
.
IsDNSSubdomain
(
pod
.
Namespace
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
}
}
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
pod
.
Spec
)
.
Prefix
(
"spec"
)
...
)
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
pod
.
Spec
)
.
Prefix
(
"spec"
)
...
)
...
@@ -549,25 +553,20 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorL
...
@@ -549,25 +553,20 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorL
}
}
// ValidateBoundPod tests if required fields on a bound pod are set.
// ValidateBoundPod tests if required fields on a bound pod are set.
func
ValidateBoundPod
(
pod
*
api
.
BoundPod
)
(
errors
[]
error
)
{
func
ValidateBoundPod
(
pod
*
api
.
BoundPod
)
errs
.
ValidationErrorList
{
if
!
util
.
IsDNSSubdomain
(
pod
.
Name
)
{
allErrs
:=
errs
.
ValidationErrorList
{}
errors
=
append
(
errors
,
errs
.
NewFieldInvalid
(
"name"
,
pod
.
Name
,
""
))
if
len
(
pod
.
Name
)
==
0
{
}
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"name"
,
pod
.
Name
))
if
!
util
.
IsDNSSubdomain
(
pod
.
Namespace
)
{
}
else
if
!
util
.
IsDNSSubdomain
(
pod
.
Name
)
{
errors
=
append
(
errors
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"name"
,
pod
.
Name
,
""
))
}
containerManifest
:=
&
api
.
ContainerManifest
{
Version
:
"v1beta2"
,
ID
:
pod
.
Name
,
UUID
:
pod
.
UID
,
Containers
:
pod
.
Spec
.
Containers
,
Volumes
:
pod
.
Spec
.
Volumes
,
RestartPolicy
:
pod
.
Spec
.
RestartPolicy
,
}
}
if
errs
:=
ValidateManifest
(
containerManifest
);
len
(
errs
)
!=
0
{
if
len
(
pod
.
Name
)
==
0
{
errors
=
append
(
errors
,
errs
...
)
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"namespace"
,
pod
.
Namespace
))
}
else
if
!
util
.
IsDNSSubdomain
(
pod
.
Namespace
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"namespace"
,
pod
.
Namespace
,
""
))
}
}
return
errors
allErrs
=
append
(
allErrs
,
ValidatePodSpec
(
&
pod
.
Spec
)
.
Prefix
(
"spec"
)
...
)
return
allErrs
}
}
// ValidateMinion tests if required fields in the minion are set.
// ValidateMinion tests if required fields in the minion are set.
...
...
pkg/api/validation/validation_test.go
View file @
b56e0ece
...
@@ -338,7 +338,22 @@ func TestValidateRestartPolicy(t *testing.T) {
...
@@ -338,7 +338,22 @@ func TestValidateRestartPolicy(t *testing.T) {
if
noPolicySpecified
.
Always
==
nil
{
if
noPolicySpecified
.
Always
==
nil
{
t
.
Errorf
(
"expected Always policy specified"
)
t
.
Errorf
(
"expected Always policy specified"
)
}
}
}
func
TestValidateDNSPolicy
(
t
*
testing
.
T
)
{
successCases
:=
[]
api
.
DNSPolicy
{
api
.
DNSClusterFirst
,
api
.
DNSDefault
,
api
.
DNSPolicy
(
""
)}
for
_
,
policy
:=
range
successCases
{
if
errs
:=
validateDNSPolicy
(
&
policy
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
errorCases
:=
[]
api
.
DNSPolicy
{
api
.
DNSPolicy
(
"invalid"
)}
for
_
,
policy
:=
range
errorCases
{
if
errs
:=
validateDNSPolicy
(
&
policy
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %v"
,
policy
)
}
}
}
}
func
TestValidateManifest
(
t
*
testing
.
T
)
{
func
TestValidateManifest
(
t
*
testing
.
T
)
{
...
@@ -404,59 +419,109 @@ func TestValidateManifest(t *testing.T) {
...
@@ -404,59 +419,109 @@ func TestValidateManifest(t *testing.T) {
}
}
}
}
func
TestValidatePod
(
t
*
testing
.
T
)
{
func
TestValidatePodSpec
(
t
*
testing
.
T
)
{
errs
:=
ValidatePod
(
&
api
.
Pod
{
successCases
:=
[]
api
.
PodSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
{},
// empty is valid, if not very useful */
Name
:
"foo"
,
Namespace
:
api
.
NamespaceDefault
,
{
// Populate basic fields, leave defaults for most.
Labels
:
map
[
string
]
string
{
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
"foo"
:
"bar"
,
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
},
},
Spec
:
api
.
PodSpec
{
{
// Populate all fields.
RestartPolicy
:
api
.
RestartPolicy
{
Volumes
:
[]
api
.
Volume
{
Always
:
&
api
.
RestartPolicyAlways
{
},
{
Name
:
"vol"
},
},
},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
DNSPolicy
:
api
.
DNSClusterFirst
,
NodeSelector
:
map
[
string
]
string
{
"key"
:
"value"
,
},
Host
:
"foobar"
,
},
},
})
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"Unexpected non-zero error list: %#v"
,
errs
)
}
}
errs
=
ValidatePod
(
&
api
.
Pod
{
for
i
:=
range
successCases
{
ObjectMeta
:
api
.
ObjectMeta
{
if
errs
:=
ValidatePodSpec
(
&
successCases
[
i
]);
len
(
errs
)
!=
0
{
Name
:
"foo"
,
t
.
Errorf
(
"expected success: %v"
,
errs
)
Namespace
:
api
.
NamespaceDefault
,
}
Labels
:
map
[
string
]
string
{
}
"foo"
:
"bar"
,
},
failureCases
:=
map
[
string
]
api
.
PodSpec
{
"bad volume"
:
{
Volumes
:
[]
api
.
Volume
{{}},
},
"bad container"
:
{
Containers
:
[]
api
.
Container
{{}},
},
"bad DNS policy"
:
{
DNSPolicy
:
api
.
DNSPolicy
(
"invalid"
),
},
},
Spec
:
api
.
PodSpec
{},
}
})
for
k
,
v
:=
range
failureCases
{
if
len
(
errs
)
!=
0
{
if
errs
:=
ValidatePodSpec
(
&
v
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"Unexpected non-zero error list: %#v"
,
errs
)
t
.
Errorf
(
"expected failure for %q"
,
k
)
}
}
}
errs
=
ValidatePodSpec
(
&
api
.
PodSpec
{
defaultPod
:=
api
.
PodSpec
{}
// all empty fields
RestartPolicy
:
api
.
RestartPolicy
{
if
errs
:=
ValidatePodSpec
(
&
defaultPod
);
len
(
errs
)
!=
0
{
Always
:
&
api
.
RestartPolicyAlways
{},
t
.
Errorf
(
"expected success: %v"
,
errs
)
Never
:
&
api
.
RestartPolicyNever
{},
}
if
util
.
AllPtrFieldsNil
(
defaultPod
.
RestartPolicy
)
{
t
.
Errorf
(
"expected a default RestartPolicy"
)
}
if
defaultPod
.
DNSPolicy
==
""
{
t
.
Errorf
(
"expected a default DNSPolicy"
)
}
}
func
TestValidatePod
(
t
*
testing
.
T
)
{
successCases
:=
[]
api
.
Pod
{
{
// Mostly empty.
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"ns"
},
},
},
})
{
// Basic fields.
if
len
(
errs
)
!=
1
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
t
.
Errorf
(
"Unexpected error list: %#v"
,
errs
)
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
},
{
// Just about everything.
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc.123.do-re-mi"
,
Namespace
:
"ns"
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
Name
:
"vol"
},
},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
DNSPolicy
:
api
.
DNSClusterFirst
,
NodeSelector
:
map
[
string
]
string
{
"key"
:
"value"
,
},
Host
:
"foobar"
,
},
},
}
for
_
,
pod
:=
range
successCases
{
if
errs
:=
ValidatePod
(
&
pod
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
}
errs
=
ValidatePod
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
errorCases
:=
map
[
string
]
api
.
Pod
{
Name
:
"foo"
,
"bad name"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
Namespace
:
"ns"
}},
Namespace
:
api
.
NamespaceDefault
,
"bad namespace"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
""
}},
Labels
:
map
[
string
]
string
{
"bad spec"
:
{
"1/2/3/4/5"
:
"bar"
,
// invalid
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"ns"
},
"valid"
:
"bar"
,
// good
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{}},
},
},
},
},
Spec
:
api
.
PodSpec
{},
}
})
for
k
,
v
:=
range
errorCases
{
if
len
(
errs
)
!=
1
{
if
errs
:=
ValidatePod
(
&
v
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"Unexpected error list: %#v"
,
errs
)
t
.
Errorf
(
"expected failure for %s"
,
k
)
}
}
}
}
}
...
@@ -623,6 +688,57 @@ func TestValidatePodUpdate(t *testing.T) {
...
@@ -623,6 +688,57 @@ func TestValidatePodUpdate(t *testing.T) {
}
}
}
}
func
TestValidateBoundPods
(
t
*
testing
.
T
)
{
successCases
:=
[]
api
.
BoundPod
{
{
// Mostly empty.
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"ns"
},
},
{
// Basic fields.
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
},
{
// Just about everything.
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc.123.do-re-mi"
,
Namespace
:
"ns"
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{
{
Name
:
"vol"
},
},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
DNSPolicy
:
api
.
DNSClusterFirst
,
NodeSelector
:
map
[
string
]
string
{
"key"
:
"value"
,
},
Host
:
"foobar"
,
},
},
}
for
_
,
pod
:=
range
successCases
{
if
errs
:=
ValidateBoundPod
(
&
pod
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
errorCases
:=
map
[
string
]
api
.
Pod
{
"bad name"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
""
,
Namespace
:
"ns"
}},
"bad namespace"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
""
}},
"bad spec"
:
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"abc"
,
Namespace
:
"ns"
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{}},
},
},
}
for
k
,
v
:=
range
errorCases
{
if
errs
:=
ValidatePod
(
&
v
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %s"
,
k
)
}
}
}
func
TestValidateService
(
t
*
testing
.
T
)
{
func
TestValidateService
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
name
string
...
...
pkg/kubelet/config/config_test.go
View file @
b56e0ece
...
@@ -59,6 +59,7 @@ func CreateValidPod(name, namespace, source string) api.BoundPod {
...
@@ -59,6 +59,7 @@ func CreateValidPod(name, namespace, source string) api.BoundPod {
},
},
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
DNSPolicy
:
api
.
DNSClusterFirst
,
},
},
}
}
}
}
...
...
pkg/kubelet/config/http_test.go
View file @
b56e0ece
...
@@ -132,6 +132,7 @@ func TestExtractFromHTTP(t *testing.T) {
...
@@ -132,6 +132,7 @@ func TestExtractFromHTTP(t *testing.T) {
},
},
Spec
:
api
.
PodSpec
{
Spec
:
api
.
PodSpec
{
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
RestartPolicy
:
api
.
RestartPolicy
{
Always
:
&
api
.
RestartPolicyAlways
{}},
DNSPolicy
:
api
.
DNSClusterFirst
,
},
},
}),
}),
},
},
...
...
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