@@ -23,6 +23,7 @@ import (
2323 "runtime"
2424
2525 dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
26+ "github.com/devfile/devworkspace-operator/pkg/constants"
2627 "github.com/devfile/devworkspace-operator/test/e2e/pkg/config"
2728 "github.com/onsi/ginkgo/v2"
2829 "github.com/onsi/gomega"
@@ -86,6 +87,36 @@ var _ = ginkgo.Describe("[Custom Init Container Tests]", func() {
8687 return err
8788 }, "10m" , "5s" ).Should (gomega .Succeed ())
8889
90+ // Wait for init container to complete and verify it succeeded
91+ gomega .Eventually (func () error {
92+ pod , err := config .AdminK8sClient .Kube ().CoreV1 ().Pods (config .DevWorkspaceNamespace ).Get (context .TODO (), podName , metav1.GetOptions {})
93+ if err != nil {
94+ return err
95+ }
96+ for _ , status := range pod .Status .InitContainerStatuses {
97+ if status .Name == constants .HomeInitComponentName {
98+ if status .State .Terminated == nil {
99+ return fmt .Errorf ("init container %s still running" , constants .HomeInitComponentName )
100+ }
101+ if status .State .Terminated .ExitCode != 0 {
102+ // Get logs for debugging
103+ logs , logErr := config .AdminK8sClient .GetLogsForContainer (podName , config .DevWorkspaceNamespace , constants .HomeInitComponentName )
104+ logMsg := ""
105+ if logErr == nil {
106+ logMsg = fmt .Sprintf (" Logs: %s" , logs )
107+ }
108+ return fmt .Errorf ("init container %s failed with exit code %d: %s%s" ,
109+ constants .HomeInitComponentName ,
110+ status .State .Terminated .ExitCode ,
111+ status .State .Terminated .Message ,
112+ logMsg )
113+ }
114+ return nil
115+ }
116+ }
117+ return fmt .Errorf ("init container %s status not found" , constants .HomeInitComponentName )
118+ }, "5m" , "5s" ).Should (gomega .Succeed (), "Init container should complete successfully" )
119+
89120 // Check that the custom init script ran by verifying the marker file exists
90121 resultOfExecCommand , err := config .DevK8sClient .ExecCommandInContainer (podName , config .DevWorkspaceNamespace , "tooling" , "test -f /home/user/.custom_init_complete && echo 'SUCCESS' || echo 'FAILED'" )
91122 if err != nil {
0 commit comments