Add update to the pod etcd handler.

This commit is contained in:
Brendan Burns
2014-10-09 20:30:34 -07:00
parent b3292e947f
commit 4380637be7
4 changed files with 380 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package validation
import (
"reflect"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@@ -338,6 +339,30 @@ func ValidatePod(pod *api.Pod) errs.ErrorList {
return allErrs
}
// ValidatePodUpdate tests to see if the update is legal
func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ErrorList {
allErrs := errs.ErrorList{}
if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) {
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
return allErrs
}
pod := *newPod
pod.Labels = oldPod.Labels
pod.TypeMeta.ResourceVersion = oldPod.TypeMeta.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
newContainers = append(newContainers, container)
}
pod.DesiredState.Manifest.Containers = newContainers
if !reflect.DeepEqual(&pod, oldPod) {
allErrs = append(allErrs, errs.NewFieldInvalid("DesiredState.Manifest.Containers", newPod.DesiredState.Manifest.Containers))
}
return allErrs
}
// ValidateService tests if required fields in the service are set.
func ValidateService(service *api.Service) errs.ErrorList {
allErrs := errs.ErrorList{}