Skip to content
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

ssh: Abort keepalive on not found #257

Merged
merged 3 commits into from
Mar 20, 2023
Merged
Changes from 1 commit
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
Next Next commit
abort keepalive when bastion not found
  • Loading branch information
petersutter committed Mar 15, 2023
commit 236b1526c633e8fd233c4fef2b1d3a20d70a9db9
13 changes: 10 additions & 3 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func (o *SSHOptions) Run(f util.Factory) error {
}

// continuously keep the bastion alive by renewing its annotation
go keepBastionAlive(ctx, gardenClient.RuntimeClient(), bastion.DeepCopy())
go keepBastionAlive(ctx, cancel, gardenClient.RuntimeClient(), bastion.DeepCopy())

logger.Info("Waiting for bastion to be ready…", "waitTimeout", o.WaitTimeout)

Expand Down Expand Up @@ -967,8 +967,8 @@ func getKeepAliveInterval() time.Duration {
return keepAliveInterval
}

func keepBastionAlive(ctx context.Context, gardenClient client.Client, bastion *operationsv1alpha1.Bastion) {
logger := klog.FromContext(ctx)
func keepBastionAlive(ctx context.Context, cancel context.CancelFunc, gardenClient client.Client, bastion *operationsv1alpha1.Bastion) {
logger := klog.FromContext(ctx).WithValues("bastion", klog.KObj(bastion))

ticker := time.NewTicker(getKeepAliveInterval())
defer ticker.Stop()
Expand All @@ -986,6 +986,13 @@ func keepBastionAlive(ctx context.Context, gardenClient client.Client, bastion *
bastion.Annotations = map[string]string{}

if err := gardenClient.Get(ctx, key, bastion); err != nil {
if apierrors.IsNotFound(err) {
logger.Error(err, "Can't keep bastion alive. Bastion is already gone.")
cancel()

return
}

logger.Error(err, "Failed to keep bastion alive.")
}

Expand Down