Skip to content

Commit

Permalink
keep daemonset running; avoid CrashLoopBackOff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-led committed Mar 27, 2024
1 parent 9ea516b commit a770f0f
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,33 @@ func run(c context.Context, log *logrus.Entry, cfg *config.Config) error {
}
}()

select {
case err = <-errorCh:
if err != nil {
return errors.Wrap(err, "assigning static public IP address")
}
case <-ctx.Done():
log.Infof("kubeip agent gracefully stopped")
if cfg.ReleaseOnExit {
log.Infof("releasing static public IP address")
releaseCtx, releaseCancel := context.WithTimeout(context.Background(), unassignTimeout) // release the static public IP address within 5 minutes
defer releaseCancel()
// use a different context for releasing the static public IP address since the main context is canceled
if err = assigner.Unassign(releaseCtx, n.Instance, n.Zone); err != nil { //nolint:contextcheck
return errors.Wrap(err, "failed to release static public IP address")
for {
select {
case err = <-errorCh:
if err != nil {
return errors.Wrap(err, "assigning static public IP address")
}
case <-ctx.Done():
log.Infof("kubeip agent gracefully stopped")
if cfg.ReleaseOnExit {
log.Infof("releasing static public IP address")
err = func() error {
releaseCtx, releaseCancel := context.WithTimeout(context.Background(), unassignTimeout) // release the static public IP address within 5 minutes
defer releaseCancel()
// use a different context for releasing the static public IP address since the main context is canceled
if err = assigner.Unassign(releaseCtx, n.Instance, n.Zone); err != nil {
return errors.Wrap(err, "failed to release static public IP address")
}
return nil
}()
if err != nil {
return err //nolint:wrapcheck
}
log.Infof("static public IP address released")
}
log.Infof("static public IP address released")
return nil
}
}

return nil
}

func runCmd(c *cli.Context) error {
Expand Down

0 comments on commit a770f0f

Please sign in to comment.