Skip to content

[OSPRH-17456] Fix namespace handling for operator references#1527

Merged
openshift-merge-bot[bot] merged 1 commit into
openstack-k8s-operators:mainfrom
abays:fix_OSPRH_17456
Jul 9, 2025
Merged

[OSPRH-17456] Fix namespace handling for operator references#1527
openshift-merge-bot[bot] merged 1 commit into
openstack-k8s-operators:mainfrom
abays:fix_OSPRH_17456

Conversation

@abays

@abays abays commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Problem:
The postCleanupObsoleteResources function was attempting to unconditionally set the namespace for all operator references using obj.SetNamespace(refData["namespace"].(string)). This caused a panic when processing cluster-scoped resources that don't have a namespace field in their reference data.

Solution:
Added a safety check to only set the namespace if it exists in the reference data:

// Some of the references are not namespaced, so we need to check if the namespace is present
if namespace, ok := refData["namespace"]; ok {
    obj.SetNamespace(namespace.(string))
}

Changes:
Modified the namespace handling logic in postCleanupObsoleteResources() function
Added conditional check for namespace existence before setting it on the object
Added explanatory comment about cluster-scoped vs namespaced resources

Testing:
Prevents panic when processing operator references that include cluster-scoped resources
Maintains existing functionality for namespaced resources
Allows cleanup process to continue successfully for mixed reference types

Files Changed:
controllers/operator/openstack_controller.go
This fix ensures robust handling of both namespaced and cluster-scoped operator references during the cleanup process.

Generated-By: cursor with claude-4-sonnet model

Jira: https://issues.redhat.com/browse/OSPRH-17456

@openshift-ci openshift-ci Bot requested review from rabi and viroel July 9, 2025 14:55
@openshift-ci openshift-ci Bot added the approved label Jul 9, 2025
@abays abays requested review from dprince and stuggi and removed request for rabi and viroel July 9, 2025 16:55
@openshift-ci

openshift-ci Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abays, dprince

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot Bot merged commit 1fb1db4 into openstack-k8s-operators:main Jul 9, 2025
8 checks passed
@stuggi

stuggi commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

/cherry-pick 18.0-fr3

@openshift-cherrypick-robot

Copy link
Copy Markdown

@stuggi: new pull request created: #1529

Details

In response to this:

/cherry-pick 18.0-fr3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants