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

Pass independent context to DeleteClusterMember #638

Merged
Merged
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
11 changes: 10 additions & 1 deletion src/k8s/pkg/k8sd/api/cluster_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"net/http"
"time"

apiv1 "github.com/canonical/k8s-snap-api/api/v1"
databaseutil "github.com/canonical/k8s/pkg/k8sd/database/util"
Expand Down Expand Up @@ -66,7 +67,15 @@ func (e *Endpoints) postClusterRemove(s state.State, r *http.Request) response.R
if err != nil {
return response.InternalError(fmt.Errorf("failed to create client to cluster leader: %w", err))
}
if err := c.DeleteClusterMember(ctx, req.Name, req.Force); err != nil {

// NOTE(hue): node removal process in CAPI might fail, we figured that the context passed to
// `DeleteClusterMember` is somehow getting canceled but couldn't figure out why or by which component.
// The cancellation happens after the `RunPreRemoveHook` call and before the `DeleteCoreClusterMember` call
// in `clusterMemberDelete` endpoint of microcluster. This is a workaround to avoid the cancellation.
// keep in mind that this failure is flaky and might not happen in every run.
deleteCtx, deleteCancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer deleteCancel()
if err := c.DeleteClusterMember(deleteCtx, req.Name, req.Force); err != nil {
return response.InternalError(fmt.Errorf("failed to delete cluster member %s: %w", req.Name, err))
}

Expand Down
Loading