Skip to content

Commit

Permalink
Remove set namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyunchen committed Jul 16, 2018
1 parent 720c014 commit a791c5d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/kubernetes/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ func New(clientset kubernetes.Interface, namespace string) *KubeCtl {
Namespace: namespace,
}
}

func (kc *KubeCtl) SetNamespace(namespace string) {
kc.Namespace = namespace
}
2 changes: 0 additions & 2 deletions src/kubernetes/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ func TestNewKubeCtl(t *testing.T) {
kubectl := New(clientset, namespace)
assert.Equal(t, namespace, kubectl.Namespace)
assert.NotNil(t, kubectl)
// Change struct namespace field value
kubectl.SetNamespace("test")
}
4 changes: 2 additions & 2 deletions src/prometheuscontroller/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func GetContainer(sp *serviceprovider.Container, id string) (entity.ContainerMet
// command
kc := sp.KubeCtl
kc.Namespace = container.Detail.Namespace
pod, err := kc.GetPod(container.Detail.Pod, "default")
pod, err := kc.GetPod(container.Detail.Pod, container.Detail.Namespace)
if err != nil {
return entity.ContainerMetrics{}, err
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func GetService(sp *serviceprovider.Container, id string) (entity.ServiceMetrics

kc := sp.KubeCtl
kc.Namespace = service.Namespace
object, err := kc.GetService(service.ServiceName, "default")
object, err := kc.GetService(service.ServiceName, service.Namespace)
if err != nil {
return entity.ServiceMetrics{}, err
}
Expand Down
9 changes: 4 additions & 5 deletions src/prometheuscontroller/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type PrometheusExpressionTestSuite struct {
func (suite *PrometheusExpressionTestSuite) SetupSuite() {
cf := config.MustRead("../../config/local.json")
suite.sp = serviceprovider.New(cf)
suite.sp.KubeCtl.SetNamespace("monitoring")
}

func (suite *PrometheusExpressionTestSuite) TearDownSuite() {
Expand Down Expand Up @@ -69,7 +68,7 @@ func (suite *PrometheusExpressionTestSuite) TestListNodeNICs() {
}

func (suite *PrometheusExpressionTestSuite) TestGetPod() {
namespace := "default"
namespace := "monitoring"
pods, err := suite.sp.KubeCtl.GetPods(namespace)
suite.NoError(err)
podName := pods[0].GetName()
Expand All @@ -80,7 +79,7 @@ func (suite *PrometheusExpressionTestSuite) TestGetPod() {
}

func (suite *PrometheusExpressionTestSuite) TestGetContainer() {
namespace := "default"
namespace := "monitoring"
pods, err := suite.sp.KubeCtl.GetPods(namespace)
suite.NoError(err)
containerName := pods[0].Status.ContainerStatuses[0].Name
Expand All @@ -91,7 +90,7 @@ func (suite *PrometheusExpressionTestSuite) TestGetContainer() {
}

func (suite *PrometheusExpressionTestSuite) TestGetService() {
namespace := "default"
namespace := "monitoring"
services, err := suite.sp.KubeCtl.GetServices(namespace)
suite.NoError(err)
serviceName := services[0].GetName()
Expand All @@ -102,7 +101,7 @@ func (suite *PrometheusExpressionTestSuite) TestGetService() {
}

func (suite *PrometheusExpressionTestSuite) TestGetController() {
namespace := "default"
namespace := "monitoring"
deployments, err := suite.sp.KubeCtl.GetDeployments(namespace)
suite.NoError(err)
deploymentName := deployments[0].GetName()
Expand Down

0 comments on commit a791c5d

Please sign in to comment.