-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from njhale/test-ownerref-gc
test(e2e): add OwnerReference GC behavior test
- Loading branch information
Showing
4 changed files
with
119 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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,84 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coreos/go-semver/semver" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil" | ||
) | ||
|
||
// TestOwnerReferenceGCBehavior runs a simple check on OwnerReference behavior to ensure | ||
// a resource with multiple OwnerReferences will not be garbage collected when one of its | ||
// owners has been deleted. | ||
// Test Case: | ||
// CSV-A CSV-B CSV-B | ||
// \ / --Delete CSV-A--> | | ||
// ConfigMap ConfigMap | ||
func TestOwnerReferenceGCBehavior(t *testing.T) { | ||
defer cleaner.NotifyTestComplete(t, true) | ||
|
||
ownerA := newCSV("ownera", testNamespace, "", *semver.New("0.0.0"), nil, nil, newNginxInstallStrategy("dep-")) | ||
ownerB := newCSV("ownerb", testNamespace, "", *semver.New("0.0.0"), nil, nil, newNginxInstallStrategy("dep-")) | ||
|
||
// create all owners | ||
c := newKubeClient(t) | ||
crc := newCRClient(t) | ||
|
||
fetchedA, err := crc.Operators().ClusterServiceVersions(testNamespace).Create(&ownerA) | ||
require.NoError(t, err) | ||
fetchedB, err := crc.Operators().ClusterServiceVersions(testNamespace).Create(&ownerB) | ||
require.NoError(t, err) | ||
|
||
dependent := &corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "dependent", | ||
}, | ||
Data: map[string]string{}, | ||
} | ||
|
||
// add owners | ||
ownerutil.AddOwner(dependent, fetchedA, true, false) | ||
ownerutil.AddOwner(dependent, fetchedB, true, false) | ||
|
||
// create dependent | ||
_, err = c.KubernetesInterface().CoreV1().ConfigMaps(testNamespace).Create(dependent) | ||
require.NoError(t, err, "dependent could not be created") | ||
|
||
// delete ownerA in the foreground (to ensure any "blocking" dependents are deleted before ownerA) | ||
propagation := metav1.DeletionPropagation("Foreground") | ||
options := metav1.DeleteOptions{PropagationPolicy: &propagation} | ||
err = crc.Operators().ClusterServiceVersions(testNamespace).Delete(fetchedA.GetName(), &options) | ||
require.NoError(t, err) | ||
|
||
// wait for deletion of ownerA | ||
waitForDelete(func() error { | ||
_, err := crc.Operators().ClusterServiceVersions(testNamespace).Get(ownerA.GetName(), metav1.GetOptions{}) | ||
return err | ||
}) | ||
|
||
// check for dependent (should still exist since it still has one owner present) | ||
_, err = c.KubernetesInterface().CoreV1().ConfigMaps(testNamespace).Get(dependent.GetName(), metav1.GetOptions{}) | ||
require.NoError(t, err, "dependent deleted after one owner was deleted") | ||
t.Log("dependent still exists after one owner was deleted") | ||
|
||
// delete ownerB in the foreground (to ensure any "blocking" dependents are deleted before ownerB) | ||
err = crc.Operators().ClusterServiceVersions(testNamespace).Delete(fetchedB.GetName(), &options) | ||
require.NoError(t, err) | ||
|
||
// wait for deletion of ownerB | ||
waitForDelete(func() error { | ||
_, err := crc.Operators().ClusterServiceVersions(testNamespace).Get(ownerB.GetName(), metav1.GetOptions{}) | ||
return err | ||
}) | ||
|
||
// check for dependent (should be deleted since last blocking owner was deleted) | ||
_, err = c.KubernetesInterface().CoreV1().ConfigMaps(testNamespace).Get(dependent.GetName(), metav1.GetOptions{}) | ||
require.Error(t, err) | ||
require.True(t, k8serrors.IsNotFound(err)) | ||
t.Log("dependent successfully garbage collected after both owners were deleted") | ||
} |
This file contains 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 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