Skip to content

Commit 68728a9

Browse files
stuggiclaude
andcommitted
Fix ReconcileVersion re-creating OpenStackVersion during deletion
When an OpenStackControlPlane CR is deleted, the reconciler called ReconcileVersion() before checking DeletionTimestamp. ReconcileVersion unconditionally called CreateOrPatch on the OpenStackVersion CR, which would re-create it even during deletion. This caused issues in adoption CI: the pcp_cleanup role deleted the OpenStackControlPlane but the controller re-created the OpenStackVersion before fully shutting down. The leftover OpenStackVersion (named 'controlplane' from the source cloud) then caused the new OpenStackControlPlane (named 'openstack') to be rejected by the webhook with: OpenStackControlPlane 'openstack' must have same name as the existing 'controlplane' OpenStackVersion Fix ReconcileVersion to properly handle the Get result: - Return actual errors (not IsNotFound) instead of swallowing them - Skip CreateOrPatch when the controlplane is being deleted - Still return the existing version object so reconcileDelete can remove its finalizer Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 55df25d commit 68728a9

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

internal/openstack/version.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
1111
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/api/core/v1beta1"
12+
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/types"
1415
ctrl "sigs.k8s.io/controller-runtime"
@@ -244,15 +245,24 @@ func ReconcileVersion(ctx context.Context, instance *corev1beta1.OpenStackContro
244245

245246
Log := GetLogger(ctx)
246247

247-
// return if OpenStackVersion CR already exists
248248
if err := helper.GetClient().Get(ctx, types.NamespacedName{
249249
Name: instance.Name,
250250
Namespace: instance.Namespace,
251-
},
252-
version); err == nil {
253-
Log.Info(fmt.Sprintf("OpenStackVersion found. Name: %s", version.Name))
254-
} else {
251+
}, version); err != nil {
252+
if !k8s_errors.IsNotFound(err) {
253+
return ctrl.Result{}, nil, err
254+
}
255+
// OpenStackVersion not found, only create it if we're not being deleted
256+
if !instance.DeletionTimestamp.IsZero() {
257+
return ctrl.Result{}, version, nil
258+
}
255259
Log.Info(fmt.Sprintf("OpenStackVersion does not exist. Creating: %s", version.Name))
260+
} else {
261+
Log.Info(fmt.Sprintf("OpenStackVersion found. Name: %s", version.Name))
262+
// Already exists, nothing to do if we're being deleted
263+
if !instance.DeletionTimestamp.IsZero() {
264+
return ctrl.Result{}, version, nil
265+
}
256266
}
257267

258268
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), version, func() error {

0 commit comments

Comments
 (0)