Files
my-rook-config/pkg/operator/ceph/file/health.go
T
Sébastien Han b89730d895 ceph: refactor operator initialization sequence
This commit is a large refactor on how the operator starts, stops and
how it starts various sub-components such as the ceph-csi driver. It
also refines the way we cancel orchestrations. We don't use breakpoints
anymore but send our self a SIGUP to reload our controller runtime
manager.
The reload will happen under different circonstances like:

* a new adminission controller secret is created/deleted/changed
* a CephCluster CR is edited

As mentioned earlier, the csi driver now has its own controller, just
like flex. It reacts to change in the operator config map for particular
ROOK_CSI_ fields.

A second new controller for the operator's general config has been
created, it manages:

* the logging level
* the ceph CLI command timeout
* the discovery daemon

The operator reacts much more rapidly to cancellation events by stopping
the manager's context and reloading it.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-09-17 16:57:12 +02:00

114 lines
3.4 KiB
Go

/*
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 (
"context"
"time"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
defaultHealthCheckInterval = 1 * time.Minute
)
type mirrorChecker struct {
context *clusterd.Context
interval time.Duration
client client.Client
clusterInfo *cephclient.ClusterInfo
namespacedName types.NamespacedName
fsSpec *cephv1.FilesystemSpec
fsName string
}
// newMirrorChecker creates a new HealthChecker
func newMirrorChecker(context *clusterd.Context, client client.Client, clusterInfo *cephclient.ClusterInfo, namespacedName types.NamespacedName, fsSpec *cephv1.FilesystemSpec, fsName string) *mirrorChecker {
c := &mirrorChecker{
context: context,
interval: defaultHealthCheckInterval,
clusterInfo: clusterInfo,
namespacedName: namespacedName,
client: client,
fsSpec: fsSpec,
fsName: fsName,
}
// allow overriding the check interval
checkInterval := fsSpec.StatusCheck.Mirror.Interval
if checkInterval != nil {
logger.Infof("filesystem %q mirroring status check interval is %q", namespacedName.Name, checkInterval)
c.interval = checkInterval.Duration
}
return c
}
// checkMirroring periodically checks the health of the cluster
func (c *mirrorChecker) checkMirroring(context context.Context) {
// check the mirroring health immediately before starting the loop
err := c.checkMirroringHealth()
if err != nil {
c.updateStatusMirroring(nil, nil, err.Error())
logger.Debugf("failed to check filesystem mirroring status %q. %v", c.namespacedName.Name, err)
}
for {
select {
case <-context.Done():
logger.Infof("stopping monitoring filesystem mirroring status %q", c.namespacedName.Name)
return
case <-time.After(c.interval):
logger.Debugf("checking filesystem mirroring status %q", c.namespacedName.Name)
err := c.checkMirroringHealth()
if err != nil {
c.updateStatusMirroring(nil, nil, err.Error())
logger.Debugf("failed to check filesystem %q mirroring status. %v", c.namespacedName.Name, err)
}
}
}
}
func (c *mirrorChecker) checkMirroringHealth() error {
mirrorStatus, err := cephclient.GetFSMirrorDaemonStatus(c.context, c.clusterInfo, c.fsName)
if err != nil {
c.updateStatusMirroring(nil, nil, err.Error())
return err
}
var snapSchedStatus []cephv1.FilesystemSnapshotSchedulesSpec
if c.fsSpec.Mirroring.SnapShotScheduleEnabled() {
snapSchedStatus, err = cephclient.GetSnapshotScheduleStatus(c.context, c.clusterInfo, c.fsName)
if err != nil {
c.updateStatusMirroring(nil, nil, err.Error())
return err
}
}
// On success
c.updateStatusMirroring(mirrorStatus, snapSchedStatus, "")
return nil
}