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
42 changes: 42 additions & 0 deletions test/e2e/features/uninstall.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Feature: Uninstall ClusterExtension

As an OLM user I would like to uninstall a cluster extension,
removing all resources previously installed/updated through the extension.

Background:
Given OLM is available
And ClusterCatalog "test" serves bundles
And ServiceAccount "olm-sa" with needed permissions is available in ${TEST_NAMESPACE}
And ClusterExtension is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterExtension
metadata:
name: ${NAME}
spec:
namespace: ${TEST_NAMESPACE}
serviceAccount:
name: olm-sa
source:
sourceType: Catalog
catalog:
packageName: test
selector:
matchLabels:
"olm.operatorframework.io/metadata.name": test-catalog
"""
And bundle "test-operator.1.2.0" is installed in version "1.2.0"
And ClusterExtension is rolled out
And ClusterExtension resources are created and labeled

Scenario: Removing ClusterExtension triggers the extension uninstall, eventually removing all installed resources
When ClusterExtension is removed
Then the ClusterExtension's constituent resources are removed

Scenario: Removing ClusterExtension resources leads to all installed resources being removed even if the service account is no longer present
When resource "serviceaccount/olm-sa" is removed
# Ensure service account is gone before checking to ensure resources are cleaned up whether the service account
# and its permissions are present on the cluster or not
And resource "serviceaccount/olm-sa" is eventually not found
And ClusterExtension is removed
Then the ClusterExtension's constituent resources are removed
21 changes: 21 additions & 0 deletions test/e2e/steps/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/component-base/featuregate"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/operator-framework/operator-controller/internal/operator-controller/features"
)
Expand All @@ -32,6 +33,26 @@ type scenarioContext struct {
removedResources []unstructured.Unstructured
backGroundCmds []*exec.Cmd
metricsResponse map[string]string

extensionObjects []client.Object
}

// GatherClusterExtensionObjects collects all resources related to the ClusterExtension container in
// either their Helm release Secret or ClusterExtensionRevision depending on the applier being used
// and saves them into the context.
func (s *scenarioContext) GatherClusterExtensionObjects() error {
objs, err := listExtensionResources(s.clusterExtensionName)
if err != nil {
return fmt.Errorf("failed to load extension resources into context: %w", err)
}
s.extensionObjects = objs
return nil
}

// GetClusterExtensionObjects returns the ClusterExtension objects currently saved into the context.
// Will always return nil until GatherClusterExtensionObjects is called
func (s *scenarioContext) GetClusterExtensionObjects() []client.Object {
return s.extensionObjects
}

type contextKey string
Expand Down
Loading
Loading