mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2026-01-25 23:03:57 +00:00
* feat: added namespace filter Signed-off-by: AlexsJones <alexsimonjones@gmail.com> * chore: Moved the explain bool out Signed-off-by: AlexsJones <alexsimonjones@gmail.com> --------- Signed-off-by: AlexsJones <alexsimonjones@gmail.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package analyzer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/util"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func AnalyzePersistentVolumeClaim(ctx context.Context, config *AnalysisConfiguration, client *kubernetes.Client, aiClient ai.IAI, analysisResults *[]Analysis) error {
|
|
|
|
// search all namespaces for pods that are not running
|
|
list, err := client.GetClient().CoreV1().PersistentVolumeClaims(config.Namespace).List(ctx, metav1.ListOptions{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var preAnalysis = map[string]PreAnalysis{}
|
|
|
|
for _, pvc := range list.Items {
|
|
var failures []string
|
|
|
|
// Check for empty rs
|
|
if pvc.Status.Phase == "Pending" {
|
|
|
|
// parse the event log and append details
|
|
evt, err := FetchLatestPvcEvent(ctx, client, &pvc)
|
|
if err != nil || evt == nil {
|
|
continue
|
|
}
|
|
if evt.Reason == "ProvisioningFailed" && evt.Message != "" {
|
|
failures = append(failures, evt.Message)
|
|
}
|
|
}
|
|
if len(failures) > 0 {
|
|
preAnalysis[fmt.Sprintf("%s/%s", pvc.Namespace, pvc.Name)] = PreAnalysis{
|
|
PersistentVolumeClaim: pvc,
|
|
FailureDetails: failures,
|
|
}
|
|
}
|
|
}
|
|
|
|
for key, value := range preAnalysis {
|
|
var currentAnalysis = Analysis{
|
|
Kind: "PersistentVolumeClaim",
|
|
Name: key,
|
|
Error: value.FailureDetails,
|
|
}
|
|
|
|
parent, _ := util.GetParent(client, value.PersistentVolumeClaim.ObjectMeta)
|
|
currentAnalysis.ParentObject = parent
|
|
*analysisResults = append(*analysisResults, currentAnalysis)
|
|
}
|
|
|
|
return nil
|
|
}
|