-
Notifications
You must be signed in to change notification settings - Fork 32
K8SPS-535: fix more delete-backup
finalizer issues
#1113
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
Changes from all commits
30786ee
3d424a7
ee03389
d28352f
032e2bb
42af5a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,19 +281,13 @@ func TestStateDescCleanup(t *testing.T) { | |
} | ||
|
||
func TestCheckFinalizers(t *testing.T) { | ||
ctx := context.Background() | ||
scheme := runtime.NewScheme() | ||
if err := clientgoscheme.AddToScheme(scheme); err != nil { | ||
t.Fatal(err, "failed to add client-go scheme") | ||
} | ||
if err := apiv1.AddToScheme(scheme); err != nil { | ||
t.Fatal(err, "failed to add apis scheme") | ||
} | ||
require.NoError(t, clientgoscheme.AddToScheme(scheme)) | ||
require.NoError(t, apiv1.AddToScheme(scheme)) | ||
namespace := "some-namespace" | ||
|
||
cr, err := readDefaultCRBackup("some-name", namespace) | ||
if err != nil { | ||
t.Fatal(err, "failed to read default backup") | ||
} | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
|
@@ -414,9 +408,10 @@ func TestCheckFinalizers(t *testing.T) { | |
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.cr.Status.Storage = storage | ||
cr := tt.cr.DeepCopy() | ||
cr.Status.Storage = storage | ||
|
||
job := xtrabackup.GetDeleteJob(new(apiv1.PerconaServerMySQL), tt.cr, new(xtrabackup.BackupConfig)) | ||
job := xtrabackup.GetDeleteJob(new(apiv1.PerconaServerMySQL), cr, new(xtrabackup.BackupConfig)) | ||
cond := batchv1.JobCondition{ | ||
Type: batchv1.JobComplete, | ||
Status: corev1.ConditionTrue, | ||
|
@@ -426,25 +421,33 @@ func TestCheckFinalizers(t *testing.T) { | |
} | ||
job.Status.Conditions = append(job.Status.Conditions, cond) | ||
|
||
cb := fake.NewClientBuilder().WithScheme(scheme).WithObjects(tt.cr, sec, job) | ||
cb := fake.NewClientBuilder().WithScheme(scheme).WithObjects(cr, sec, job) | ||
r := PerconaServerMySQLBackupReconciler{ | ||
Client: cb.Build(), | ||
Scheme: scheme, | ||
ServerVersion: &platform.ServerVersion{Platform: platform.PlatformKubernetes}, | ||
} | ||
err := r.Delete(ctx, tt.cr) | ||
if err != nil { | ||
|
||
require.NoError(t, r.Delete(t.Context(), cr)) | ||
|
||
// Getting backup with deletion timestamp | ||
if err := r.Get(t.Context(), client.ObjectKeyFromObject(cr), cr); err != nil { | ||
if k8serrors.IsNotFound(err) && len(tt.expectedFinalizers) == 0 { | ||
return | ||
} | ||
t.Fatal(err) | ||
} | ||
cr := new(apiv1.PerconaServerMySQLBackup) | ||
if err := r.Get(ctx, types.NamespacedName{Name: tt.cr.Name, Namespace: tt.cr.Namespace}, cr); err != nil { | ||
if k8serrors.IsNotFound(err) && len(cr.Finalizers) == 0 { | ||
|
||
assert.NoError(t, r.checkFinalizers(t.Context(), cr)) | ||
Comment on lines
+431
to
+441
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
|
||
// Getting backup with updated finalizers | ||
if err := r.Get(t.Context(), client.ObjectKeyFromObject(cr), cr); err != nil { | ||
Comment on lines
+431
to
+444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
Comment on lines
+431
to
+444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if k8serrors.IsNotFound(err) && len(tt.expectedFinalizers) == 0 { | ||
return | ||
} | ||
t.Fatal(err) | ||
} | ||
|
||
r.checkFinalizers(ctx, cr) | ||
assert.Equal(t, tt.expectedFinalizers, cr.Finalizers) | ||
}) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.