mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-28 10:08:23 +00:00
Merge pull request #5502 from wojtek-t/completely_remove_bound_pods
Remove BoundPod type from source code
This commit is contained in:
@@ -84,20 +84,6 @@ func init() {
|
||||
return nil
|
||||
},
|
||||
|
||||
// Convert Pod to BoundPod
|
||||
func(in *Pod, out *BoundPod, s conversion.Scope) error {
|
||||
if err := s.Convert(&in.Spec, &out.Spec, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
// Only copy a subset of fields, and override manifest attributes with the pod
|
||||
// metadata
|
||||
out.UID = in.UID
|
||||
out.Name = in.Name
|
||||
out.Namespace = in.Namespace
|
||||
out.CreationTimestamp = in.CreationTimestamp
|
||||
return nil
|
||||
},
|
||||
|
||||
// Conversion between Manifest and PodSpec
|
||||
func(in *PodSpec, out *ContainerManifest, s conversion.Scope) error {
|
||||
if err := s.Convert(&in.Volumes, &out.Volumes, 0); err != nil {
|
||||
|
||||
@@ -43,7 +43,6 @@ func init() {
|
||||
&EventList{},
|
||||
&ContainerManifest{},
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&List{},
|
||||
&LimitRange{},
|
||||
&LimitRangeList{},
|
||||
@@ -77,7 +76,6 @@ func (*Event) IsAnAPIObject() {}
|
||||
func (*EventList) IsAnAPIObject() {}
|
||||
func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
func (*LimitRange) IsAnAPIObject() {}
|
||||
func (*LimitRangeList) IsAnAPIObject() {}
|
||||
|
||||
@@ -1270,19 +1270,6 @@ type ContainerManifestList struct {
|
||||
Items []ContainerManifest `json:"items"`
|
||||
}
|
||||
|
||||
// BoundPod is a collection of containers that should be run on a host. A BoundPod
|
||||
// defines how a Pod may change after a Binding is created. A Pod is a request to
|
||||
// execute a pod, whereas a BoundPod is the specification that would be run on a server.
|
||||
//
|
||||
// TODO(wojtek-t): Get rid of this type.
|
||||
type BoundPod struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
// Spec defines the behavior of a pod.
|
||||
Spec PodSpec `json:"spec,omitempty"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
@@ -448,18 +448,6 @@ func init() {
|
||||
return nil
|
||||
},
|
||||
|
||||
func(in *newer.PodSpec, out *BoundPod, s conversion.Scope) error {
|
||||
if err := s.Convert(&in, &out.Spec, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
func(in *BoundPod, out *newer.PodSpec, s conversion.Scope) error {
|
||||
if err := s.Convert(&in.Spec, &out, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
// Converts internal Container to v1beta1.Container.
|
||||
// Fields 'CPU' and 'Memory' are not present in the internal Container object.
|
||||
// Hence the need for a custom conversion function.
|
||||
|
||||
@@ -51,48 +51,6 @@ func TestSetDefaultService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulPodSpec(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Volumes = []current.Volume{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
if bp2.Spec.DNSPolicy != current.DNSClusterFirst {
|
||||
t.Errorf("Expected default dns policy :%s, got: %s", current.DNSClusterFirst, bp2.Spec.DNSPolicy)
|
||||
}
|
||||
policy := bp2.Spec.RestartPolicy
|
||||
if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil {
|
||||
t.Errorf("Expected only policy.Always is set, got: %s", policy)
|
||||
}
|
||||
vsource := bp2.Spec.Volumes[0].Source
|
||||
if vsource.EmptyDir == nil {
|
||||
t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultContainer(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Containers = []current.Container{{}}
|
||||
bp.Spec.Containers[0].Ports = []current.ContainerPort{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
|
||||
container := bp2.Spec.Containers[0]
|
||||
if container.TerminationMessagePath != current.TerminationMessagePathDefault {
|
||||
t.Errorf("Expected termination message path: %s, got: %s",
|
||||
current.TerminationMessagePathDefault, container.TerminationMessagePath)
|
||||
}
|
||||
if container.ImagePullPolicy != current.PullIfNotPresent {
|
||||
t.Errorf("Expected image pull policy: %s, got: %s",
|
||||
current.PullIfNotPresent, container.ImagePullPolicy)
|
||||
}
|
||||
if container.Ports[0].Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected protocol: %s, got: %s",
|
||||
current.ProtocolTCP, container.Ports[0].Protocol)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecret(t *testing.T) {
|
||||
s := ¤t.Secret{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
|
||||
@@ -50,8 +50,6 @@ func init() {
|
||||
&EventList{},
|
||||
&ContainerManifest{},
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&List{},
|
||||
&LimitRange{},
|
||||
&LimitRangeList{},
|
||||
@@ -85,8 +83,6 @@ func (*Event) IsAnAPIObject() {}
|
||||
func (*EventList) IsAnAPIObject() {}
|
||||
func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
func (*LimitRange) IsAnAPIObject() {}
|
||||
func (*LimitRangeList) IsAnAPIObject() {}
|
||||
|
||||
@@ -1060,28 +1060,6 @@ type PodSpec struct {
|
||||
Host string `json:"host,omitempty" description:"host requested for this pod"`
|
||||
}
|
||||
|
||||
// BoundPod is a collection of containers that should be run on a host. A BoundPod
|
||||
// defines how a Pod may change after a Binding is created. A Pod is a request to
|
||||
// execute a pod, whereas a BoundPod is the specification that would be run on a server.
|
||||
type BoundPod struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
// Spec defines the behavior of a pod.
|
||||
Spec PodSpec `json:"spec,omitempty" description:"specification of the desired state of containers and volumes comprising the pod"`
|
||||
}
|
||||
|
||||
// BoundPods is a list of Pods bound to a common server. The resource version of
|
||||
// the pod list is guaranteed to only change when the list of bound pods changes.
|
||||
type BoundPods struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
// Host is the name of a node that these pods were bound to.
|
||||
Host string `json:"host" description:"name of a node that these pods were bound to"`
|
||||
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []Pod `json:"items" description:"list of all pods bound to a given host"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
@@ -51,48 +51,6 @@ func TestSetDefaultService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulPodSpec(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Volumes = []current.Volume{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
if bp2.Spec.DNSPolicy != current.DNSClusterFirst {
|
||||
t.Errorf("Expected default dns policy :%s, got: %s", current.DNSClusterFirst, bp2.Spec.DNSPolicy)
|
||||
}
|
||||
policy := bp2.Spec.RestartPolicy
|
||||
if policy.Never != nil || policy.OnFailure != nil || policy.Always == nil {
|
||||
t.Errorf("Expected only policy.Always is set, got: %s", policy)
|
||||
}
|
||||
vsource := bp2.Spec.Volumes[0].Source
|
||||
if vsource.EmptyDir == nil {
|
||||
t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultContainer(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Containers = []current.Container{{}}
|
||||
bp.Spec.Containers[0].Ports = []current.ContainerPort{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
|
||||
container := bp2.Spec.Containers[0]
|
||||
if container.TerminationMessagePath != current.TerminationMessagePathDefault {
|
||||
t.Errorf("Expected termination message path: %s, got: %s",
|
||||
current.TerminationMessagePathDefault, container.TerminationMessagePath)
|
||||
}
|
||||
if container.ImagePullPolicy != current.PullIfNotPresent {
|
||||
t.Errorf("Expected image pull policy: %s, got: %s",
|
||||
current.PullIfNotPresent, container.ImagePullPolicy)
|
||||
}
|
||||
if container.Ports[0].Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected protocol: %s, got: %s",
|
||||
current.ProtocolTCP, container.Ports[0].Protocol)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecret(t *testing.T) {
|
||||
s := ¤t.Secret{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
|
||||
@@ -50,8 +50,6 @@ func init() {
|
||||
&EventList{},
|
||||
&ContainerManifest{},
|
||||
&ContainerManifestList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&List{},
|
||||
&LimitRange{},
|
||||
&LimitRangeList{},
|
||||
@@ -85,8 +83,6 @@ func (*Event) IsAnAPIObject() {}
|
||||
func (*EventList) IsAnAPIObject() {}
|
||||
func (*ContainerManifest) IsAnAPIObject() {}
|
||||
func (*ContainerManifestList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
func (*LimitRange) IsAnAPIObject() {}
|
||||
func (*LimitRangeList) IsAnAPIObject() {}
|
||||
|
||||
@@ -1065,7 +1065,7 @@ type EventList struct {
|
||||
// ContainerManifest corresponds to the Container Manifest format, documented at:
|
||||
// https://developers.google.com/compute/docs/containers/container_vms#container_manifest
|
||||
// This is used as the representation of Kubernetes workloads.
|
||||
// DEPRECATED: Replaced with BoundPod
|
||||
// DEPRECATED: Replaced with Pod
|
||||
type ContainerManifest struct {
|
||||
// Required: This must be a supported version string, such as "v1beta1".
|
||||
Version string `json:"version" description:"manifest version; must be v1beta1"`
|
||||
@@ -1084,7 +1084,7 @@ type ContainerManifest struct {
|
||||
}
|
||||
|
||||
// ContainerManifestList is used to communicate container manifests to kubelet.
|
||||
// DEPRECATED: Replaced with BoundPods
|
||||
// DEPRECATED: Replaced with PodList
|
||||
type ContainerManifestList struct {
|
||||
TypeMeta `json:",inline"`
|
||||
Items []ContainerManifest `json:"items" description:"list of pod container manifests"`
|
||||
@@ -1122,28 +1122,6 @@ type PodSpec struct {
|
||||
Host string `json:"host,omitempty" description:"host requested for this pod"`
|
||||
}
|
||||
|
||||
// BoundPod is a collection of containers that should be run on a host. A BoundPod
|
||||
// defines how a Pod may change after a Binding is created. A Pod is a request to
|
||||
// execute a pod, whereas a BoundPod is the specification that would be run on a server.
|
||||
type BoundPod struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
// Spec defines the behavior of a pod.
|
||||
Spec PodSpec `json:"spec,omitempty" description:"specification of the desired state of containers and volumes comprising the pod"`
|
||||
}
|
||||
|
||||
// BoundPods is a list of Pods bound to a common server. The resource version of
|
||||
// the pod list is guaranteed to only change when the list of bound pods changes.
|
||||
type BoundPods struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
// Host is the name of a node that these pods were bound to.
|
||||
Host string `json:"host" description:"name of a node that these pods were bound to"`
|
||||
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []Pod `json:"items" description:"list of all pods bound to a given host"`
|
||||
}
|
||||
|
||||
// List holds a list of objects, which may not be known by the server.
|
||||
type List struct {
|
||||
TypeMeta `json:",inline"`
|
||||
|
||||
@@ -52,48 +52,6 @@ func TestSetDefaultService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulPodSpec(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Volumes = []current.Volume{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
if bp2.Spec.DNSPolicy != current.DNSClusterFirst {
|
||||
t.Errorf("Expected default dns policy :%s, got: %s", current.DNSClusterFirst, bp2.Spec.DNSPolicy)
|
||||
}
|
||||
policy := bp2.Spec.RestartPolicy
|
||||
if policy != current.RestartPolicyAlways {
|
||||
t.Errorf("Expected only policy.Always is set, got: %s", policy)
|
||||
}
|
||||
vsource := bp2.Spec.Volumes[0].VolumeSource
|
||||
if vsource.EmptyDir == nil {
|
||||
t.Errorf("Expected non-empty volume is set, got: %s", vsource.EmptyDir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultContainer(t *testing.T) {
|
||||
bp := ¤t.BoundPod{}
|
||||
bp.Spec.Containers = []current.Container{{}}
|
||||
bp.Spec.Containers[0].Ports = []current.ContainerPort{{}}
|
||||
|
||||
obj2 := roundTrip(t, runtime.Object(bp))
|
||||
bp2 := obj2.(*current.BoundPod)
|
||||
|
||||
container := bp2.Spec.Containers[0]
|
||||
if container.TerminationMessagePath != current.TerminationMessagePathDefault {
|
||||
t.Errorf("Expected termination message path: %s, got: %s",
|
||||
current.TerminationMessagePathDefault, container.TerminationMessagePath)
|
||||
}
|
||||
if container.ImagePullPolicy != current.PullIfNotPresent {
|
||||
t.Errorf("Expected image pull policy: %s, got: %s",
|
||||
current.PullIfNotPresent, container.ImagePullPolicy)
|
||||
}
|
||||
if container.Ports[0].Protocol != current.ProtocolTCP {
|
||||
t.Errorf("Expected protocol: %s, got: %s",
|
||||
current.ProtocolTCP, container.Ports[0].Protocol)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecret(t *testing.T) {
|
||||
s := ¤t.Secret{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
|
||||
@@ -31,8 +31,6 @@ func init() {
|
||||
&PodStatusResult{},
|
||||
&PodTemplate{},
|
||||
&PodTemplateList{},
|
||||
&BoundPod{},
|
||||
&BoundPods{},
|
||||
&ReplicationController{},
|
||||
&ReplicationControllerList{},
|
||||
&Service{},
|
||||
@@ -66,8 +64,6 @@ func (*PodList) IsAnAPIObject() {}
|
||||
func (*PodStatusResult) IsAnAPIObject() {}
|
||||
func (*PodTemplate) IsAnAPIObject() {}
|
||||
func (*PodTemplateList) IsAnAPIObject() {}
|
||||
func (*BoundPod) IsAnAPIObject() {}
|
||||
func (*BoundPods) IsAnAPIObject() {}
|
||||
func (*ReplicationController) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerList) IsAnAPIObject() {}
|
||||
func (*Service) IsAnAPIObject() {}
|
||||
|
||||
@@ -597,8 +597,7 @@ type PodStatusResult struct {
|
||||
}
|
||||
|
||||
// Pod is a collection of containers that can run on a host. This resource is created
|
||||
// by clients and scheduled onto hosts. BoundPod represents the state of this resource
|
||||
// to hosts.
|
||||
// by clients and scheduled onto hosts.
|
||||
type Pod struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ObjectMeta `json:"metadata,omitempty" description:"standard object metadata; see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/api-conventions.md#metadata"`
|
||||
@@ -645,30 +644,6 @@ type PodTemplateList struct {
|
||||
Items []PodTemplate `json:"items" description:"list of pod templates"`
|
||||
}
|
||||
|
||||
// BoundPod is a collection of containers that should be run on a host. A BoundPod
|
||||
// defines how a Pod may change after a Binding is created. A Pod is a request to
|
||||
// execute a pod, whereas a BoundPod is the specification that would be run on a server.
|
||||
type BoundPod struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ObjectMeta `json:"metadata,omitempty" description:"standard object metadata; see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/api-conventions.md#metadata"`
|
||||
|
||||
// Spec defines the behavior of a pod.
|
||||
Spec PodSpec `json:"spec,omitempty" description:"specification of the desired behavior of the pod; https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/api-conventions.md#spec-and-status"`
|
||||
}
|
||||
|
||||
// BoundPods is a list of Pods bound to a common server. The resource version of
|
||||
// the pod list is guaranteed to only change when the list of bound pods changes.
|
||||
type BoundPods struct {
|
||||
TypeMeta `json:",inline"`
|
||||
ObjectMeta `json:"metadata,omitempty" description:"standard object metadata; see https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/api-conventions.md#metadata"`
|
||||
|
||||
// Host is the name of a node that these pods were bound to.
|
||||
Host string `json:"host" description:"name of a node that these pods were bound to"`
|
||||
|
||||
// Items is the list of all pods bound to a given host.
|
||||
Items []Pod `json:"items" description:"list of all pods bound to a given host"`
|
||||
}
|
||||
|
||||
// ReplicationControllerSpec is the specification of a replication controller.
|
||||
type ReplicationControllerSpec struct {
|
||||
// Replicas is the number of desired replicas.
|
||||
|
||||
@@ -813,26 +813,6 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ValidationErrorL
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidateBoundPod tests if required fields on a bound pod are set.
|
||||
// TODO: to be removed.
|
||||
func ValidateBoundPod(pod *api.BoundPod) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
if len(pod.Name) == 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("name", pod.Name))
|
||||
} else {
|
||||
if ok, qualifier := nameIsDNSSubdomain(pod.Name, false); !ok {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("name", pod.Name, qualifier))
|
||||
}
|
||||
}
|
||||
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, dnsSubdomainErrorMsg))
|
||||
}
|
||||
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidateMinion tests if required fields in the node are set.
|
||||
func ValidateMinion(node *api.Node) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
|
||||
@@ -1027,98 +1027,6 @@ func TestValidatePodUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBoundPods(t *testing.T) {
|
||||
successCases := []api.BoundPod{
|
||||
{ // Mostly empty.
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
{ // Basic fields.
|
||||
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
|
||||
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
{ // Just about everything.
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc.123.do-re-mi", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
Volumes: []api.Volume{
|
||||
{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
|
||||
},
|
||||
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
RestartPolicy: 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{
|
||||
"zero-length name": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
"bad namespace": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: ""},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
"bad spec": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{{Name: "name", ImagePullPolicy: "IfNotPresent"}},
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
"name > 253 characters": {
|
||||
ObjectMeta: api.ObjectMeta{Name: strings.Repeat("a", 254), Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
"name not a DNS subdomain": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "a..b.c", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
"name with underscore": {
|
||||
ObjectMeta: api.ObjectMeta{Name: "a_b_c", Namespace: "ns"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, v := range errorCases {
|
||||
if errs := ValidatePod(&v); len(errs) != 1 {
|
||||
t.Errorf("expected one failure for %s; got %d: %s", k, len(errs), errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateService(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestAddOrUpdateEventNoExisting(t *testing.T) {
|
||||
Reason: "my reasons are many",
|
||||
Message: "my message is love",
|
||||
InvolvedObject: api.ObjectReference{
|
||||
Kind: "BoundPod",
|
||||
Kind: "Pod",
|
||||
Name: "awesome.name",
|
||||
Namespace: "betterNamespace",
|
||||
UID: "C934D34AFB20242",
|
||||
@@ -143,7 +143,7 @@ func TestGetEventExisting(t *testing.T) {
|
||||
Reason: "do I exist",
|
||||
Message: "I do, oh my",
|
||||
InvolvedObject: api.ObjectReference{
|
||||
Kind: "BoundPod",
|
||||
Kind: "Pod",
|
||||
Name: "clever.name.here",
|
||||
Namespace: "spaceOfName",
|
||||
UID: "D933D32AFB2A238",
|
||||
|
||||
@@ -224,7 +224,7 @@ func (d *PodDescriber) Describe(namespace, name string) (string, error) {
|
||||
if ref, err := api.GetReference(pod); err != nil {
|
||||
glog.Errorf("Unable to construct reference to '%#v': %v", pod, err)
|
||||
} else {
|
||||
ref.Kind = "" // Find BoundPod objects, too!
|
||||
ref.Kind = ""
|
||||
events, _ = d.Events(namespace).Search(ref)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user