-
Notifications
You must be signed in to change notification settings - Fork 142
/
status.go
90 lines (73 loc) · 2.52 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package status
import (
"fmt"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/cloud-credential-operator/pkg/operator/constants"
"github.com/openshift/cloud-credential-operator/pkg/operator/status"
"github.com/openshift/cloud-credential-operator/pkg/operator/utils"
)
type SecretStatusHandler struct {
kubeClient client.Client
}
func NewSecretStatusHandler(kubeClient client.Client) *SecretStatusHandler {
return &SecretStatusHandler{
kubeClient: kubeClient,
}
}
var _ status.Handler = &SecretStatusHandler{}
func (s *SecretStatusHandler) GetConditions(logger log.FieldLogger) ([]configv1.ClusterOperatorStatusCondition, error) {
conditions := []configv1.ClusterOperatorStatusCondition{}
mode, conflict, err := utils.GetOperatorConfiguration(s.kubeClient, logger)
if err != nil {
return conditions, err
}
// shouldn't happen with the server-side enforcement of the CRDs enum specification
if !utils.IsValidMode(mode) {
conditions = append(conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorDegraded,
Status: configv1.ConditionTrue,
Reason: constants.StatusModeInvalid,
Message: fmt.Sprintf("operator mode of %s is invalid", mode),
})
} else if conflict {
conditions = append(conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorDegraded,
Status: configv1.ConditionTrue,
Reason: constants.StatusModeMismatch,
Message: fmt.Sprintf("legacy configmap disabled setting conflicts with operator config mode of %s",
mode),
})
}
return conditions, nil
}
func (s *SecretStatusHandler) GetRelatedObjects(logger log.FieldLogger) ([]configv1.ObjectReference, error) {
related := []configv1.ObjectReference{
{
Group: operatorv1.GroupName,
Resource: "cloudcredentials",
Name: constants.CloudCredOperatorConfig,
},
}
// check for the legacy configmap
cm, err := utils.GetLegacyConfigMap(s.kubeClient)
if err != nil && !errors.IsNotFound(err) {
logger.WithError(err).Error("failed fetching legacy configmap")
return related, err
}
// add the configmap if it exists
if !errors.IsNotFound(err) {
related = append(related, configv1.ObjectReference{
Resource: "configmap",
Namespace: cm.Namespace,
Name: cm.Name,
})
}
return related, nil
}
func (s *SecretStatusHandler) Name() string {
return constants.SecretAnnotatorControllerName
}