Skip to content

Commit a0f0789

Browse files
committed
Add the cleanup call to backplane-api to delete investigation RBAC
After the investigation has ended we need to cleanup the created RBAC. We will have garbage collection via managed-cluster-config in case this fails. One can also delete it manually with backplane-cli.
1 parent c67e5e2 commit a0f0789

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/investigations/clustermonitoringerrorbudgetburn/clustermonitoringerrorbudgetburn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package clustermonitoringerrorbudgetburn
33

44
import (
55
"context"
6+
"errors"
67
"fmt"
78
"strings"
89

@@ -31,6 +32,13 @@ func Investigate(r *investigation.Resources) (investigation.InvestigationResult,
3132
if err != nil {
3233
return result, fmt.Errorf("unable to initialize k8s cli: %w", err)
3334
}
35+
defer func() {
36+
deferErr := k8sclient.Cleanup(r.Cluster.ID(), r.OcmClient, r.Name)
37+
if deferErr != nil {
38+
logging.Error(deferErr)
39+
err = errors.Join(err, deferErr)
40+
}
41+
}()
3442

3543
// Initialize PagerDuty note writer
3644
notes := notewriter.New(r.Name, logging.RawLogger)

pkg/k8s/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ func New(clusterID string, ocmClient ocm.Client, remediation string) (client.Cli
3232
return client.New(cfg, client.Options{Scheme: scheme})
3333
}
3434

35+
func Cleanup(clusterID string, ocmClient ocm.Client, remediation string) error {
36+
backplaneURL := os.Getenv("BACKPLANE_URL")
37+
if backplaneURL == "" {
38+
return fmt.Errorf("could not create new k8sclient: missing environment variable BACKPLANE_URL")
39+
}
40+
return bpremediation.DeleteRemediationWithConn(config.BackplaneConfiguration{URL: backplaneURL}, ocmClient.GetConnection(), clusterID, remediation)
41+
}
42+
3543
// Initialize all apis we need in CAD
3644
func initScheme() (*runtime.Scheme, error) {
3745
scheme := runtime.NewScheme()

0 commit comments

Comments
 (0)