MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / ValidateAllProjects

Function ValidateAllProjects

pkg/library/projects/clone.go:46–86  ·  view source on GitHub ↗

ValidateAllProjectsvalidates that no two projects, dependentProjects or starterProjects (if one is selected) share the same name or cloned path

(workspace *dw.DevWorkspaceTemplateSpec)

Source from the content-addressed store, hash-verified

44// ValidateAllProjectsvalidates that no two projects, dependentProjects or starterProjects (if one is selected) share
45// the same name or cloned path
46func ValidateAllProjects(workspace *dw.DevWorkspaceTemplateSpec) error {
47 // Map of project names to project sources (project, dependentProject, starterProject)
48 projectNames := map[string][]string{}
49 // Map of project clone paths to project sources ("project <name>", "starterProject <name>", "dependentProject <name>")
50 clonePaths := map[string][]string{}
51
52 for idx, project := range workspace.Projects {
53 projectNames[project.Name] = append(projectNames[project.Name], "projects")
54 clonePath := GetClonePath(&workspace.Projects[idx])
55 clonePaths[clonePath] = append(clonePaths[clonePath], fmt.Sprintf("project %s", project.Name))
56 }
57
58 for idx, project := range workspace.DependentProjects {
59 projectNames[project.Name] = append(projectNames[project.Name], "dependentProjects")
60 clonePath := GetClonePath(&workspace.DependentProjects[idx])
61 clonePaths[clonePath] = append(clonePaths[clonePath], fmt.Sprintf("dependentProject %s", project.Name))
62 }
63
64 starterProject, err := GetStarterProject(workspace)
65 if err != nil {
66 return err
67 }
68 if starterProject != nil {
69 projectNames[starterProject.Name] = append(projectNames[starterProject.Name], "starterProjects")
70 // Starter projects do not have a clonePath field
71 clonePaths[starterProject.Name] = append(clonePaths[starterProject.Name], fmt.Sprintf("starterProject %s", starterProject.Name))
72 }
73
74 for projectName, projectTypes := range projectNames {
75 if len(projectTypes) > 1 {
76 return fmt.Errorf("found multiple projects with the same name '%s' in: %s", projectName, strings.Join(projectTypes, ", "))
77 }
78 }
79 for clonePath, projects := range clonePaths {
80 if len(projects) > 1 {
81 return fmt.Errorf("found multiple projects with the same clone path (%s): %s", clonePath, strings.Join(projects, ", "))
82 }
83 }
84
85 return nil
86}
87
88func GetProjectCloneInitContainer(workspace *dw.DevWorkspaceTemplateSpec, options Options, proxyConfig *controllerv1alpha1.Proxy) (*corev1.Container, error) {
89 starterProject, err := GetStarterProject(workspace)

Callers 1

ReconcileMethod · 0.92

Calls 2

GetClonePathFunction · 0.85
GetStarterProjectFunction · 0.85

Tested by

no test coverage detected