Skip to content

Commit

Permalink
fix: fix go lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ruquanzhao committed Dec 18, 2024
1 parent f768a2a commit 0a217d2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions pkg/core/manager/insight/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

const (
PodStatusRunning = "Running"
PodStatusTerminated = "Terminated"
PodStatusUnknown = "Unknown"
PodStatusWaiting = "Waiting"
)

// GetDetailsForCluster returns ClusterDetail object for a given cluster
func (i *InsightManager) GetDetailsForCluster(ctx context.Context, client *multicluster.MultiClusterClient, name string) (*ClusterDetail, error) {
serverVersion, err := client.ClientSet.DiscoveryClient.ServerVersion()
Expand Down Expand Up @@ -217,35 +224,35 @@ func (i *InsightManager) GetResourceGroupSummary(ctx context.Context, client *mu
func GetPodStatus(obj map[string]any) string {
containerStatuses, found, err := unstructured.NestedSlice(obj, "status", "containerStatuses")
if err != nil || !found || len(containerStatuses) == 0 {
return "Unknown"
return PodStatusUnknown
}
firstContainer, ok := containerStatuses[0].(map[string]any)
if !ok {
return "Unknown"
return PodStatusUnknown
}
state, found := firstContainer["state"]
if !found {
return "Unknown"
return PodStatusUnknown
}
stateMap, ok := state.(map[string]interface{})
if !ok {
return "Unknown"
return PodStatusUnknown
}
if stateMap["running"] != nil {
return "Running"
return PodStatusRunning
}
if stateMap["waiting"] != nil {
waitMap, ok := stateMap["waiting"].(map[string]any)
if !ok {
return "Waiting"
return PodStatusWaiting
}
if reason, ok := waitMap["reason"].(string); ok && reason != "" {
return reason
}
return "Waiting"
return PodStatusWaiting
}
if stateMap["terminated"] != nil {
return "Terminated"
return PodStatusTerminated
}
return "Unknown"
return PodStatusUnknown
}

0 comments on commit 0a217d2

Please sign in to comment.