mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-07-16 08:25:54 +00:00
Merge branch 'main' of github.com:k8sgpt-ai/k8sgpt into feat/rs_fail
This commit is contained in:
commit
8e6b9886ea
13
README.md
13
README.md
@ -1,18 +1,11 @@
|
||||
<img src="images/logo.png" width="100px;" />
|
||||
|
||||
# k8sgpt
|
||||
|
||||
<br />
|
||||
AI Powered Kubernetes debugging for SRE, Platform and DevOps teams.
|
||||
<br />
|
||||
|
||||
<img src="images/demo2.gif" width=650px; />
|
||||
|
||||
## What is k8sgpt?
|
||||
|
||||
`k8sgpt` is a tool for scanning your kubernetes clusters, diagnosing and triaging issues in simple english.
|
||||
|
||||
It reduces the mystery of kubernetes and makes it easy to understand what is going on in your cluster.
|
||||
It has SRE experience codified into it's analyzers and helps to pull out the most relevent information to enrich it with AI.
|
||||
|
||||
<img src="images/demo2.gif" width=650px; />
|
||||
|
||||
## Usage
|
||||
|
||||
|
33
pkg/analyzer/events.go
Normal file
33
pkg/analyzer/events.go
Normal file
@ -0,0 +1,33 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func FetchLatestPodEvent(ctx context.Context, kubernetesClient *kubernetes.Client, pod *v1.Pod) (*v1.Event, error) {
|
||||
|
||||
// get the list of events
|
||||
events, err := kubernetesClient.GetClient().CoreV1().Events(pod.Namespace).List(ctx,
|
||||
metav1.ListOptions{
|
||||
FieldSelector: "involvedObject.name=" + pod.Name,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// find most recent event
|
||||
var latestEvent *v1.Event
|
||||
for _, event := range events.Items {
|
||||
if latestEvent == nil {
|
||||
latestEvent = &event
|
||||
}
|
||||
if event.LastTimestamp.After(latestEvent.LastTimestamp.Time) {
|
||||
latestEvent = &event
|
||||
}
|
||||
}
|
||||
return latestEvent, nil
|
||||
}
|
@ -46,6 +46,19 @@ func AnalyzePod(ctx context.Context, client *kubernetes.Client, aiClient *ai.Cli
|
||||
failureDetails = append(failureDetails, containerStatus.State.Waiting.Message)
|
||||
brokenPods[fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)] = failureDetails
|
||||
}
|
||||
// This represents a container that is still being created or blocked due to conditions such as OOMKilled
|
||||
if containerStatus.State.Waiting.Reason == "ContainerCreating" && pod.Status.Phase == "Pending" {
|
||||
|
||||
// parse the event log and append details
|
||||
evt, err := FetchLatestPodEvent(ctx, client, &pod)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if evt.Reason == "FailedCreatePodSandBox" {
|
||||
failureDetails = append(failureDetails, evt.Message)
|
||||
brokenPods[fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)] = failureDetails
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -96,6 +109,8 @@ func AnalyzePod(ctx context.Context, client *kubernetes.Client, aiClient *ai.Cli
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
color.Green(response)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user