@@ -6,7 +6,10 @@ import (
66 "fmt"
77 runtimevar "github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/runtime"
88 "github.com/loft-sh/devspace/pkg/devspace/imageselector"
9+ "github.com/loft-sh/devspace/pkg/devspace/kubectl/selector"
910 "io"
11+ kerrors "k8s.io/apimachinery/pkg/api/errors"
12+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1013 "os"
1114 "path/filepath"
1215 "runtime"
@@ -104,7 +107,7 @@ func (c *controller) startWithWait(options *Options, log logpkg.Logger) error {
104107 }
105108
106109 // start the sync
107- client , err := c .startSync (options , onInitUploadDone , onInitDownloadDone , onDone , onError , log )
110+ client , pod , err := c .startSync (options , onInitUploadDone , onInitDownloadDone , onDone , onError , log )
108111 if err != nil {
109112 pluginErr := hook .ExecuteHooks (c .client , c .config , c .dependencies , map [string ]interface {}{
110113 "sync_config" : options .SyncConfig ,
@@ -185,6 +188,7 @@ func (c *controller) startWithWait(options *Options, log logpkg.Logger) error {
185188 }, options .SyncLog , hook .EventsForSingle ("restart:sync" , options .SyncConfig .Name ).With ("sync.restart" )... )
186189
187190 options .SyncLog .Info ("Restarting sync..." )
191+ PrintPodError (context .TODO (), c .client , pod .Pod , options .SyncLog )
188192 for {
189193 err := c .startWithWait (options , options .SyncLog )
190194 if err != nil {
@@ -218,6 +222,25 @@ func (c *controller) startWithWait(options *Options, log logpkg.Logger) error {
218222
219223 return nil
220224}
225+
226+ func PrintPodError (ctx context.Context , kubeClient kubectl.Client , pod * v1.Pod , log logpkg.Logger ) {
227+ // check if pod still exists
228+ newPod , err := kubeClient .KubeClient ().CoreV1 ().Pods (pod .Namespace ).Get (ctx , pod .Name , metav1.GetOptions {})
229+ if err != nil {
230+ if kerrors .IsNotFound (err ) {
231+ log .Errorf ("Restarted because old pod %s/%s seems to be erased" , pod .Namespace , pod .Name )
232+ return
233+ }
234+
235+ return
236+ }
237+
238+ podStatus := kubectl .GetPodStatus (newPod )
239+ if podStatus != "Running" {
240+ log .Errorf ("Restarted because old pod %s/%s has status %s" , pod .Namespace , pod .Name , podStatus )
241+ }
242+ }
243+
221244func realWorkDir () (string , error ) {
222245 if runtime .GOOS == "darwin" {
223246 if pwd , present := os .LookupEnv ("PWD" ); present {
@@ -229,15 +252,15 @@ func realWorkDir() (string, error) {
229252 return "." , nil
230253}
231254
232- func (c * controller ) startSync (options * Options , onInitUploadDone chan struct {}, onInitDownloadDone chan struct {}, onDone chan struct {}, onError chan error , log logpkg.Logger ) (* sync.Sync , error ) {
255+ func (c * controller ) startSync (options * Options , onInitUploadDone chan struct {}, onInitDownloadDone chan struct {}, onDone chan struct {}, onError chan error , log logpkg.Logger ) (* sync.Sync , * selector. SelectedPodContainer , error ) {
233256 options .TargetOptions .SkipInitContainers = true
234257 var (
235258 syncConfig = options .SyncConfig
236259 )
237260
238261 localPath , err := realWorkDir ()
239262 if err != nil {
240- return nil , err
263+ return nil , nil , err
241264 }
242265
243266 if syncConfig .LocalSubPath != "" {
@@ -247,20 +270,20 @@ func (c *controller) startSync(options *Options, onInitUploadDone chan struct{},
247270 _ , err = os .Stat (localPath )
248271 if err != nil {
249272 if ! os .IsNotExist (err ) {
250- return nil , err
273+ return nil , nil , err
251274 }
252275
253276 err = os .MkdirAll (localPath , os .ModePerm )
254277 if err != nil {
255- return nil , err
278+ return nil , nil , err
256279 }
257280 }
258281
259282 options .TargetOptions .ImageSelector = []imageselector.ImageSelector {}
260283 if syncConfig .ImageSelector != "" {
261284 imageSelector , err := runtimevar .NewRuntimeResolver (true ).FillRuntimeVariablesAsImageSelector (syncConfig .ImageSelector , c .config , c .dependencies )
262285 if err != nil {
263- return nil , err
286+ return nil , nil , err
264287 }
265288
266289 options .TargetOptions .ImageSelector = append (options .TargetOptions .ImageSelector , * imageSelector )
@@ -269,18 +292,18 @@ func (c *controller) startSync(options *Options, onInitUploadDone chan struct{},
269292 log .Info ("Waiting for containers to start..." )
270293 container , err := targetselector .NewTargetSelector (c .client ).SelectSingleContainer (context .TODO (), options .TargetOptions , log )
271294 if err != nil {
272- return nil , errors .Errorf ("Error selecting pod: %v" , err )
295+ return nil , nil , errors .Errorf ("Error selecting pod: %v" , err )
273296 }
274297
275298 log .Info ("Starting sync..." )
276299 syncClient , err := c .initClient (container .Pod , container .Container .Name , syncConfig , options .Verbose , options .SyncLog )
277300 if err != nil {
278- return nil , errors .Wrap (err , "start sync" )
301+ return nil , nil , errors .Wrap (err , "start sync" )
279302 }
280303
281304 err = syncClient .Start (onInitUploadDone , onInitDownloadDone , onDone , onError )
282305 if err != nil {
283- return nil , errors .Errorf ("Sync error: %v" , err )
306+ return nil , nil , errors .Errorf ("Sync error: %v" , err )
284307 }
285308
286309 containerPath := "."
@@ -289,7 +312,7 @@ func (c *controller) startSync(options *Options, onInitUploadDone chan struct{},
289312 }
290313
291314 log .Donef ("Sync started on %s <-> %s (Pod: %s/%s)" , syncClient .LocalPath , containerPath , container .Pod .Namespace , container .Pod .Name )
292- return syncClient , nil
315+ return syncClient , container , nil
293316}
294317
295318func (c * controller ) initClient (pod * v1.Pod , container string , syncConfig * latest.SyncConfig , verbose bool , customLog logpkg.Logger ) (* sync.Sync , error ) {
0 commit comments