|
9 | 9 |
|
10 | 10 | "github.com/openstack-k8s-operators/lib-common/modules/common/helper" |
11 | 11 | corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/api/core/v1beta1" |
| 12 | + k8s_errors "k8s.io/apimachinery/pkg/api/errors" |
12 | 13 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
13 | 14 | "k8s.io/apimachinery/pkg/types" |
14 | 15 | ctrl "sigs.k8s.io/controller-runtime" |
@@ -244,15 +245,21 @@ func ReconcileVersion(ctx context.Context, instance *corev1beta1.OpenStackContro |
244 | 245 |
|
245 | 246 | Log := GetLogger(ctx) |
246 | 247 |
|
247 | | - // return if OpenStackVersion CR already exists |
248 | 248 | if err := helper.GetClient().Get(ctx, types.NamespacedName{ |
249 | 249 | Name: instance.Name, |
250 | 250 | 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 | 255 | Log.Info(fmt.Sprintf("OpenStackVersion does not exist. Creating: %s", version.Name)) |
| 256 | + } else { |
| 257 | + Log.Info(fmt.Sprintf("OpenStackVersion found. Name: %s", version.Name)) |
| 258 | + } |
| 259 | + |
| 260 | + // Don't create or update the OpenStackVersion when the controlplane is being deleted |
| 261 | + if !instance.DeletionTimestamp.IsZero() { |
| 262 | + return ctrl.Result{}, version, nil |
256 | 263 | } |
257 | 264 |
|
258 | 265 | op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), version, func() error { |
|
0 commit comments