mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Pod Templates
This commit is contained in:
@@ -80,6 +80,10 @@ func TestRESTMapper(t *testing.T) {
|
||||
t.Errorf("unexpected version mapping: %s %s %v", v, k, err)
|
||||
}
|
||||
|
||||
if m, err := RESTMapper.RESTMapping("PodTemplate", ""); err != nil || m.APIVersion != "v1beta3" || m.Resource != "podtemplates" {
|
||||
t.Errorf("unexpected version mapping: %#v %v", m, err)
|
||||
}
|
||||
|
||||
for _, version := range Versions {
|
||||
mapping, err := RESTMapper.RESTMapping("ReplicationController", version)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,6 +28,8 @@ func init() {
|
||||
&Pod{},
|
||||
&PodList{},
|
||||
&PodStatusResult{},
|
||||
&PodTemplate{},
|
||||
&PodTemplateList{},
|
||||
&ReplicationControllerList{},
|
||||
&ReplicationController{},
|
||||
&ServiceList{},
|
||||
@@ -71,6 +73,8 @@ func init() {
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
func (*PodList) IsAnAPIObject() {}
|
||||
func (*PodStatusResult) IsAnAPIObject() {}
|
||||
func (*PodTemplate) IsAnAPIObject() {}
|
||||
func (*PodTemplateList) IsAnAPIObject() {}
|
||||
func (*ReplicationController) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerList) IsAnAPIObject() {}
|
||||
func (*Service) IsAnAPIObject() {}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (t *Tester) TestCreateRejectsMismatchedNamespace(valid runtime.Object) {
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, but we didn't get one")
|
||||
} else if strings.Contains(err.Error(), "Controller.Namespace does not match the provided context") {
|
||||
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,30 @@ func (t *Tester) TestCreateRejectsNamespace(valid runtime.Object) {
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, but we didn't get one")
|
||||
} else if strings.Contains(err.Error(), "Controller.Namespace does not match the provided context") {
|
||||
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err.Error())
|
||||
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tester) TestUpdate(valid runtime.Object, existing, older runtime.Object) {
|
||||
t.TestUpdateFailsOnNotFound(copyOrDie(valid))
|
||||
t.TestUpdateFailsOnVersion(copyOrDie(older))
|
||||
}
|
||||
|
||||
func (t *Tester) TestUpdateFailsOnNotFound(valid runtime.Object) {
|
||||
_, _, err := t.storage.(rest.Updater).Update(api.NewDefaultContext(), valid)
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, but we didn't get one")
|
||||
} else if !errors.IsNotFound(err) {
|
||||
t.Errorf("Expected NotFound error, got '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tester) TestUpdateFailsOnVersion(older runtime.Object) {
|
||||
_, _, err := t.storage.(rest.Updater).Update(api.NewDefaultContext(), older)
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, but we didn't get one")
|
||||
} else if !errors.IsConflict(err) {
|
||||
t.Errorf("Expected Conflict error, got '%v'", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,13 +85,20 @@ func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
|
||||
}
|
||||
|
||||
// roundTripSame verifies the same source object is tested in all API versions.
|
||||
func roundTripSame(t *testing.T, item runtime.Object) {
|
||||
func roundTripSame(t *testing.T, item runtime.Object, except ...string) {
|
||||
set := util.NewStringSet(except...)
|
||||
seed := rand.Int63()
|
||||
fuzzInternalObject(t, "", item, seed)
|
||||
roundTrip(t, v1beta1.Codec, item)
|
||||
roundTrip(t, v1beta2.Codec, item)
|
||||
fuzzInternalObject(t, "v1beta3", item, seed)
|
||||
roundTrip(t, v1beta3.Codec, item)
|
||||
if !set.Has("v1beta1") {
|
||||
roundTrip(t, v1beta1.Codec, item)
|
||||
}
|
||||
if !set.Has("v1beta2") {
|
||||
roundTrip(t, v1beta2.Codec, item)
|
||||
}
|
||||
if !set.Has("v1beta3") {
|
||||
fuzzInternalObject(t, "v1beta3", item, seed)
|
||||
roundTrip(t, v1beta3.Codec, item)
|
||||
}
|
||||
}
|
||||
|
||||
func roundTripAll(t *testing.T, item runtime.Object) {
|
||||
@@ -130,6 +137,10 @@ func TestList(t *testing.T) {
|
||||
|
||||
var nonRoundTrippableTypes = util.NewStringSet("ContainerManifest", "ContainerManifestList")
|
||||
var nonInternalRoundTrippableTypes = util.NewStringSet("List", "ListOptions", "PodExecOptions")
|
||||
var nonRoundTrippableTypesByVersion = map[string][]string{
|
||||
"PodTemplate": {"v1beta1", "v1beta2"},
|
||||
"PodTemplateList": {"v1beta1", "v1beta2"},
|
||||
}
|
||||
|
||||
func TestRoundTripTypes(t *testing.T) {
|
||||
// api.Scheme.Log(t)
|
||||
@@ -148,7 +159,7 @@ func TestRoundTripTypes(t *testing.T) {
|
||||
if _, err := meta.TypeAccessor(item); err != nil {
|
||||
t.Fatalf("%q is not a TypeMeta and cannot be tested - add it to nonRoundTrippableTypes: %v", kind, err)
|
||||
}
|
||||
roundTripSame(t, item)
|
||||
roundTripSame(t, item, nonRoundTrippableTypesByVersion[kind]...)
|
||||
if !nonInternalRoundTrippableTypes.Has(kind) {
|
||||
roundTrip(t, api.Codec, fuzzInternalObject(t, "", item, rand.Int63()))
|
||||
}
|
||||
|
||||
@@ -888,6 +888,24 @@ func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) errs.ValidationErrorList {
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidatePodTemplate tests if required fields in the pod template are set.
|
||||
func ValidatePodTemplate(pod *api.PodTemplate) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, ValidateObjectMeta(&pod.ObjectMeta, true, ValidatePodName).Prefix("metadata")...)
|
||||
allErrs = append(allErrs, ValidatePodTemplateSpec(&pod.Spec, 0).Prefix("spec")...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidatePodTemplateUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
|
||||
// that cannot be changed.
|
||||
func ValidatePodTemplateUpdate(newPod, oldPod *api.PodTemplate) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
|
||||
allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldPod.ObjectMeta, &newPod.ObjectMeta).Prefix("metadata")...)
|
||||
allErrs = append(allErrs, ValidatePodTemplateSpec(&newPod.Spec, 0).Prefix("spec")...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
var supportedSessionAffinityType = util.NewStringSet(string(api.AffinityTypeClientIP), string(api.AffinityTypeNone))
|
||||
|
||||
// ValidateService tests if required fields in the service are set.
|
||||
|
||||
Reference in New Issue
Block a user