Skip to content

fix : execute preStart devfile events after project-clone initContainer #1461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/workspace/devworkspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
if projectClone, err := projects.GetProjectCloneInitContainer(&workspace.Spec.Template, projectCloneOptions, workspace.Config.Routing.ProxyConfig); err != nil {
return r.failWorkspace(workspace, fmt.Sprintf("Failed to set up project-clone init container: %s", err), metrics.ReasonInfrastructureFailure, reqLogger, &reconcileStatus), nil
} else if projectClone != nil {
devfilePodAdditions.InitContainers = append(devfilePodAdditions.InitContainers, *projectClone)
devfilePodAdditions.InitContainers = append([]corev1.Container{*projectClone}, devfilePodAdditions.InitContainers...)
}

// Add ServiceAccount tokens into devfile containers
Expand Down
33 changes: 33 additions & 0 deletions controllers/workspace/devworkspace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,39 @@ var _ = Describe("DevWorkspace Controller", func() {
workspacecontroller.SetupHttpClientsForTesting(getBasicTestHttpClient())
})

It("Ensures preStart initContainers are run after project-clone", func() {
createDevWorkspace(devWorkspaceName, "test-devworkspace-prestart.yaml")
defer deleteDevWorkspace(devWorkspaceName)
devWorkspace := getExistingDevWorkspace(devWorkspaceName)
workspaceID := devWorkspace.Status.DevWorkspaceId

By("Manually making Routing ready to continue")
markRoutingReady("test-url", common.DevWorkspaceRoutingName(workspaceID))

By("Setting the deployment to have 1 ready replica")
markDeploymentReady(common.DeploymentName(workspaceID))

deployment := &appsv1.Deployment{}
err := k8sClient.Get(ctx, namespacedName(workspaceID, testNamespace), deployment)
Expect(err).ToNot(HaveOccurred(), "Failed to get DevWorkspace deployment")

By("Checking initContainer order in the created Deployment")
initContainers := deployment.Spec.Template.Spec.InitContainers
Expect(len(initContainers)).To(BeNumerically(">", 0), "No initContainers found")

expectedOrder := []string{
"project-clone",
"go-mod-builder",
"go-builder",
}

for i, name := range expectedOrder {
if i >= len(initContainers) {
Fail(fmt.Sprintf("Expected init container %s at position %d, but only %d containers found", name, i, len(initContainers)))
}
Expect(initContainers[i].Name).To(Equal(name), fmt.Sprintf("Init container at position %d is not %s", i, name))
}
})
})

})
50 changes: 50 additions & 0 deletions controllers/workspace/testdata/test-devworkspace-prestart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
labels:
controller.devfile.io/creator: ""
spec:
started: true
template:
projects:
- name: my-app
clonePath: my-app
git:
remotes:
origin: https://github.com/che-samples/web-nodejs-sample.git
checkoutFrom:
revision: main
components:
- name: tools
container:
image: quay.io/devfile/universal-developer-image:ubi8-latest
memoryLimit: 256Mi
mountSources: true
sourceMapping: /projects
- name: go-mod-builder
container:
image: quay.io/devfile/universal-developer-image:ubi8-latest
command:
- "go"
- "mod"
- "download"
- name: go-builder
container:
image: quay.io/devfile/universal-developer-image:ubi8-latest
command:
- "go"
- "build"
- "-buildvcs=false"
- "-o"
- "./main"
commands:
- id: go-mod
apply:
component: go-mod-builder
- id: go-build
apply:
component: go-builder
events:
preStart:
- go-mod
- go-build
Loading