Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions pkg/environment/magic.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (mr *MagicEnvironment) Finish() {
var result milestone.Result = unknownResult{}
if mr.managedT != nil {
result = mr.managedT
if !result.Failed() {
if err := feature.DeleteResources(mr.c, mr.managedT, mr.References()); err != nil {
mr.managedT.Fatal(err)
}
}
}
if mr.milestones != nil {
mr.milestones.Finished(result)
Expand Down
31 changes: 14 additions & 17 deletions pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,21 @@ func (f *Feature) References() []corev1.ObjectReference {
// DeleteResources delete all known resources to the Feature registered
// via `Reference`.
//
// Use References to get the undeleted resources.
//
// Expected to be used as a StepFn.
func (f *Feature) DeleteResources(ctx context.Context, t T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function still has the comment:

// It doesn't fail when a referenced resource couldn't be deleted.
// Use References to get the undeleted resources.

We're now changing the behavior. When some resource couldn't be deleted we're failing the test. Is this intentional?

A few lines below we still assign this but it will be probably unused because we now fail the test with t.Fatal immediately:

f.refs = refFailedDeletion

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weren't we failing even without this patch?

	err := wait.Poll(time.Second, 4*time.Minute, func() (bool, error) { // ... }
	if err != nil {
		LogReferences(refFailedDeletion...)(ctx, t)
		t.Fatalf("failed to wait for resources to be deleted: %v", err)
	}

https://github.com/knative-sandbox/reconciler-test/blob/dc48d52d7e3cf5b7d2c8078b8907c5df2522c0c1/pkg/feature/feature.go#L229-L260

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. OK. So this condition was broken earlier. And the comment is not valid for a long time. So, now I wonder why f.refs = refFailedDeletion is still there (probably a bug).
Let's remove the invalid comment for now. Not sure what to do about the refs.

if err := DeleteResources(ctx, t, f.References()); err != nil {
t.Fatal(err)
}
}

func DeleteResources(ctx context.Context, t T, refs []corev1.ObjectReference) error {
dc := dynamicclient.Get(ctx)
for _, ref := range f.References() {

for _, ref := range refs {

gv, err := schema.ParseGroupVersion(ref.APIVersion)
if err != nil {
t.Fatalf("Could not parse GroupVersion for %+v", ref.APIVersion)
return fmt.Errorf("could not parse GroupVersion for %+v", ref.APIVersion)
}

resource := apis.KindToResource(gv.WithKind(ref.Kind))
Expand All @@ -222,15 +227,11 @@ func (f *Feature) DeleteResources(ctx context.Context, t T) {
}
}

// refFailedDeletion keeps the failed to delete resources.
var refFailedDeletion []corev1.ObjectReference

err := wait.Poll(time.Second, 4*time.Minute, func() (bool, error) {
refFailedDeletion = nil // Reset failed deletion.
for _, ref := range f.References() {
for _, ref := range refs {
gv, err := schema.ParseGroupVersion(ref.APIVersion)
if err != nil {
t.Fatalf("Could not parse GroupVersion for %+v", ref.APIVersion)
return false, fmt.Errorf("could not parse GroupVersion for %+v", ref.APIVersion)
}

resource := apis.KindToResource(gv.WithKind(ref.Kind))
Expand All @@ -243,7 +244,7 @@ func (f *Feature) DeleteResources(ctx context.Context, t T) {
continue
}
if err != nil {
refFailedDeletion = append(refFailedDeletion, ref)
LogReferences(ref)(ctx, t)
return false, fmt.Errorf("failed to get resource %+v %s/%s: %w", resource, ref.Namespace, ref.Name, err)
}

Expand All @@ -254,14 +255,10 @@ func (f *Feature) DeleteResources(ctx context.Context, t T) {
return true, nil
})
if err != nil {
LogReferences(refFailedDeletion...)(ctx, t)
t.Fatalf("failed to wait for resources to be deleted: %v", err)
return fmt.Errorf("failed to wait for resources to be deleted: %v", err)
}

f.refsMu.Lock()
defer f.refsMu.Unlock()

f.refs = refFailedDeletion
return nil
}

var (
Expand Down