Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 677bfc9

Browse files
committed
Set kube namespace properly
Signed-off-by: Guillaume Tardif <[email protected]>
1 parent 15c0b88 commit 677bfc9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kube/client/client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import (
3232

3333
// KubeClient API to access kube objects
3434
type KubeClient struct {
35-
client *kubernetes.Clientset
35+
client *kubernetes.Clientset
36+
namespace string
3637
}
3738

3839
// NewKubeClient new kubernetes client
@@ -46,8 +47,15 @@ func NewKubeClient(config genericclioptions.RESTClientGetter) (*KubeClient, erro
4647
if err != nil {
4748
return nil, err
4849
}
50+
51+
namespace, _, err := config.ToRawKubeConfigLoader().Namespace()
52+
if err != nil {
53+
return nil, err
54+
}
55+
4956
return &KubeClient{
50-
client: clientset,
57+
client: clientset,
58+
namespace: namespace,
5159
}, nil
5260
}
5361

@@ -58,7 +66,7 @@ func (kc KubeClient) GetContainers(ctx context.Context, projectName string, all
5866
fieldSelector = "status.phase=Running"
5967
}
6068

61-
pods, err := kc.client.CoreV1().Pods("").List(ctx, metav1.ListOptions{
69+
pods, err := kc.client.CoreV1().Pods(kc.namespace).List(ctx, metav1.ListOptions{
6270
LabelSelector: fmt.Sprintf("%s=%s", compose.ProjectTag, projectName),
6371
FieldSelector: fieldSelector,
6472
})

0 commit comments

Comments
 (0)