Browse Source

Merge pull request #696 from oshtman/0.3.0-show-selected-namespace-pods-in-status-and-metric-tabs

[0.3.0] Show selected namespace pods in status and metric tabs
abelanger5 5 years ago
parent
commit
cdf9aad548

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricsSection.tsx

@@ -369,6 +369,7 @@ export default class MetricsSection extends Component<PropsType, StateType> {
         "<token>",
         {
           cluster_id: currentCluster.id,
+          namespace: selectedController?.metadata?.namespace,
           selectors,
         },
         {

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/expanded-chart/status/ControllerTab.tsx

@@ -59,6 +59,7 @@ export default class ControllerTab extends Component<PropsType, StateType> {
         "<token>",
         {
           cluster_id: currentCluster.id,
+          namespace: controller?.metadata?.namespace,
           selectors,
         },
         {

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -472,6 +472,7 @@ const getJobPods = baseApi<
 const getMatchingPods = baseApi<
   {
     cluster_id: number;
+    namespace: string;
     selectors: string[];
   },
   { id: number }

+ 2 - 2
internal/kubernetes/agent.go

@@ -340,9 +340,9 @@ func (a *Agent) GetCronJob(c grapher.Object) (*batchv1beta1.CronJob, error) {
 }
 
 // GetPodsByLabel retrieves pods with matching labels
-func (a *Agent) GetPodsByLabel(selector string) (*v1.PodList, error) {
+func (a *Agent) GetPodsByLabel(selector string, namespace string) (*v1.PodList, error) {
 	// Search in all namespaces for matching pods
-	return a.Clientset.CoreV1().Pods("").List(
+	return a.Clientset.CoreV1().Pods(namespace).List(
 		context.TODO(),
 		metav1.ListOptions{
 			LabelSelector: selector,

+ 2 - 1
server/api/k8s_handler.go

@@ -664,9 +664,10 @@ func (app *App) HandleListPods(w http.ResponseWriter, r *http.Request) {
 		agent, err = kubernetes.GetAgentOutOfClusterConfig(form.OutOfClusterConfig)
 	}
 
+	namespace := vals.Get("namespace")
 	pods := []v1.Pod{}
 	for _, selector := range vals["selectors"] {
-		podsList, err := agent.GetPodsByLabel(selector)
+		podsList, err := agent.GetPodsByLabel(selector, namespace)
 
 		if err != nil {
 			app.handleErrorFormValidation(err, ErrK8sValidate, w)

+ 2 - 1
server/api/release_handler.go

@@ -549,7 +549,8 @@ func (app *App) HandleGetReleaseAllPods(w http.ResponseWriter, r *http.Request)
 			selectors = append(selectors, key+"="+val)
 		}
 
-		podList, err := k8sAgent.GetPodsByLabel(strings.Join(selectors, ","))
+		namespace := vals.Get("namespace")
+		podList, err := k8sAgent.GetPodsByLabel(strings.Join(selectors, ","), namespace)
 
 		if err != nil {
 			app.handleErrorDataRead(err, w)