Files
my-rook-config/pkg/operator/ceph/file/status.go
T

131 lines
4.9 KiB
Go
Raw Normal View History

2021-04-08 15:44:27 +02:00
/*
Copyright 2021 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 file manages a CephFS filesystem and the required daemons.
package file
import (
"time"
2025-07-24 07:21:06 +05:30
"github.com/pkg/errors"
2021-04-08 15:44:27 +02:00
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/operator/ceph/reporting"
2022-03-16 19:58:35 +05:30
"github.com/rook/rook/pkg/operator/k8sutil"
2025-12-03 10:35:58 -07:00
"github.com/rook/rook/pkg/util/log"
2021-04-08 15:44:27 +02:00
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
2025-07-24 07:21:06 +05:30
"k8s.io/client-go/util/retry"
2021-04-08 15:44:27 +02:00
)
// updateStatus updates a fs CR with the given status
2025-07-24 07:21:06 +05:30
func (r *ReconcileCephFilesystem) updateStatus(observedGeneration int64, namespacedName types.NamespacedName, status cephv1.ConditionType, info map[string]string, cephx *cephv1.CephxStatus) (*cephv1.CephFilesystem, error) {
2021-04-08 15:44:27 +02:00
fs := &cephv1.CephFilesystem{}
2025-07-24 07:21:06 +05:30
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := r.client.Get(r.opManagerContext, namespacedName, fs)
if err != nil {
if kerrors.IsNotFound(err) {
2025-12-03 10:35:58 -07:00
log.NamedDebug(namespacedName, logger, "CephFilesystem resource %q not found. Ignoring since object must be deleted.", namespacedName.String())
2025-07-24 07:21:06 +05:30
return nil
}
return errors.Wrapf(err, "failed to retrieve filesystem %q to update status to %q.", namespacedName.String(), status)
2021-04-08 15:44:27 +02:00
}
2025-07-24 07:21:06 +05:30
if fs.Status == nil {
fs.Status = &cephv1.CephFilesystemStatus{}
}
fs.Status.Phase = status
fs.Status.Info = info
if observedGeneration != k8sutil.ObservedGenerationNotAvailable {
fs.Status.ObservedGeneration = observedGeneration
}
if cephx != nil {
fs.Status.Cephx.Daemon = *cephx
}
if err := reporting.UpdateStatus(r.client, fs); err != nil {
return errors.Wrapf(err, "failed to set filesystem %q status to %q.", namespacedName.String(), status)
}
2022-12-01 20:37:07 +05:30
return nil
2025-07-24 07:21:06 +05:30
})
if err != nil {
return nil, err
2021-04-08 15:44:27 +02:00
}
2025-12-03 10:35:58 -07:00
log.NamedDebug(namespacedName, logger, "filesystem %q status updated to %q", namespacedName.String(), status)
2025-07-24 07:21:06 +05:30
return fs, nil
2021-04-08 15:44:27 +02:00
}
// updateStatusBucket updates an object with a given status
func (c *mirrorChecker) updateStatusMirroring(mirrorStatus []cephv1.FilesystemMirroringInfo, snapSchedStatus []cephv1.FilesystemSnapshotSchedulesSpec, details string) {
fs := &cephv1.CephFilesystem{}
if err := c.client.Get(c.clusterInfo.Context, c.namespacedName, fs); err != nil {
2021-04-08 15:44:27 +02:00
if kerrors.IsNotFound(err) {
2025-12-03 10:35:58 -07:00
log.NamedDebug(c.namespacedName, logger, "CephFilesystem resource not found. Ignoring since object must be deleted.")
2021-04-08 15:44:27 +02:00
return
}
2025-12-03 10:35:58 -07:00
log.NamedWarning(c.namespacedName, logger, "failed to retrieve ceph filesystem to update mirroring status. %v", err)
2021-04-08 15:44:27 +02:00
return
}
if fs.Status == nil {
fs.Status = &cephv1.CephFilesystemStatus{}
}
// Update the CephFilesystem CR status field
fs.Status = toCustomResourceStatus(fs.Status, mirrorStatus, snapSchedStatus, details)
if err := reporting.UpdateStatus(c.client, fs); err != nil {
2025-12-03 10:35:58 -07:00
log.NamedError(c.namespacedName, logger, "failed to set ceph filesystem mirroring status. %v", err)
2021-04-08 15:44:27 +02:00
return
}
2025-12-03 10:35:58 -07:00
log.NamedDebug(c.namespacedName, logger, "ceph filesystem %q mirroring status updated", c.namespacedName.Name)
2021-04-08 15:44:27 +02:00
}
func toCustomResourceStatus(currentStatus *cephv1.CephFilesystemStatus, mirrorStatus []cephv1.FilesystemMirroringInfo, snapSchedStatus []cephv1.FilesystemSnapshotSchedulesSpec, details string) *cephv1.CephFilesystemStatus {
mirrorStatusSpec := &cephv1.FilesystemMirroringInfoSpec{}
mirrorSnapScheduleStatusSpec := &cephv1.FilesystemSnapshotScheduleStatusSpec{}
now := time.Now().UTC().Format(time.RFC3339)
// MIRROR
if len(mirrorStatus) != 0 {
mirrorStatusSpec.LastChecked = now
mirrorStatusSpec.FilesystemMirroringAllInfo = mirrorStatus
}
// Always display the details, typically an error
mirrorStatusSpec.Details = details
if currentStatus != nil {
if currentStatus.MirroringStatus != nil {
mirrorStatusSpec.LastChanged = currentStatus.MirroringStatus.LastChanged
}
if currentStatus.SnapshotScheduleStatus != nil {
mirrorStatusSpec.LastChanged = currentStatus.SnapshotScheduleStatus.LastChanged
}
}
// SNAP SCHEDULE
if len(snapSchedStatus) != 0 {
mirrorSnapScheduleStatusSpec.LastChecked = now
mirrorSnapScheduleStatusSpec.SnapshotSchedules = snapSchedStatus
}
// Always display the details, typically an error
mirrorSnapScheduleStatusSpec.Details = details
return &cephv1.CephFilesystemStatus{MirroringStatus: mirrorStatusSpec, SnapshotScheduleStatus: mirrorSnapScheduleStatusSpec, Phase: currentStatus.Phase, Info: currentStatus.Info}
}