Files
my-rook-config/pkg/operator/ceph/reporting/status.go
T
Travis Nielsen 0a3a599580 block: add condition for deletion blocked with images
When the blockpool is deleted and there are images or
snapshots in the pool, the deletion is blocked by the
finalizer until they are all removed. The condition added
to the cephblockpool status only indicated if there were
radosnamespace dependencies. A new condition is now added
to describe if there are images or snapshots.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
2025-05-07 15:42:17 -06:00

69 lines
2.1 KiB
Go

/*
Copyright 2020 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package reporting
import (
"context"
"fmt"
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// UpdateStatus updates an object with a given status. The object is updated with the latest version
// from the server on a successful update.
func UpdateStatus(client client.Client, obj client.Object) error {
nsName := types.NamespacedName{
Namespace: obj.GetNamespace(),
Name: obj.GetName(),
}
// Try to update the status
err := client.Status().Update(context.Background(), obj)
// If the object doesn't exist yet, we need to initialize it
if kerrors.IsNotFound(err) {
err = client.Update(context.Background(), obj)
}
if err != nil {
return errors.Wrapf(err, "failed to update object %q status", nsName.String())
}
return nil
}
// UpdateStatusCondition updates (or adds to) the status condition to the given object. The object
// is updated with the latest version from the server on a successful update.
func UpdateStatusCondition(
client client.Client, obj statusConditionGetter, newConditions ...cephv1.Condition,
) error {
kind := obj.GetObjectKind().GroupVersionKind().Kind
nsName := fmt.Sprintf("%s/%s", obj.GetNamespace(), obj.GetName())
for _, newCondition := range newConditions {
cephv1.SetStatusCondition(obj.GetStatusConditions(), newCondition)
}
if err := UpdateStatus(client, obj); err != nil {
return errors.Wrapf(err, "failed to update %s %q status conditions", kind, nsName)
}
return nil
}