func podSpec(containerImages ...string) kapi.PodSpec { spec := kapi.PodSpec{ Containers: []kapi.Container{}, } for _, image := range containerImages { container := kapi.Container{ Image: image, } spec.Containers = append(spec.Containers, container) } return spec }
// DeploymentConfig creates a deploymentConfig resource from the deployment configuration reference // // TODO: take a pod template spec as argument func (r *DeploymentConfigRef) DeploymentConfig() (*deployapi.DeploymentConfig, error) { if len(r.Name) == 0 { suggestions := NameSuggestions{} for i := range r.Images { suggestions = append(suggestions, r.Images[i]) } name, ok := suggestions.SuggestName() if !ok { return nil, fmt.Errorf("unable to suggest a name for this DeploymentConfig") } r.Name = name } selector := map[string]string{ "deploymentconfig": r.Name, } triggers := []deployapi.DeploymentTriggerPolicy{ // By default, always deploy on change { Type: deployapi.DeploymentTriggerOnConfigChange, }, } template := kapi.PodSpec{} for i := range r.Images { c, containerTriggers, err := r.Images[i].DeployableContainer() if err != nil { return nil, err } triggers = append(triggers, containerTriggers...) template.Containers = append(template.Containers, *c) } // Create EmptyDir volumes for all container volume mounts for _, c := range template.Containers { for _, v := range c.VolumeMounts { template.Volumes = append(template.Volumes, kapi.Volume{ Name: v.Name, VolumeSource: kapi.VolumeSource{ EmptyDir: &kapi.EmptyDirVolumeSource{Medium: kapi.StorageMediumDefault}, }, }) } } for i := range template.Containers { template.Containers[i].Env = append(template.Containers[i].Env, r.Env.List()...) } return &deployapi.DeploymentConfig{ ObjectMeta: kapi.ObjectMeta{ Name: r.Name, }, Template: deployapi.DeploymentTemplate{ ControllerTemplate: kapi.ReplicationControllerSpec{ Replicas: 1, Selector: selector, Template: &kapi.PodTemplateSpec{ ObjectMeta: kapi.ObjectMeta{ Labels: selector, }, Spec: template, }, }, }, Triggers: triggers, }, nil }
func convert_v1_PodSpec_To_api_PodSpec(in *PodSpec, out *api.PodSpec, s conversion.Scope) error { if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found { defaulting.(func(*PodSpec))(in) } if in.Volumes != nil { out.Volumes = make([]api.Volume, len(in.Volumes)) for i := range in.Volumes { if err := convert_v1_Volume_To_api_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil { return err } } } else { out.Volumes = nil } if in.Containers != nil { out.Containers = make([]api.Container, len(in.Containers)) for i := range in.Containers { if err := convert_v1_Container_To_api_Container(&in.Containers[i], &out.Containers[i], s); err != nil { return err } } } else { out.Containers = nil } out.RestartPolicy = api.RestartPolicy(in.RestartPolicy) if in.TerminationGracePeriodSeconds != nil { out.TerminationGracePeriodSeconds = new(int64) *out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds } else { out.TerminationGracePeriodSeconds = nil } if in.ActiveDeadlineSeconds != nil { out.ActiveDeadlineSeconds = new(int64) *out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds } else { out.ActiveDeadlineSeconds = nil } out.DNSPolicy = api.DNSPolicy(in.DNSPolicy) if in.NodeSelector != nil { out.NodeSelector = make(map[string]string) for key, val := range in.NodeSelector { out.NodeSelector[key] = val } } else { out.NodeSelector = nil } // We support DeprecatedServiceAccount as an alias for ServiceAccountName. // If both are specified, ServiceAccountName (the new field) wins. out.ServiceAccountName = in.ServiceAccountName if in.ServiceAccountName == "" { out.ServiceAccountName = in.DeprecatedServiceAccount } out.NodeName = in.NodeName // carry conversion if in.NodeName == "" { out.NodeName = in.DeprecatedHost } out.HostNetwork = in.HostNetwork if in.ImagePullSecrets != nil { out.ImagePullSecrets = make([]api.LocalObjectReference, len(in.ImagePullSecrets)) for i := range in.ImagePullSecrets { if err := convert_v1_LocalObjectReference_To_api_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil { return err } } } else { out.ImagePullSecrets = nil } return nil }
// DeploymentConfig creates a deploymentConfig resource from the deployment configuration reference // // TODO: take a pod template spec as argument func (r *DeploymentConfigRef) DeploymentConfig() (*deployapi.DeploymentConfig, error) { if len(r.Name) == 0 { suggestions := NameSuggestions{} for i := range r.Images { suggestions = append(suggestions, r.Images[i]) } name, ok := suggestions.SuggestName() if !ok { return nil, fmt.Errorf("unable to suggest a name for this DeploymentConfig") } r.Name = name } selector := map[string]string{ "deploymentconfig": r.Name, } triggers := []deployapi.DeploymentTriggerPolicy{ // By default, always deploy on change { Type: deployapi.DeploymentTriggerOnConfigChange, }, } template := kapi.PodSpec{} for i := range r.Images { c, containerTriggers, err := r.Images[i].DeployableContainer() if err != nil { return nil, err } triggers = append(triggers, containerTriggers...) template.Containers = append(template.Containers, *c) } // TODO: populate volumes for i := range template.Containers { template.Containers[i].Env = append(template.Containers[i].Env, r.Env.List()...) } return &deployapi.DeploymentConfig{ ObjectMeta: kapi.ObjectMeta{ Name: r.Name, }, Template: deployapi.DeploymentTemplate{ Strategy: deployapi.DeploymentStrategy{ Type: deployapi.DeploymentStrategyTypeRecreate, }, ControllerTemplate: kapi.ReplicationControllerSpec{ Replicas: 1, Selector: selector, Template: &kapi.PodTemplateSpec{ ObjectMeta: kapi.ObjectMeta{ Labels: selector, }, Spec: template, }, }, }, Triggers: triggers, }, nil }