-
Notifications
You must be signed in to change notification settings - Fork 34
/
remove_lb_scrape_config.go
35 lines (28 loc) · 1.3 KB
/
remove_lb_scrape_config.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
package usecases
import (
"context"
"fmt"
"path/filepath"
"github.com/berops/claudie/internal/utils"
"github.com/berops/claudie/proto/pb"
scrapeconfig "github.com/berops/claudie/services/kuber/server/domain/utils/scrape-config"
)
// RemoveLBScrapeConfig deletes the Kubernetes secret containing Prometheus scrape config related to
// the LB clusters attached to given K8s cluster.
func (u *Usecases) RemoveLBScrapeConfig(ctx context.Context, request *pb.RemoveLBScrapeConfigRequest) (*pb.RemoveLBScrapeConfigResponse, error) {
tempClusterID := fmt.Sprintf("%s-%s", request.Cluster.ClusterInfo.Name, utils.CreateHash(5))
clusterID := utils.GetClusterID(request.Cluster.ClusterInfo)
clusterDir := filepath.Join(outputDir, tempClusterID)
logger := utils.CreateLoggerWithClusterName(clusterID)
logger.Info().Msgf("Deleting load balancer scrape-config")
sc := scrapeconfig.ScrapeConfig{
Cluster: request.GetCluster(),
Directory: clusterDir,
}
if err := sc.RemoveLBScrapeConfig(); err != nil {
logger.Err(err).Msgf("Error while removing scrape config for Loadbalancer nodes")
return nil, fmt.Errorf("error while removing old loadbalancer scrape-config for %s : %w", clusterID, err)
}
logger.Info().Msgf("Load balancer scrape-config successfully deleted")
return &pb.RemoveLBScrapeConfigResponse{}, nil
}