(workspace *dw.DevWorkspaceTemplateSpec, options Options, proxyConfig *controllerv1alpha1.Proxy)
| 86 | } |
| 87 | |
| 88 | func GetProjectCloneInitContainer(workspace *dw.DevWorkspaceTemplateSpec, options Options, proxyConfig *controllerv1alpha1.Proxy) (*corev1.Container, error) { |
| 89 | starterProject, err := GetStarterProject(workspace) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | if len(workspace.Projects) == 0 && len(workspace.DependentProjects) == 0 && starterProject == nil { |
| 94 | return nil, nil |
| 95 | } |
| 96 | if workspace.Attributes.GetString(constants.ProjectCloneAttribute, nil) == constants.ProjectCloneDisable { |
| 97 | return nil, nil |
| 98 | } |
| 99 | if !hasContainerComponents(workspace) { |
| 100 | // Avoid adding project-clone init container when DevWorkspace does not define any containers |
| 101 | return nil, nil |
| 102 | } |
| 103 | |
| 104 | var cloneImage string |
| 105 | if options.Image != "" { |
| 106 | cloneImage = options.Image |
| 107 | } else { |
| 108 | cloneImage = images.GetProjectCloneImage() |
| 109 | } |
| 110 | if cloneImage == "" { |
| 111 | // Assume project clone is intentionally disabled if project clone image is not defined |
| 112 | return nil, nil |
| 113 | } |
| 114 | |
| 115 | resources := dwResources.FilterResources(options.Resources) |
| 116 | if err := dwResources.ValidateResources(resources); err != nil { |
| 117 | return nil, fmt.Errorf("invalid resources for project clone container: %w", err) |
| 118 | } |
| 119 | |
| 120 | return &corev1.Container{ |
| 121 | Name: ProjectClonerContainerName, |
| 122 | Image: cloneImage, |
| 123 | Env: options.Env, |
| 124 | Resources: *resources, |
| 125 | VolumeMounts: []corev1.VolumeMount{ |
| 126 | { |
| 127 | Name: devfileConstants.ProjectsVolumeName, |
| 128 | MountPath: constants.DefaultProjectsSourcesRoot, |
| 129 | }, |
| 130 | }, |
| 131 | ImagePullPolicy: options.PullPolicy, |
| 132 | }, nil |
| 133 | } |
| 134 | |
| 135 | func GetStarterProject(workspace *dw.DevWorkspaceTemplateSpec) (*dw.StarterProject, error) { |
| 136 | if !workspace.Attributes.Exists(constants.StarterProjectAttribute) { |
no test coverage detected