Repository navigation
🤖 fix: hold a deleted CoderControlPlane while CoderMCPServer objects still use it #384
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a4409ed
🤖 fix: hold a deleted CoderControlPlane while CoderMCPServer objects …
ThomasK33 05a47b6
🤖 docs: limit the ten-minute group recheck to valid group names
ThomasK33 cf8651d
🤖 fix: end a CoderMCPServer delete pass under the control plane hold …
ThomasK33 859d6bc
🤖 fix: count the hold requeue of a CoderMCPServer delete from the end…
ThomasK33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
internal/controller/codermcpserver_delete_internal_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
|
||
| coderv1alpha1 "github.com/coder/coder-k8s/api/v1alpha1" | ||
| ) | ||
|
|
||
| // #384 review: a delete pass under the control plane hold ends at the hold | ||
| // end, also when Coder does not answer, so the bounded pass after it fits in | ||
| // the grace period. Here the hold ends in 5 s and Coder hangs on the DELETE, | ||
| // whose own request timeout is 30 s. | ||
| func TestMCPServerDeleteUnderHoldEndsAtHoldEnd(t *testing.T) { | ||
| t.Parallel() | ||
| coder := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { | ||
| <-r.Context().Done() | ||
| })) | ||
| t.Cleanup(coder.Close) | ||
|
|
||
| scheme := runtime.NewScheme() | ||
| require.NoError(t, clientgoscheme.AddToScheme(scheme)) | ||
| require.NoError(t, coderv1alpha1.AddToScheme(scheme)) | ||
| deleted := metav1.NewTime(time.Now().Add(5*time.Second - controlPlaneDependentHold)) | ||
| controlPlane := &coderv1alpha1.CoderControlPlane{ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "coder", Namespace: "ns", DeletionTimestamp: &deleted, Finalizers: []string{workspaceRBACFinalizer}, | ||
| }} | ||
| controlPlane.Status.URL = coder.URL | ||
| controlPlane.Status.OperatorAccessReady = true | ||
| controlPlane.Status.OperatorTokenSecretRef = &coderv1alpha1.SecretKeySelector{Name: "coder-operator-token"} | ||
| token := &corev1.Secret{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "coder-operator-token", Namespace: "ns"}, | ||
| Data: map[string][]byte{coderv1alpha1.DefaultTokenSecretKey: []byte("token")}, | ||
| } | ||
| namespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "ns"}} | ||
| r := &CoderMCPServerReconciler{Client: fake.NewClientBuilder().WithScheme(scheme).WithObjects(controlPlane, token, namespace).Build(), Scheme: scheme} | ||
| held, err := controlPlaneHolds(context.Background(), r.Client, controlPlane, time.Now()) | ||
| require.NoError(t, err) | ||
| require.True(t, held, "assertion failed: the test needs a control plane that holds") | ||
|
|
||
| server := &coderv1alpha1.CoderMCPServer{ObjectMeta: metav1.ObjectMeta{Name: "github", Namespace: "ns"}} | ||
| server.Spec.ControlPlaneRef.Name = "coder" | ||
| server.Spec.Slug = "github" | ||
| server.Status.OrganizationID = uuid.NewString() | ||
| server.Status.ConfigID = uuid.NewString() | ||
| start := time.Now() | ||
| release, step, err := r.deleteStep(context.Background(), server) | ||
| require.NoError(t, err) | ||
| require.Less(t, time.Since(start), 15*time.Second, "the pass ends at the hold end, not at the 30 s request timeout") | ||
| require.False(t, release, "a pass under the hold never releases without a delete") | ||
| require.NotNil(t, step) | ||
| require.Equal(t, "CoderUnavailable", step.reason) | ||
| // The requeue counts from the end of the pass: the time left to the hold | ||
| // end, which is about 0 here, plus 1 s (controlPlaneHoldRequeue). | ||
| require.LessOrEqual(t, step.requeue, 2*time.Second, "the next pass runs right after the hold end") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.