mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2026-01-25 14:54:20 +00:00
* chore: analyzer and ai interfacing Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: backend variable for aiProvider in cmd Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: changed folders for analyzers Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * chore: renamed analyzers Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: fixed ingress tests after rebase Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> * fix: fixed ingress tests after rebase Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu> --------- Signed-off-by: Thomas Schuetz <thomas.schuetz@t-sc.eu>
33 lines
785 B
Go
33 lines
785 B
Go
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 FetchLatestEvent(ctx context.Context, kubernetesClient *kubernetes.Client, namespace string, name string) (*v1.Event, error) {
|
|
|
|
// get the list of events
|
|
events, err := kubernetesClient.GetClient().CoreV1().Events(namespace).List(ctx,
|
|
metav1.ListOptions{
|
|
FieldSelector: "involvedObject.name=" + 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
|
|
}
|