mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Factor out API defaulting from validation logic
Currently, the validation logic validates fields in an object and supply default values wherever applies. This change factors out defaulting to a set of defaulting callback functions for decoding (see #1502 for more discussion). * This change is based on pull request 2587. * Most defaulting has been migrated to defaults.go where the defaulting functions are added. * validation_test.go and converter_test.go have been adapted to not testing the default values. * Fixed all tests with that create invalid objects with the absence of defaulting logic.
This commit is contained in:
@@ -62,7 +62,6 @@ func ExampleManifestAndPod(id string) (v1beta1.ContainerManifest, api.BoundPod)
|
||||
{
|
||||
Name: "c" + id,
|
||||
Image: "foo",
|
||||
TerminationMessagePath: "/somepath",
|
||||
},
|
||||
},
|
||||
Volumes: []api.Volume{
|
||||
@@ -94,7 +93,7 @@ func TestUpdateOnNonExistentFile(t *testing.T) {
|
||||
case got := <-ch:
|
||||
update := got.(kubelet.PodUpdate)
|
||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource)
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
|
||||
@@ -137,15 +136,7 @@ func TestReadFromFile(t *testing.T) {
|
||||
Namespace: "",
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "test/image",
|
||||
TerminationMessagePath: "/dev/termination-log",
|
||||
ImagePullPolicy: api.PullAlways,
|
||||
},
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
})
|
||||
|
||||
// There's no way to provide namespace in ContainerManifest, so
|
||||
@@ -161,7 +152,7 @@ func TestReadFromFile(t *testing.T) {
|
||||
}
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
|
||||
@@ -191,15 +182,7 @@ func TestReadFromFileWithoutID(t *testing.T) {
|
||||
Namespace: "",
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "test/image",
|
||||
TerminationMessagePath: "/dev/termination-log",
|
||||
ImagePullPolicy: api.PullAlways,
|
||||
},
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
})
|
||||
|
||||
if len(update.Pods[0].ObjectMeta.Name) == 0 {
|
||||
@@ -209,7 +192,7 @@ func TestReadFromFileWithoutID(t *testing.T) {
|
||||
update.Pods[0].ObjectMeta.Namespace = ""
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
|
||||
@@ -240,21 +223,13 @@ func TestReadV1Beta2FromFile(t *testing.T) {
|
||||
Namespace: "",
|
||||
SelfLink: "",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "test/image",
|
||||
TerminationMessagePath: "/dev/termination-log",
|
||||
ImagePullPolicy: api.PullAlways,
|
||||
},
|
||||
},
|
||||
},
|
||||
Spec: api.PodSpec{Containers: []api.Container{{Image: "test/image"}}},
|
||||
})
|
||||
|
||||
update.Pods[0].ObjectMeta.Namespace = ""
|
||||
update.Pods[0].ObjectMeta.SelfLink = ""
|
||||
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
|
||||
@@ -315,7 +290,7 @@ func TestExtractFromEmptyDir(t *testing.T) {
|
||||
|
||||
update := (<-ch).(kubelet.PodUpdate)
|
||||
expected := CreatePodUpdate(kubelet.SET, kubelet.FileSource)
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Errorf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
}
|
||||
@@ -371,7 +346,7 @@ func TestExtractFromDir(t *testing.T) {
|
||||
}
|
||||
sort.Sort(sortedPods(update.Pods))
|
||||
sort.Sort(sortedPods(expected.Pods))
|
||||
if !api.Semantic.DeepEqual(expected, update) {
|
||||
if !api.Semantic.DeepDerivative(expected, update) {
|
||||
t.Fatalf("Expected %#v, Got %#v", expected, update)
|
||||
}
|
||||
for i := range update.Pods {
|
||||
|
||||
Reference in New Issue
Block a user