mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 12:48:51 +00:00
v1beta3 Pod refactor
This commit is contained in:
@@ -345,7 +345,7 @@ func ValidatePod(pod *api.Pod) errs.ValidationErrorList {
|
||||
if !util.IsDNSSubdomain(pod.Namespace) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace))
|
||||
}
|
||||
allErrs = append(allErrs, ValidatePodState(&pod.DesiredState).Prefix("desiredState")...)
|
||||
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
|
||||
allErrs = append(allErrs, validateLabels(pod.Labels)...)
|
||||
return allErrs
|
||||
}
|
||||
@@ -383,8 +383,8 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("name", newPod.Name))
|
||||
}
|
||||
|
||||
if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
|
||||
if len(newPod.Spec.Containers) != len(oldPod.Spec.Containers) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
|
||||
return allErrs
|
||||
}
|
||||
pod := *newPod
|
||||
@@ -392,13 +392,13 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
|
||||
pod.ResourceVersion = oldPod.ResourceVersion
|
||||
// Tricky, we need to copy the container list so that we don't overwrite the update
|
||||
var newContainers []api.Container
|
||||
for ix, container := range pod.DesiredState.Manifest.Containers {
|
||||
container.Image = oldPod.DesiredState.Manifest.Containers[ix].Image
|
||||
for ix, container := range pod.Spec.Containers {
|
||||
container.Image = oldPod.Spec.Containers[ix].Image
|
||||
newContainers = append(newContainers, container)
|
||||
}
|
||||
pod.DesiredState.Manifest.Containers = newContainers
|
||||
if !reflect.DeepEqual(pod.DesiredState.Manifest, oldPod.DesiredState.Manifest) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
|
||||
pod.Spec.Containers = newContainers
|
||||
if !reflect.DeepEqual(pod.Spec, oldPod.Spec) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("spec.containers", newPod.Spec.Containers))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
@@ -374,13 +374,9 @@ func TestValidatePod(t *testing.T) {
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Version: "v1beta1",
|
||||
ID: "abc",
|
||||
RestartPolicy: api.RestartPolicy{
|
||||
Always: &api.RestartPolicyAlways{},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicy{
|
||||
Always: &api.RestartPolicyAlways{},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -395,28 +391,16 @@ func TestValidatePod(t *testing.T) {
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{Version: "v1beta1", ID: "abc"},
|
||||
},
|
||||
Spec: api.PodSpec{},
|
||||
})
|
||||
if len(errs) != 0 {
|
||||
t.Errorf("Unexpected non-zero error list: %#v", errs)
|
||||
}
|
||||
|
||||
errs = ValidatePod(&api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo", Namespace: api.NamespaceDefault,
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Version: "v1beta1",
|
||||
ID: "abc",
|
||||
RestartPolicy: api.RestartPolicy{Always: &api.RestartPolicyAlways{},
|
||||
Never: &api.RestartPolicyNever{}},
|
||||
},
|
||||
errs = ValidatePodSpec(&api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicy{
|
||||
Always: &api.RestartPolicyAlways{},
|
||||
Never: &api.RestartPolicyNever{},
|
||||
},
|
||||
})
|
||||
if len(errs) != 1 {
|
||||
@@ -436,9 +420,7 @@ func TestValidatePod(t *testing.T) {
|
||||
"rfc952-24chars-orless": "bar", //good label
|
||||
},
|
||||
},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{Version: "v1beta1", ID: "abc"},
|
||||
},
|
||||
Spec: api.PodSpec{},
|
||||
})
|
||||
if len(errs) != 5 {
|
||||
t.Errorf("Unexpected non-zero error list: %#v", errs)
|
||||
@@ -488,27 +470,23 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
},
|
||||
{
|
||||
Image: "bar:V2",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
},
|
||||
{
|
||||
Image: "bar:V2",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -519,24 +497,20 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
{
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -547,26 +521,22 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
{
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
CPU: 100,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
CPU: 100,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
CPU: 1000,
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
CPU: 1000,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -577,14 +547,12 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
{
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
Ports: []api.Port{
|
||||
{HostPort: 8080, ContainerPort: 80},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V1",
|
||||
Ports: []api.Port{
|
||||
{HostPort: 8080, ContainerPort: 80},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -592,14 +560,12 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
},
|
||||
api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: "foo"},
|
||||
DesiredState: api.PodState{
|
||||
Manifest: api.ContainerManifest{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
Ports: []api.Port{
|
||||
{HostPort: 8000, ContainerPort: 80},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Image: "foo:V2",
|
||||
Ports: []api.Port{
|
||||
{HostPort: 8000, ContainerPort: 80},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user