Skip to content

Commit 11a0934

Browse files
committed
Set a degraded message when persistent storage is not configured
1 parent f081206 commit 11a0934

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

pkg/client/status_reporter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (r *StatusReporter) relatedObjects() []v1.ObjectReference {
6262
}
6363
}
6464

65-
func (r *StatusReporter) SetDone() error {
65+
func (r *StatusReporter) SetDone(degradedMessage string) error {
6666
co, err := r.client.Get(context.TODO(), r.clusterOperatorName, metav1.GetOptions{})
6767
if apierrors.IsNotFound(err) {
6868
co = r.newClusterOperator()
@@ -77,7 +77,7 @@ func (r *StatusReporter) SetDone() error {
7777
conditions := newConditions(co.Status, r.version, time)
7878
conditions.setCondition(v1.OperatorAvailable, v1.ConditionTrue, "Successfully rolled out the stack.", "RollOutDone", time)
7979
conditions.setCondition(v1.OperatorProgressing, v1.ConditionFalse, "", "", time)
80-
conditions.setCondition(v1.OperatorDegraded, v1.ConditionFalse, "", "", time)
80+
conditions.setCondition(v1.OperatorDegraded, v1.ConditionFalse, degradedMessage, "", time)
8181
conditions.setCondition(v1.OperatorUpgradeable, v1.ConditionTrue, "", "", time)
8282
co.Status.Conditions = conditions.entries()
8383

pkg/manifests/config.go

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ type Config struct {
3838
UserWorkloadConfiguration *UserWorkloadConfiguration `json:"-"`
3939
}
4040

41+
func (c Config) IsStorageConfigured() bool {
42+
if c.ClusterMonitoringConfiguration == nil {
43+
return false
44+
}
45+
46+
prometheusK8sConfig := c.ClusterMonitoringConfiguration.PrometheusK8sConfig
47+
if prometheusK8sConfig == nil {
48+
return false
49+
}
50+
51+
return prometheusK8sConfig.VolumeClaimTemplate != nil
52+
}
53+
4154
type ClusterMonitoringConfiguration struct {
4255
PrometheusOperatorConfig *PrometheusOperatorConfig `json:"prometheusOperator"`
4356
PrometheusK8sConfig *PrometheusK8sConfig `json:"prometheusK8s"`

pkg/operator/operator.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import (
3737
"github.com/openshift/cluster-monitoring-operator/pkg/tasks"
3838
)
3939

40+
const StorageNotConfiguredMessage = "Prometheus is running without persistent storage. As a result, upgrades and cluster disruptions can lead to data loss."
41+
4042
// InfrastructureConfig stores information about the cluster infrastructure
4143
// which is useful for the operator.
4244
type InfrastructureConfig struct {
@@ -480,8 +482,12 @@ func (o *Operator) sync(key string) error {
480482
return err
481483
}
482484

485+
var degradedConditionMessage string
486+
if !config.IsStorageConfigured() {
487+
degradedConditionMessage = StorageNotConfiguredMessage
488+
}
483489
klog.Info("Updating ClusterOperator status to done.")
484-
err = o.client.StatusReporter().SetDone()
490+
err = o.client.StatusReporter().SetDone(degradedConditionMessage)
485491
if err != nil {
486492
klog.Errorf("error occurred while setting status to done: %v", err)
487493
}

0 commit comments

Comments
 (0)