From 677bfc9ce5f5f849f082e91fc8b07ec0e6ba2dd6 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 5 Feb 2021 11:09:06 +0100 Subject: [PATCH] Set kube namespace properly Signed-off-by: Guillaume Tardif --- kube/client/client.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kube/client/client.go b/kube/client/client.go index cdb0cb010..8eddc272a 100644 --- a/kube/client/client.go +++ b/kube/client/client.go @@ -32,7 +32,8 @@ import ( // KubeClient API to access kube objects type KubeClient struct { - client *kubernetes.Clientset + client *kubernetes.Clientset + namespace string } // NewKubeClient new kubernetes client @@ -46,8 +47,15 @@ func NewKubeClient(config genericclioptions.RESTClientGetter) (*KubeClient, erro if err != nil { return nil, err } + + namespace, _, err := config.ToRawKubeConfigLoader().Namespace() + if err != nil { + return nil, err + } + return &KubeClient{ - client: clientset, + client: clientset, + namespace: namespace, }, nil } @@ -58,7 +66,7 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all fieldSelector = "status.phase=Running" } - pods, err := kc.client.CoreV1().Pods("").List(ctx, metav1.ListOptions{ + pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{ LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName), FieldSelector: fieldSelector, })