Skip to content

Commit b1e891f

Browse files
Merge pull request #355 from RaphaelBut/cleanup-k8s
Cleanup k8s
2 parents c67e5e2 + 8b46e78 commit b1e891f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pkg/investigations/clustermonitoringerrorbudgetburn/clustermonitoringerrorbudgetburn.go

Lines changed: 13 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

@@ -26,11 +27,23 @@ var uwmMisconfiguredSL = ocm.ServiceLog{
2627

2728
func Investigate(r *investigation.Resources) (investigation.InvestigationResult, error) {
2829
// Initialize k8s client
30+
// This would be better suited to be passend in with the investigation resources
31+
// In turn we would need to split out ccam and k8sclient, as those are tied to a cluster
32+
// Failing the cleanup call is not critical as there is garbage collection for the RBAC within MCC https://issues.redhat.com/browse/OSD-27692
33+
// We can revisit backplane-apis remediation implementation to improve this behavior, by e.g.
34+
// patching the existing RBAC etc...
2935
result := investigation.InvestigationResult{}
3036
k8scli, err := k8sclient.New(r.Cluster.ID(), r.OcmClient, r.Name)
3137
if err != nil {
3238
return result, fmt.Errorf("unable to initialize k8s cli: %w", err)
3339
}
40+
defer func() {
41+
deferErr := k8sclient.Cleanup(r.Cluster.ID(), r.OcmClient, r.Name)
42+
if deferErr != nil {
43+
logging.Error(deferErr)
44+
err = errors.Join(err, deferErr)
45+
}
46+
}()
3447

3548
// Initialize PagerDuty note writer
3649
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()

test/set_stage_env.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -euo pipefail
33

44
export VAULT_ADDR="https://vault.devshift.net"
55
export VAULT_TOKEN="$(vault login -method=oidc -token-only)"
@@ -12,5 +12,4 @@ unset VAULT_ADDR VAULT_TOKEN
1212
export CAD_EXPERIMENTAL_ENABLED=true
1313
export BACKPLANE_PROXY=http://squid.corp.redhat.com:3128
1414

15-
echo
16-
15+
set +euo pipefail

0 commit comments

Comments
 (0)