Skip to content

Commit acbf474

Browse files
committed
Move handleClusternotFound to a full function.
1 parent 8f92a91 commit acbf474

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

cadctl/cmd/investigate/investigate.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,22 @@ func run(cmd *cobra.Command, _ []string) error {
116116
// Prime the builder with information required for all investigations.
117117
builder.WithName(alertInvestigation.Name()).WithCluster(clusterID).WithPagerDutyClient(pdClient).WithOcmClient(ocmClient).WithLogger(logLevelFlag, pipelineNameEnv)
118118

119-
// handleClusterNotFound centralizes the logic for this specific error case.
120-
handleClusterNotFound := func(investigationErr error) error {
121-
if investigationErr != nil && strings.Contains(investigationErr.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.")
124-
}
125-
return investigationErr
126-
}
127-
128119
precheck := precheck.ClusterStatePrecheck{}
129120
result, err := precheck.Run(builder)
130-
if err = handleClusterNotFound(err); err != nil || result.StopInvestigations {
121+
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil || result.StopInvestigations {
131122
return err
132123
}
133124

134-
inv := ccam.Investigation{}
135-
result, err = inv.Run(builder)
136-
if err = handleClusterNotFound(err); err != nil {
125+
ccamInvestigation := ccam.Investigation{}
126+
result, err = ccamInvestigation.Run(builder)
127+
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil {
137128
return err
138129
}
139130
updateMetrics(alertInvestigation.Name(), &result)
140131

141132
logging.Infof("Starting investigation for %s", alertInvestigation.Name())
142133
result, err = alertInvestigation.Run(builder)
143-
if err = handleClusterNotFound(err); err != nil {
134+
if err = handleClusterNotFound(clusterID, pdClient, err); err != nil {
144135
return err
145136
}
146137
updateMetrics(alertInvestigation.Name(), &result)

0 commit comments

Comments
 (0)