[camel-k] branch master updated (9b5bc43 -> 7f24272)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[camel-k] branch master updated (9b5bc43 -> 7f24272)

nferraro
This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.


    from 9b5bc43  Fix #1036: fix linter
     new d1e8e1a  Fix #1048: use container mode only when no other mechanism is available
     new 7f24272  Fix #1048: fix current user lookup logic for places where the current userid is unknown

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 e2e/tekton_test.go   |  2 +-
 e2e/test_support.go  | 11 +++++++++--
 pkg/client/client.go | 56 +++++++++++++++++++++++++++++++++++++++++-----------
 3 files changed, 54 insertions(+), 15 deletions(-)

Reply | Threaded
Open this post in threaded view
|

[camel-k] 01/02: Fix #1048: use container mode only when no other mechanism is available

nferraro
This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d1e8e1a5af42578683f92be7022e088af3f72ffa
Author: Nicola Ferraro <[hidden email]>
AuthorDate: Tue Nov 12 00:57:24 2019 +0100

    Fix #1048: use container mode only when no other mechanism is available
---
 e2e/tekton_test.go   |  2 +-
 e2e/test_support.go  | 11 +++++++++--
 pkg/client/client.go | 21 +++++++++++++++------
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/e2e/tekton_test.go b/e2e/tekton_test.go
index dd4d7dc..fbb08d8 100644
--- a/e2e/tekton_test.go
+++ b/e2e/tekton_test.go
@@ -38,7 +38,7 @@ func TestTektonLikeBehavior(t *testing.T) {
  Expect(createOperatorRoleBinding(ns)).Should(BeNil())
 
  Eventually(operatorPod(ns)).Should(BeNil())
- Expect(createKamelPod(ns, "tekton-task", "install")).Should(BeNil())
+ Expect(createKamelPod(ns, "tekton-task", "install", "--skip-cluster-setup")).Should(BeNil())
 
  Eventually(operatorPod(ns)).ShouldNot(BeNil())
  })
diff --git a/e2e/test_support.go b/e2e/test_support.go
index d4cec56..f9a7e3b 100644
--- a/e2e/test_support.go
+++ b/e2e/test_support.go
@@ -445,8 +445,15 @@ func createOperatorServiceAccount(ns string) error {
  return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-service-account.yaml")
 }
 
-func createOperatorRole(ns string) error {
- return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-openshift.yaml")
+func createOperatorRole(ns string) (err error) {
+ var oc bool
+ if oc, err = openshift.IsOpenShift(testClient); err != nil {
+ panic(err)
+ }
+ if oc {
+ return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-openshift.yaml")
+ }
+ return install.Resource(testContext, testClient, ns, install.IdentityResourceCustomizer, "operator-role-kubernetes.yaml")
 }
 
 func createOperatorRoleBinding(ns string) error {
diff --git a/pkg/client/client.go b/pkg/client/client.go
index dd0f06d..466d400 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -136,7 +136,7 @@ func FromManager(manager manager.Manager) (Client, error) {
 func initialize(kubeconfig string) {
  if kubeconfig == "" {
  // skip out-of-cluster initialization if inside the container
- if kc, err := runningInKubernetesContainer(); kc && err == nil {
+ if kc, err := shouldUseContainerMode(); kc && err == nil {
  return
  } else if err != nil {
  logrus.Errorf("could not determine if running in a container: %v", err)
@@ -158,7 +158,7 @@ func getDefaultKubeConfigFile() string {
 // GetCurrentNamespace --
 func GetCurrentNamespace(kubeconfig string) (string, error) {
  if kubeconfig == "" {
- kubeContainer, err := runningInKubernetesContainer()
+ kubeContainer, err := shouldUseContainerMode()
  if err != nil {
  return "", err
  }
@@ -194,12 +194,21 @@ func GetCurrentNamespace(kubeconfig string) (string, error) {
  return ns, err
 }
 
-func runningInKubernetesContainer() (bool, error) {
- _, err := os.Stat(inContainerNamespaceFile)
- if os.IsNotExist(err) {
+func shouldUseContainerMode() (bool, error) {
+ // When kube config is set, container mode is not used
+ if os.Getenv(k8sutil.KubeConfigEnvVar) != "" {
  return false, nil
  }
- return true, err
+ // Use container mode only when the kubeConfigFile does not exist and the container namespace file is present
+ _, err := os.Stat(getDefaultKubeConfigFile())
+ if os.IsNotExist(err) {
+ _, err := os.Stat(inContainerNamespaceFile)
+ if os.IsNotExist(err) {
+ return false, nil
+ }
+ return true, err
+ }
+ return false, nil
 }
 
 func getNamespaceFromKubernetesContainer() (string, error) {

Reply | Threaded
Open this post in threaded view
|

[camel-k] 02/02: Fix #1048: fix current user lookup logic for places where the current userid is unknown

nferraro
In reply to this post by nferraro
This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 7f24272846e42c48b40371a5da19cd4f2ad817b3
Author: Nicola Ferraro <[hidden email]>
AuthorDate: Wed Nov 13 10:21:57 2019 +0100

    Fix #1048: fix current user lookup logic for places where the current userid is unknown
---
 pkg/client/client.go | 39 +++++++++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/pkg/client/client.go b/pkg/client/client.go
index 466d400..d5fea7f 100644
--- a/pkg/client/client.go
+++ b/pkg/client/client.go
@@ -141,18 +141,21 @@ func initialize(kubeconfig string) {
  } else if err != nil {
  logrus.Errorf("could not determine if running in a container: %v", err)
  }
-
- kubeconfig = getDefaultKubeConfigFile()
+ var err error
+ kubeconfig, err = getDefaultKubeConfigFile()
+ if err != nil {
+ panic(err)
+ }
  }
  os.Setenv(k8sutil.KubeConfigEnvVar, kubeconfig)
 }
 
-func getDefaultKubeConfigFile() string {
+func getDefaultKubeConfigFile() (string, error) {
  usr, err := user.Current()
  if err != nil {
- panic(err) // TODO handle error
+ return "", err
  }
- return filepath.Join(usr.HomeDir, ".kube", "config")
+ return filepath.Join(usr.HomeDir, ".kube", "config"), nil
 }
 
 // GetCurrentNamespace --
@@ -167,7 +170,11 @@ func GetCurrentNamespace(kubeconfig string) (string, error) {
  }
  }
  if kubeconfig == "" {
- kubeconfig = getDefaultKubeConfigFile()
+ var err error
+ kubeconfig, err = getDefaultKubeConfigFile()
+ if err != nil {
+ logrus.Errorf("Cannot get information about current user: %v", err)
+ }
  }
  if kubeconfig == "" {
  return "default", nil
@@ -200,8 +207,24 @@ func shouldUseContainerMode() (bool, error) {
  return false, nil
  }
  // Use container mode only when the kubeConfigFile does not exist and the container namespace file is present
- _, err := os.Stat(getDefaultKubeConfigFile())
- if os.IsNotExist(err) {
+ userUnknown := false
+ configFile, err := getDefaultKubeConfigFile()
+ if err != nil {
+ _, userUnknown = err.(user.UnknownUserIdError)
+ if !userUnknown {
+ return false, err
+ }
+ }
+ configFilePresent := true
+ if !userUnknown {
+ _, err := os.Stat(configFile)
+ if err != nil && os.IsNotExist(err) {
+ configFilePresent = false
+ } else if err != nil {
+ return false, err
+ }
+ }
+ if userUnknown || !configFilePresent {
  _, err := os.Stat(inContainerNamespaceFile)
  if os.IsNotExist(err) {
  return false, nil