You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/12/18 10:30:09 UTC
[camel-k] 09/10: Fixed a not configured k8s client being used in
commands preRun preventing testability and possibly causing some unwanted
effects in some scenarios like loading commands configs/flags from env vars
and config files
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 46916233a89ce5f551ac8e637129c5eea2d18a55
Author: Andrea Tarocchi <an...@gmail.com>
AuthorDate: Tue Dec 17 14:06:50 2019 +0100
Fixed a not configured k8s client being used in commands preRun
preventing testability and possibly causing some unwanted effects
in some scenarios like loading commands configs/flags from env vars and config files
---
pkg/client/client.go | 5 +++++
pkg/cmd/root.go | 7 ++++++-
pkg/util/test/client.go | 4 ++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/pkg/client/client.go b/pkg/client/client.go
index 55ddf41..2fcb141 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -53,6 +53,7 @@ type Client interface {
kubernetes.Interface
GetScheme() *runtime.Scheme
GetConfig() *rest.Config
+ GetCurrentNamespace(kubeConfig string) (string, error)
}
// Injectable identifies objects that can receive a Client
@@ -80,6 +81,10 @@ func (c *defaultClient) GetConfig() *rest.Config {
return c.config
}
+func (c *defaultClient) GetCurrentNamespace(kubeConfig string) (string, error) {
+ return GetCurrentNamespace(kubeConfig)
+}
+
// NewOutOfClusterClient creates a new k8s client that can be used from outside the cluster
func NewOutOfClusterClient(kubeconfig string) (Client, error) {
initialize(kubeconfig)
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index cc8473d..c1ed396 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -119,7 +119,12 @@ func addKamelSubcommands(cmd cobra.Command, options RootCmdOptions) *cobra.Comma
func (command *RootCmdOptions) preRun(cmd *cobra.Command, _ []string) error {
if command.Namespace == "" {
- current, err := client.GetCurrentNamespace(command.KubeConfig)
+ var current string
+ client, err := command.GetCmdClient()
+ if err != nil {
+ return errors.Wrap(err, "cannot get command client")
+ }
+ current, err = client.GetCurrentNamespace(command.KubeConfig)
if err != nil {
return errors.Wrap(err, "cannot get current namespace")
}
diff --git a/pkg/util/test/client.go b/pkg/util/test/client.go
index 47d1bcd..d3df07b 100644
--- a/pkg/util/test/client.go
+++ b/pkg/util/test/client.go
@@ -61,3 +61,7 @@ func (c *FakeClient) GetScheme() *runtime.Scheme {
func (c *FakeClient) GetConfig() *rest.Config {
return nil
}
+
+func (c *FakeClient) GetCurrentNamespace(kubeConfig string) (string, error) {
+ return "", nil
+}