| 126 | } |
| 127 | |
| 128 | func validateContainer(c kube.Container) error { |
| 129 | validMeta := kube.ObjectMeta{ |
| 130 | Name: "valid", |
| 131 | Namespace: "object", |
| 132 | } |
| 133 | |
| 134 | pod := kube.Pod{ |
| 135 | ObjectMeta: validMeta, |
| 136 | Spec: kube.PodSpec{ |
| 137 | Containers: []kube.Container{c}, |
| 138 | RestartPolicy: kube.RestartPolicyAlways, |
| 139 | DNSPolicy: kube.DNSClusterFirst, |
| 140 | }, |
| 141 | } |
| 142 | |
| 143 | // fake volumes to allow validation |
| 144 | for _, mount := range c.VolumeMounts { |
| 145 | volume := kube.Volume{ |
| 146 | Name: mount.Name, |
| 147 | VolumeSource: kube.VolumeSource{EmptyDir: &kube.EmptyDirVolumeSource{}}, |
| 148 | } |
| 149 | pod.Spec.Volumes = append(pod.Spec.Volumes, volume) |
| 150 | } |
| 151 | |
| 152 | errList := validation.ValidatePod(&pod) |
| 153 | |
| 154 | // Remove error for missing image field |
| 155 | return errList.Filter(func(e error) bool { |
| 156 | return e.Error() == NoImageErrStr |
| 157 | }).ToAggregate() |
| 158 | } |
| 159 | |
| 160 | var ( |
| 161 | // ErrMissingImage is where the Container is being used in a context where it must be valid and doesn't have an Image. |