ceph: use metav1.Duration for time CRD field

Previously, `interval` was just a string so no special validation was
done by the OpenAPI validator. Now that it is advertised as metav1.Duration
 the server will introspect it correctly. Underneath the type is still a
 string so no update issue to be worried about.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han committed 2021-03-25 12:12:31 +01:00
1 parent e30cca076d
commit d8de013443
12 files changed
+97 -66

No files matched your search

@@ -155,6 +155,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -557,6 +558,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -568,6 +570,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -579,6 +582,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -4777,6 +4781,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -4910,6 +4915,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -6192,6 +6198,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -6734,6 +6741,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -6956,6 +6964,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -7303,6 +7312,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -7435,6 +7445,7 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -178,6 +178,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -628,6 +630,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -640,6 +644,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -652,6 +658,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -7658,6 +7666,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -7810,6 +7820,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -9850,6 +9862,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -10775,6 +10789,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -11050,6 +11066,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -11431,6 +11449,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
@@ -11582,6 +11602,8 @@ spec:
disabled:
type: boolean
interval:
description: Interval is the internal in second or minute
for the health check to run like 60s for 60 seconds
type: string
timeout:
type: string
+2 -1
View File
@@ -988,8 +988,9 @@ type BucketHealthCheckSpec struct {
type HealthCheckSpec struct {
// +optional
Disabled bool `json:"disabled,omitempty"`
// Interval is the internal in second or minute for the health check to run like 60s for 60 seconds
// +optional
Interval string `json:"interval,omitempty"`
Interval *metav1.Duration `json:"interval,omitempty"`
// +optional
Timeout string `json:"timeout,omitempty"`
}
@@ -23,13 +23,14 @@ package v1
import (
rookiov1 "github.com/rook/rook/pkg/apis/rook.io/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BucketHealthCheckSpec) DeepCopyInto(out *BucketHealthCheckSpec) {
*out = *in
out.Bucket = in.Bucket
in.Bucket.DeepCopyInto(&out.Bucket)
if in.LivenessProbe != nil {
in, out := &in.LivenessProbe, &out.LivenessProbe
*out = new(rookiov1.ProbeSpec)
@@ -302,7 +303,7 @@ func (in *CephCluster) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CephClusterHealthCheckSpec) DeepCopyInto(out *CephClusterHealthCheckSpec) {
*out = *in
out.DaemonHealth = in.DaemonHealth
in.DaemonHealth.DeepCopyInto(&out.DaemonHealth)
if in.LivenessProbe != nil {
in, out := &in.LivenessProbe, &out.LivenessProbe
*out = make(map[rookiov1.KeyType]*rookiov1.ProbeSpec, len(*in))
@@ -1242,9 +1243,9 @@ func (in *CrashCollectorSpec) DeepCopy() *CrashCollectorSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DaemonHealthSpec) DeepCopyInto(out *DaemonHealthSpec) {
*out = *in
out.Status = in.Status
out.Monitor = in.Monitor
out.ObjectStorageDaemon = in.ObjectStorageDaemon
in.Status.DeepCopyInto(&out.Status)
in.Monitor.DeepCopyInto(&out.Monitor)
in.ObjectStorageDaemon.DeepCopyInto(&out.ObjectStorageDaemon)
return
}
@@ -1502,6 +1503,11 @@ func (in *GatewaySpec) DeepCopy() *GatewaySpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *HealthCheckSpec) DeepCopyInto(out *HealthCheckSpec) {
*out = *in
if in.Interval != nil {
in, out := &in.Interval, &out.Interval
*out = new(metav1.Duration)
**out = **in
}
return
}
@@ -1610,7 +1616,7 @@ func (in *MgrSpec) DeepCopy() *MgrSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MirrorHealthCheckSpec) DeepCopyInto(out *MirrorHealthCheckSpec) {
*out = *in
out.Mirror = in.Mirror
in.Mirror.DeepCopyInto(&out.Mirror)
return
}
@@ -2010,7 +2016,7 @@ func (in *PoolSpec) DeepCopyInto(out *PoolSpec) {
}
}
in.Mirroring.DeepCopyInto(&out.Mirroring)
out.StatusCheck = in.StatusCheck
in.StatusCheck.DeepCopyInto(&out.StatusCheck)
in.Quotas.DeepCopyInto(&out.Quotas)
return
}
+13 -17
View File
@@ -37,7 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
var (
// defaultStatusCheckInterval is the interval to check the status of the ceph cluster
defaultStatusCheckInterval = 60 * time.Second
)
@@ -46,7 +46,7 @@ const (
type cephStatusChecker struct {
context *clusterd.Context
clusterInfo *cephclient.ClusterInfo
interval time.Duration
interval *time.Duration
client client.Client
isExternal bool
}
@@ -56,30 +56,26 @@ func newCephStatusChecker(context *clusterd.Context, clusterInfo *cephclient.Clu
c := &cephStatusChecker{
context: context,
clusterInfo: clusterInfo,
interval: defaultStatusCheckInterval,
interval: &defaultStatusCheckInterval,
client: context.Client,
isExternal: clusterSpec.External.Enable,
}
// allow overriding the check interval with an env var on the operator
// Keep the existing behavior
var checkInterval string
var checkInterval *time.Duration
checkIntervalCRSetting := clusterSpec.HealthCheck.DaemonHealth.Status.Interval
checkIntervalEnv := os.Getenv("ROOK_CEPH_STATUS_CHECK_INTERVAL")
if checkIntervalEnv != "" {
checkInterval = checkIntervalEnv
}
if checkIntervalCRSetting != "" && checkIntervalEnv == "" {
checkInterval = checkIntervalCRSetting
}
// Set duration
if checkInterval != "" {
if duration, err := time.ParseDuration(checkInterval); err == nil {
logger.Infof("ceph status check interval is %s", checkInterval)
c.interval = duration
if duration, err := time.ParseDuration(checkIntervalEnv); err == nil {
checkInterval = &duration
}
} else if checkIntervalCRSetting != nil {
checkInterval = &checkIntervalCRSetting.Duration
}
if checkInterval != nil {
logger.Infof("ceph status check interval is %s", checkInterval.String())
c.interval = checkInterval
}
return c
@@ -96,7 +92,7 @@ func (c *cephStatusChecker) checkCephStatus(stopCh chan struct{}) {
logger.Infof("stopping monitoring of ceph status")
return
case <-time.After(c.interval):
case <-time.After(*c.interval):
c.checkStatus()
}
}
+3 -3
View File
@@ -142,9 +142,9 @@ func TestNewCephStatusChecker(t *testing.T) {
args args
want *cephStatusChecker
}{
{"default-interval", args{c, clusterInfo, &cephv1.ClusterSpec{}}, &cephStatusChecker{c, clusterInfo, defaultStatusCheckInterval, c.Client, false}},
{"10s-interval", args{c, clusterInfo, &cephv1.ClusterSpec{HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Status: cephv1.HealthCheckSpec{Interval: "10s"}}}}}, &cephStatusChecker{c, clusterInfo, time10s, c.Client, false}},
{"10s-interval-external", args{c, clusterInfo, &cephv1.ClusterSpec{External: cephv1.ExternalSpec{Enable: true}, HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Status: cephv1.HealthCheckSpec{Interval: "10s"}}}}}, &cephStatusChecker{c, clusterInfo, time10s, c.Client, true}},
{"default-interval", args{c, clusterInfo, &cephv1.ClusterSpec{}}, &cephStatusChecker{c, clusterInfo, &defaultStatusCheckInterval, c.Client, false}},
{"10s-interval", args{c, clusterInfo, &cephv1.ClusterSpec{HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Status: cephv1.HealthCheckSpec{Interval: &metav1.Duration{Duration: time10s}}}}}}, &cephStatusChecker{c, clusterInfo, &time10s, c.Client, false}},
{"10s-interval-external", args{c, clusterInfo, &cephv1.ClusterSpec{External: cephv1.ExternalSpec{Enable: true}, HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Status: cephv1.HealthCheckSpec{Interval: &metav1.Duration{Duration: time10s}}}}}}, &cephStatusChecker{c, clusterInfo, &time10s, c.Client, true}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
+3 -5
View File
@@ -61,11 +61,9 @@ func NewHealthChecker(monCluster *Cluster) *HealthChecker {
checkInterval := monCluster.spec.HealthCheck.DaemonHealth.Monitor.Interval
// allow overriding the check interval
if checkInterval != "" {
if duration, err := time.ParseDuration(checkInterval); err == nil {
logger.Infof("ceph mon status in namespace %q check interval %q", monCluster.Namespace, checkInterval)
h.interval = duration
}
if checkInterval != nil {
logger.Infof("ceph mon status in namespace %q check interval %q", monCluster.Namespace, checkInterval.Duration.String())
h.interval = checkInterval.Duration
}
return h
+1 -1
View File
@@ -385,7 +385,7 @@ func TestAddOrRemoveExternalMonitor(t *testing.T) {
func TestNewHealthChecker(t *testing.T) {
c := &Cluster{spec: cephv1.ClusterSpec{HealthCheck: cephv1.CephClusterHealthCheckSpec{}}}
time10s, _ := time.ParseDuration("10s")
c10s := &Cluster{spec: cephv1.ClusterSpec{HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Monitor: cephv1.HealthCheckSpec{Interval: "10s"}}}}}
c10s := &Cluster{spec: cephv1.ClusterSpec{HealthCheck: cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{Monitor: cephv1.HealthCheckSpec{Interval: &metav1.Duration{Duration: time10s}}}}}}
type args struct {
monCluster *Cluster
+6 -8
View File
@@ -46,7 +46,7 @@ type OSDHealthMonitor struct {
context *clusterd.Context
clusterInfo *client.ClusterInfo
removeOSDsIfOUTAndSafeToRemove bool
interval time.Duration
interval *time.Duration
}
// NewOSDHealthMonitor instantiates OSD monitoring
@@ -55,16 +55,14 @@ func NewOSDHealthMonitor(context *clusterd.Context, clusterInfo *client.ClusterI
context: context,
clusterInfo: clusterInfo,
removeOSDsIfOUTAndSafeToRemove: removeOSDsIfOUTAndSafeToRemove,
interval: defaultHealthCheckInterval,
interval: &defaultHealthCheckInterval,
}
// allow overriding the check interval
checkInterval := healthCheck.DaemonHealth.ObjectStorageDaemon.Interval
if checkInterval != "" {
if duration, err := time.ParseDuration(checkInterval); err == nil {
logger.Infof("ceph osd status in namespace %q check interval %q", h.clusterInfo.Namespace, checkInterval)
h.interval = duration
}
if checkInterval != nil {
logger.Infof("ceph osd status in namespace %q check interval %q", h.clusterInfo.Namespace, checkInterval.Duration.String())
h.interval = &checkInterval.Duration
}
return h
@@ -75,7 +73,7 @@ func (m *OSDHealthMonitor) Start(stopCh chan struct{}) {
for {
select {
case <-time.After(m.interval):
case <-time.After(*m.interval):
logger.Debug("checking osd processes status.")
m.checkOSDHealth()
+2 -2
View File
@@ -128,8 +128,8 @@ func TestNewOSDHealthMonitor(t *testing.T) {
args args
want *OSDHealthMonitor
}{
{"default-interval", args{c, false, cephv1.CephClusterHealthCheckSpec{}}, &OSDHealthMonitor{c, clusterInfo, false, defaultHealthCheckInterval}},
{"10s-interval", args{c, false, cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{ObjectStorageDaemon: cephv1.HealthCheckSpec{Interval: "10s"}}}}, &OSDHealthMonitor{c, clusterInfo, false, time10s}},
{"default-interval", args{c, false, cephv1.CephClusterHealthCheckSpec{}}, &OSDHealthMonitor{c, clusterInfo, false, &defaultHealthCheckInterval}},
{"10s-interval", args{c, false, cephv1.CephClusterHealthCheckSpec{DaemonHealth: cephv1.DaemonHealthSpec{ObjectStorageDaemon: cephv1.HealthCheckSpec{Interval: &metav1.Duration{Duration: time10s}}}}}, &OSDHealthMonitor{c, clusterInfo, false, &time10s}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
+14 -13
View File
@@ -29,19 +29,22 @@ import (
)
const (
s3UserHealthCheckName = "rook-ceph-internal-s3-user-checker"
s3HealthCheckBucketName = "rook-ceph-bucket-checker"
s3UserHealthCheckName = "rook-ceph-internal-s3-user-checker"
s3HealthCheckBucketName = "rook-ceph-bucket-checker"
s3HealthCheckObjectBody = "Test Rook Object Data"
s3HealthCheckObjectKey = "rookHealthCheckTestObject"
contentType = "plain/text"
)
var (
defaultHealthCheckInterval = 1 * time.Minute
s3HealthCheckObjectBody = "Test Rook Object Data"
s3HealthCheckObjectKey = "rookHealthCheckTestObject"
contentType = "plain/text"
)
// bucketChecker aggregates the mon/cluster info needed to check the health of the monitors
type bucketChecker struct {
context *clusterd.Context
objContext *Context
interval time.Duration
interval *time.Duration
serviceIP string
port string
client client.Client
@@ -54,7 +57,7 @@ func newBucketChecker(context *clusterd.Context, objContext *Context, serviceIP,
c := &bucketChecker{
context: context,
objContext: objContext,
interval: defaultHealthCheckInterval,
interval: &defaultHealthCheckInterval,
serviceIP: serviceIP,
port: port,
namespacedName: namespacedName,
@@ -64,11 +67,9 @@ func newBucketChecker(context *clusterd.Context, objContext *Context, serviceIP,
// allow overriding the check interval
checkInterval := healthCheckSpec.Bucket.Interval
if checkInterval != "" {
if duration, err := time.ParseDuration(checkInterval); err == nil {
logger.Infof("ceph rgw status check interval for object store %q is %q", namespacedName.Name, checkInterval)
c.interval = duration
}
if checkInterval != nil {
logger.Infof("ceph rgw status check interval for object store %q is %q", namespacedName.Name, checkInterval.Duration.String())
c.interval = &checkInterval.Duration
}
return c
@@ -92,7 +93,7 @@ func (c *bucketChecker) checkObjectStore(stopCh chan struct{}) {
logger.Infof("stopping monitoring of rgw endpoints for object store %q", c.namespacedName.Name)
return
case <-time.After(c.interval):
case <-time.After(*c.interval):
logger.Debugf("checking rgw health of object store %q", c.namespacedName.Name)
err := c.checkObjectStoreHealth()
if err != nil {
+7 -9
View File
@@ -26,13 +26,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
var (
defaultHealthCheckInterval = 1 * time.Minute
)
type mirrorChecker struct {
context *clusterd.Context
interval time.Duration
interval *time.Duration
client client.Client
clusterInfo *cephclient.ClusterInfo
namespacedName types.NamespacedName
@@ -44,7 +44,7 @@ type mirrorChecker struct {
func newMirrorChecker(context *clusterd.Context, client client.Client, clusterInfo *cephclient.ClusterInfo, namespacedName types.NamespacedName, poolSpec *cephv1.PoolSpec, poolName string) *mirrorChecker {
c := &mirrorChecker{
context: context,
interval: defaultHealthCheckInterval,
interval: &defaultHealthCheckInterval,
clusterInfo: clusterInfo,
namespacedName: namespacedName,
client: client,
@@ -54,11 +54,9 @@ func newMirrorChecker(context *clusterd.Context, client client.Client, clusterIn
// allow overriding the check interval
checkInterval := poolSpec.StatusCheck.Mirror.Interval
if checkInterval != "" {
if duration, err := time.ParseDuration(checkInterval); err == nil {
logger.Infof("pool mirroring status check interval for block pool %q is %q", namespacedName.Name, checkInterval)
c.interval = duration
}
if checkInterval != nil {
logger.Infof("pool mirroring status check interval for block pool %q is %q", namespacedName.Name, checkInterval.Duration.String())
c.interval = &checkInterval.Duration
}
return c
@@ -79,7 +77,7 @@ func (c *mirrorChecker) checkMirroring(stopCh chan struct{}) {
logger.Infof("stopping monitoring pool mirroring status %q", c.namespacedName.Name)
return
case <-time.After(c.interval):
case <-time.After(*c.interval):
logger.Debugf("checking pool mirroring status %q", c.namespacedName.Name)
err := c.checkMirroringHealth()
if err != nil {