From 5d50c829ae94fb9a5f169bea4cc13fe30987d715 Mon Sep 17 00:00:00 2001 From: Andrew Obuchowicz Date: Tue, 17 Oct 2023 15:22:36 -0400 Subject: [PATCH] fixup! Fix: include starter projects for $PROJECT_SOURCE path selection --- pkg/library/container/container.go | 6 ++--- pkg/library/container/mountSources.go | 31 ++++++++++------------- pkg/library/projects/util.go | 36 --------------------------- 3 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 pkg/library/projects/util.go diff --git a/pkg/library/container/container.go b/pkg/library/container/container.go index 6214c1a74..582216f0a 100644 --- a/pkg/library/container/container.go +++ b/pkg/library/container/container.go @@ -64,8 +64,7 @@ func GetKubeContainersFromDevfile(workspace *dw.DevWorkspaceTemplateSpec, securi if err != nil { return nil, err } - err = handleMountSources(k8sContainer, component.Container, workspace) - if err != nil { + if err := handleMountSources(k8sContainer, component.Container, workspace); err != nil { return nil, err } if overrides.NeedsContainerOverride(&component) { @@ -91,8 +90,7 @@ func GetKubeContainersFromDevfile(workspace *dw.DevWorkspaceTemplateSpec, securi if err != nil { return nil, err } - err = handleMountSources(k8sContainer, initComponent.Container, workspace) - if err != nil { + if err := handleMountSources(k8sContainer, initComponent.Container, workspace); err != nil { return nil, err } if overrides.NeedsContainerOverride(&initComponent) { diff --git a/pkg/library/container/mountSources.go b/pkg/library/container/mountSources.go index d27b493a2..f6a765743 100644 --- a/pkg/library/container/mountSources.go +++ b/pkg/library/container/mountSources.go @@ -102,28 +102,23 @@ func handleMountSources(k8sContainer *corev1.Container, devfileContainer *dw.Con // // 2. If the workspace has a starter project that is selected, its name will be used as the project source path. // -// 3. If the workspace has at least one starter project, but none are selected, -// the name of the first starter project will be used as the project source path. -// -// 4. Otherwise, the returned project source path will be an empty string. +// 3. Otherwise, the returned project source path will be an empty string. func getProjectSourcePath(workspace *dw.DevWorkspaceTemplateSpec) (string, error) { - projects := projectslib.GetAllProjects(workspace) + projects := workspace.Projects + // If there are any projects, return the first one's clone path if len(projects) > 0 { - selectedStarterProject, err := projectslib.GetStarterProject(workspace) - if err != nil { - return "", err - } - // Only use the selected starterProject if we have no regular projects - if selectedStarterProject != nil && len(workspace.Projects) == 0 { - return selectedStarterProject.Name, nil - } + return projectslib.GetClonePath(&projects[0]), nil + } - firstProject := projects[0] - if firstProject.ClonePath != "" { - return firstProject.ClonePath, nil - } - return firstProject.Name, nil + // No projects, check if we have a selected starter project + selectedStarterProject, err := projectslib.GetStarterProject(workspace) + if err != nil { + return "", err + } else if selectedStarterProject != nil { + // Starter projects do not allow specifying a clone path, so use the name + return selectedStarterProject.Name, nil } + return "", nil } diff --git a/pkg/library/projects/util.go b/pkg/library/projects/util.go deleted file mode 100644 index 6ac6ffbdf..000000000 --- a/pkg/library/projects/util.go +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright (c) 2019-2023 Red Hat, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package projects - -import ( - dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" -) - -// Returns all projects (including starter projects) present in a DevWorkspaceTemplateSpec -func GetAllProjects(workspace *dw.DevWorkspaceTemplateSpec) []dw.Project { - projects := workspace.Projects - - // Note: starter project does not allow for specifying clonePath - for _, starterProject := range workspace.StarterProjects { - project := dw.Project{ - Name: starterProject.Name, - Attributes: starterProject.Attributes, - ProjectSource: starterProject.ProjectSource, - } - projects = append(projects, project) - } - return projects -}