Skip to content
Merged
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
363 changes: 363 additions & 0 deletions test/e2e/features/cos_object_collision_and_adoption.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,363 @@
@BoxcutterRuntime
Feature: ClusterObjectSet object collision and adoption

As an OLM user applying a ClusterObjectSet directly, I want the revision's
collisionProtection setting to control whether it refuses to manage objects
that already exist (reporting ObjectCollision) or adopts them, so that I can
choose how aggressively a revision takes ownership of pre-existing objects.

Background:
Given OLM is available

# ---------------------------------------------------------------------------
# Collisions: the revision refuses to take ownership (Ready=False/ObjectCollision)
# ---------------------------------------------------------------------------

Scenario: Prevent reports ObjectCollision for a pre-existing unowned object
Given namespace "${TEST_NAMESPACE}" is available
And resource is applied
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: pre-existing
"""
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: ${COS_NAME}
spec:
lifecycleState: Active
group: ${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: managed
revision: 1
"""
Then ClusterObjectSet "${COS_NAME}" reports Ready as False with Reason ObjectCollision and Message includes:
"""
Cannot take ownership of 1 object(s) in phase "resources" because they are owned by another controller or already exist.
"""
And resource "configmap/shared-cm" matches
"""
data:
k: pre-existing
"""

Scenario: Prevent reports ObjectCollision for an object owned by another revision
Given namespace "${TEST_NAMESPACE}" is available
And ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: owner-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: owner-${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: owned-by-owner
revision: 1
"""
And ClusterObjectSet "owner-${TEST_NAMESPACE}" reports Ready as True with Reason AllObjectsReady
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: main-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: main-${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: contested
revision: 1
"""
Then ClusterObjectSet "main-${TEST_NAMESPACE}" reports Ready as False with Reason ObjectCollision and Message includes:
"""
Cannot take ownership of 1 object(s) in phase "resources" because they are owned by another controller or already exist.
"""

Scenario: IfNoController reports ObjectCollision for an object owned by another revision
Given namespace "${TEST_NAMESPACE}" is available
And ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: owner-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: owner-${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: owned-by-owner
revision: 1
"""
And ClusterObjectSet "owner-${TEST_NAMESPACE}" reports Ready as True with Reason AllObjectsReady
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: main-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: main-${NAME}
collisionProtection: IfNoController
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: contested
revision: 1
"""
Then ClusterObjectSet "main-${TEST_NAMESPACE}" reports Ready as False with Reason ObjectCollision and Message includes:
"""
Cannot take ownership of 1 object(s) in phase "resources" because they are owned by another controller or already exist.
"""

# ---------------------------------------------------------------------------
# Adoption: the revision takes ownership (Ready=True/AllObjectsReady)
# ---------------------------------------------------------------------------

Scenario: IfNoController adopts a pre-existing unowned object
Given namespace "${TEST_NAMESPACE}" is available
And resource is applied
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: pre-existing
"""
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: ${COS_NAME}
spec:
lifecycleState: Active
group: ${NAME}
collisionProtection: IfNoController
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: managed
revision: 1
"""
Then ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady
And resource "configmap/shared-cm" matches
"""
data:
k: managed
"""

Scenario: None adopts a pre-existing unowned object
Given namespace "${TEST_NAMESPACE}" is available
And resource is applied
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: pre-existing
"""
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: ${COS_NAME}
spec:
lifecycleState: Active
group: ${NAME}
collisionProtection: None
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: managed
revision: 1
"""
Then ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady
And resource "configmap/shared-cm" matches
"""
data:
k: managed
"""

Scenario: None adopts an object owned by another revision
Given namespace "${TEST_NAMESPACE}" is available
And ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: owner-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: owner-${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: owned-by-owner
revision: 1
"""
And ClusterObjectSet "owner-${TEST_NAMESPACE}" reports Ready as True with Reason AllObjectsReady
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: main-${TEST_NAMESPACE}
spec:
lifecycleState: Active
group: main-${NAME}
collisionProtection: None
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: contested
revision: 1
"""
Then ClusterObjectSet "main-${TEST_NAMESPACE}" reports Ready as True with Reason AllObjectsReady
And resource "configmap/shared-cm" matches
"""
data:
k: contested
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the future we may also consider to check that:

  • the UID hasn't changed (the object was not re-created)
  • the ownerRef has been updated
    ...or maybe not, since we own the code that does the adoption and I don't think we will change that too often 🤷🏻

# ---------------------------------------------------------------------------
# Recovery: a collision clears once the conflicting object is removed
# ---------------------------------------------------------------------------

Scenario: ClusterObjectSet recovers from ObjectCollision once the conflicting object is removed
Given namespace "${TEST_NAMESPACE}" is available
And resource is applied
"""
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: pre-existing
"""
When ClusterObjectSet is applied
"""
apiVersion: olm.operatorframework.io/v1
kind: ClusterObjectSet
metadata:
name: ${COS_NAME}
spec:
lifecycleState: Active
group: ${NAME}
collisionProtection: Prevent
phases:
- name: resources
objects:
- object:
apiVersion: v1
kind: ConfigMap
metadata:
name: shared-cm
namespace: ${TEST_NAMESPACE}
data:
k: managed
revision: 1
"""
Then ClusterObjectSet "${COS_NAME}" reports Ready as False with Reason ObjectCollision and Message includes:
"""
Cannot take ownership of 1 object(s) in phase "resources" because they are owned by another controller or already exist.
"""
When resource "configmap/shared-cm" is removed
And ClusterObjectSet "${COS_NAME}" reconciliation is triggered
Then ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady
And resource "configmap/shared-cm" matches
"""
data:
k: managed
"""
Loading