func containerWithHostPorts(ports ...int) api.Container { c := api.Container{} for _, p := range ports { c.Ports = append(c.Ports, api.Port{HostPort: p}) } return c }
func fakeDeploymentConfig(name string, containers ...containerDesc) *deployapi.DeploymentConfig { specContainers := []kapi.Container{} for _, c := range containers { container := kapi.Container{ Name: c.name, } container.Ports = []kapi.ContainerPort{} for _, p := range c.ports { container.Ports = append(container.Ports, kapi.ContainerPort{ Name: fmt.Sprintf("port-%d-%s", p.port, p.protocol), ContainerPort: p.port, Protocol: kapi.Protocol(p.protocol), }) } specContainers = append(specContainers, container) } return &deployapi.DeploymentConfig{ ObjectMeta: kapi.ObjectMeta{ Name: name, }, Template: deployapi.DeploymentTemplate{ ControllerTemplate: kapi.ReplicationControllerSpec{ Replicas: 1, Selector: map[string]string{"name": "test"}, Template: &kapi.PodTemplateSpec{ Spec: kapi.PodSpec{ Containers: specContainers, }, }, }, }, } }
// ToAPIPod converts Pod to api.Pod. Note that if a field in api.Pod has no // corresponding field in Pod, the field would not be populated. func (p *Pod) ToAPIPod() *api.Pod { var pod api.Pod pod.UID = p.ID pod.Name = p.Name pod.Namespace = p.Namespace pod.Status = p.Status for _, c := range p.Containers { var container api.Container container.Name = c.Name container.Image = c.Image pod.Spec.Containers = append(pod.Spec.Containers, container) } return &pod }
// TODO(dchen1107): Move this along with other defaulting values func validatePullPolicyWithDefault(ctr *api.Container) errs.ValidationErrorList { allErrors := errs.ValidationErrorList{} // TODO(dchen1107): Move ParseImageName code to pkg/util if len(ctr.ImagePullPolicy) == 0 { parts := strings.Split(ctr.Image, ":") // Check image tag if parts[len(parts)-1] == "latest" { ctr.ImagePullPolicy = api.PullAlways } else { ctr.ImagePullPolicy = api.PullIfNotPresent } } if ctr.ImagePullPolicy != api.PullAlways && ctr.ImagePullPolicy != api.PullIfNotPresent && ctr.ImagePullPolicy != api.PullNever { allErrors = append(allErrors, errs.NewFieldNotSupported("", ctr.ImagePullPolicy)) } return allErrors }
func convert_v1beta3_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { defaulting.(func(*Container))(in) } out.Name = in.Name out.Image = in.Image if in.Command != nil { out.Command = make([]string, len(in.Command)) for i := range in.Command { out.Command[i] = in.Command[i] } } if in.Args != nil { out.Args = make([]string, len(in.Args)) for i := range in.Args { out.Args[i] = in.Args[i] } } out.WorkingDir = in.WorkingDir if in.Ports != nil { out.Ports = make([]api.ContainerPort, len(in.Ports)) for i := range in.Ports { if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil { return err } } } if in.Env != nil { out.Env = make([]api.EnvVar, len(in.Env)) for i := range in.Env { if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil { return err } } } if err := s.Convert(&in.Resources, &out.Resources, 0); err != nil { return err } if in.VolumeMounts != nil { out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts)) for i := range in.VolumeMounts { if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil { return err } } } if in.LivenessProbe != nil { out.LivenessProbe = new(api.Probe) if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil { return err } } else { out.LivenessProbe = nil } if in.ReadinessProbe != nil { out.ReadinessProbe = new(api.Probe) if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil { return err } } else { out.ReadinessProbe = nil } if in.Lifecycle != nil { out.Lifecycle = new(api.Lifecycle) if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil { return err } } else { out.Lifecycle = nil } out.TerminationMessagePath = in.TerminationMessagePath out.ImagePullPolicy = api.PullPolicy(in.ImagePullPolicy) if in.SecurityContext != nil { if in.SecurityContext.Capabilities != nil { if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) || !reflect.DeepEqual(in.SecurityContext.Capabilities.Drop, in.Capabilities.Drop) { return fmt.Errorf("container capability settings do not match security context settings, cannot convert") } } if in.SecurityContext.Privileged != nil { if in.Privileged != *in.SecurityContext.Privileged { return fmt.Errorf("container privileged settings do not match security context settings, cannot convert") } } } if in.SecurityContext != nil { out.SecurityContext = new(api.SecurityContext) if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil { return err } } else { out.SecurityContext = nil } return nil }