|
|
@@ -1211,23 +1211,46 @@ func (a *Accesses) GetInstallInfo(w http.ResponseWriter, r *http.Request, _ http
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
|
|
|
- pods, err := a.KubeClientSet.CoreV1().Pods(env.GetKubecostNamespace()).List(context.Background(), metav1.ListOptions{
|
|
|
- LabelSelector: "app=cost-analyzer",
|
|
|
- FieldSelector: "status.phase=Running",
|
|
|
- Limit: 1,
|
|
|
- })
|
|
|
+ containers, err := GetKubecostContainers(a.KubeClientSet)
|
|
|
if err != nil {
|
|
|
writeErrorResponse(w, 500, fmt.Sprintf("Unable to list pods: %s", err.Error()))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
info := InstallInfo{
|
|
|
+ Containers: containers,
|
|
|
ClusterInfo: make(map[string]string),
|
|
|
Version: version.FriendlyVersion(),
|
|
|
}
|
|
|
|
|
|
+ nodes := a.ClusterCache.GetAllNodes()
|
|
|
+ cachePods := a.ClusterCache.GetAllPods()
|
|
|
+
|
|
|
+ info.ClusterInfo["nodeCount"] = strconv.Itoa(len(nodes))
|
|
|
+ info.ClusterInfo["podCount"] = strconv.Itoa(len(cachePods))
|
|
|
+
|
|
|
+ body, err := json.Marshal(info)
|
|
|
+ if err != nil {
|
|
|
+ writeErrorResponse(w, 500, fmt.Sprintf("Error decoding pod: %s", err.Error()))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ w.Write(body)
|
|
|
+}
|
|
|
+
|
|
|
+func GetKubecostContainers(kubeClientSet kubernetes.Interface) ([]ContainerInfo, error) {
|
|
|
+ pods, err := kubeClientSet.CoreV1().Pods(env.GetKubecostNamespace()).List(context.Background(), metav1.ListOptions{
|
|
|
+ LabelSelector: "app=cost-analyzer",
|
|
|
+ FieldSelector: "status.phase=Running",
|
|
|
+ Limit: 1,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("failed to query kubernetes client for kubecost pods: %s", err)
|
|
|
+ }
|
|
|
+
|
|
|
// If we have zero pods either something is weird with the install since the app selector is not exposed in the helm
|
|
|
// chart or more likely we are running locally - in either case Images field will return as null
|
|
|
+ var containers []ContainerInfo
|
|
|
if len(pods.Items) > 0 {
|
|
|
for _, pod := range pods.Items {
|
|
|
for _, container := range pod.Spec.Containers {
|
|
|
@@ -1236,24 +1259,12 @@ func (a *Accesses) GetInstallInfo(w http.ResponseWriter, r *http.Request, _ http
|
|
|
Image: container.Image,
|
|
|
StartTime: pod.Status.StartTime.String(),
|
|
|
}
|
|
|
- info.Containers = append(info.Containers, c)
|
|
|
+ containers = append(containers, c)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- nodes := a.ClusterCache.GetAllNodes()
|
|
|
- cachePods := a.ClusterCache.GetAllPods()
|
|
|
-
|
|
|
- info.ClusterInfo["nodeCount"] = strconv.Itoa(len(nodes))
|
|
|
- info.ClusterInfo["podCount"] = strconv.Itoa(len(cachePods))
|
|
|
-
|
|
|
- body, err := json.Marshal(info)
|
|
|
- if err != nil {
|
|
|
- writeErrorResponse(w, 500, fmt.Sprintf("Error decoding pod: %s", err.Error()))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- w.Write(body)
|
|
|
+ return containers, nil
|
|
|
}
|
|
|
|
|
|
// logsFor pulls the logs for a specific pod, namespace, and container
|