Skip to content

Commit d283d19

Browse files
committed
Remove superflous cluster does not exist checking.
1 parent acbf474 commit d283d19

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,36 +118,28 @@ func run(cmd *cobra.Command, _ []string) error {
118118

119119
precheck := precheck.ClusterStatePrecheck{}
120120
result, err := precheck.Run(builder)
121-
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil || result.StopInvestigations {
122-
return err
121+
if err != nil && strings.Contains(err.Error(), "no cluster found") {
122+
logging.Warnf("No cluster found with ID '%s'. Escalating and exiting.", clusterID)
123+
return pdClient.EscalateIncidentWithNote("CAD was unable to find the incident cluster in OCM. An alert for a non-existing cluster is unexpected. Please investigate manually.")
123124
}
124125

125126
ccamInvestigation := ccam.Investigation{}
126127
result, err = ccamInvestigation.Run(builder)
127-
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil {
128+
if err != nil {
128129
return err
129130
}
130131
updateMetrics(alertInvestigation.Name(), &result)
131132

132133
logging.Infof("Starting investigation for %s", alertInvestigation.Name())
133134
result, err = alertInvestigation.Run(builder)
134-
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil {
135+
if err != nil {
135136
return err
136137
}
137138
updateMetrics(alertInvestigation.Name(), &result)
138139

139140
return updateIncidentTitle(pdClient)
140141
}
141142

142-
// handleClusterNotFound centralizes the logic for this specific error case.
143-
func handleClusterNotFound(clusterID string, pdClient *pagerduty.SdkClient, investigationErr error) error {
144-
if investigationErr != nil && strings.Contains(investigationErr.Error(), "no cluster found") {
145-
logging.Warnf("No cluster found with ID '%s'. Escalating and exiting.", clusterID)
146-
return pdClient.EscalateIncidentWithNote("CAD was unable to find the incident cluster in OCM. An alert for a non-existing cluster is unexpected. Please investigate manually.")
147-
}
148-
return investigationErr
149-
}
150-
151143
func handleCADFailure(err error, rb *investigation.ResourceBuilderT, pdClient *pagerduty.SdkClient) {
152144
logging.Errorf("CAD investigation failed: %v", err)
153145

0 commit comments

Comments
 (0)