You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/01/07 14:25:44 UTC

[camel-k] 07/13: Fix #237: fix dev mode

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 140ec9f7496e89786f93f3595e10caed5f304ffb
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Jan 4 16:32:46 2019 +0100

    Fix #237: fix dev mode
---
 pkg/cmd/run.go                 |  3 ++-
 pkg/util/kubernetes/replace.go |  3 ++-
 pkg/util/log/pod_scraper.go    | 15 ++++++++++-----
 pkg/util/watch/watch.go        |  7 +------
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 2b35397..26def41 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -376,7 +376,8 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string)
 	if err != nil && k8serrors.IsAlreadyExists(err) {
 		existed = true
 		clone := integration.DeepCopy()
-		key, err := k8sclient.ObjectKeyFromObject(clone)
+		var key k8sclient.ObjectKey
+		key, err = k8sclient.ObjectKeyFromObject(clone)
 		if err != nil {
 			return nil, err
 		}
diff --git a/pkg/util/kubernetes/replace.go b/pkg/util/kubernetes/replace.go
index 09e6e9b..619eb9e 100644
--- a/pkg/util/kubernetes/replace.go
+++ b/pkg/util/kubernetes/replace.go
@@ -46,7 +46,8 @@ func ReplaceResource(ctx context.Context, c client.Client, res runtime.Object) e
 	err := c.Create(ctx, res)
 	if err != nil && k8serrors.IsAlreadyExists(err) {
 		existing := res.DeepCopyObject()
-		key, err := k8sclient.ObjectKeyFromObject(existing)
+		var key k8sclient.ObjectKey
+		key, err = k8sclient.ObjectKeyFromObject(existing)
 		if err != nil {
 			return err
 		}
diff --git a/pkg/util/log/pod_scraper.go b/pkg/util/log/pod_scraper.go
index 9799a17..6d74eb6 100644
--- a/pkg/util/log/pod_scraper.go
+++ b/pkg/util/log/pod_scraper.go
@@ -162,6 +162,7 @@ func (s *PodScraper) waitForPodRunning(ctx context.Context, namespace string, na
 			}
 
 			if e.Object != nil {
+				var recvPod *v1.Pod
 				if runtimeUnstructured, ok := e.Object.(runtime.Unstructured); ok {
 					unstr := unstructured.Unstructured{
 						Object: runtimeUnstructured.UnstructuredContent(),
@@ -170,14 +171,18 @@ func (s *PodScraper) waitForPodRunning(ctx context.Context, namespace string, na
 					if err != nil {
 						return "", err
 					}
-					pcopy := pod.DeepCopy()
-					if err := json.Unmarshal(jsondata, pcopy); err != nil {
+					recvPod := pod.DeepCopy()
+					if err := json.Unmarshal(jsondata, recvPod); err != nil {
 						return "", err
 					}
 
-					if pcopy.Status.Phase == v1.PodRunning {
-						return s.chooseContainer(pcopy), nil
-					}
+
+				} else if gotPod, ok := e.Object.(*v1.Pod); ok {
+					recvPod = gotPod
+				}
+
+				if recvPod != nil && recvPod.Status.Phase == v1.PodRunning {
+					return s.chooseContainer(recvPod), nil
 				}
 			} else if e.Type == watch.Deleted || e.Type == watch.Error {
 				return "", errors.New("unable to watch pod " + s.name)
diff --git a/pkg/util/watch/watch.go b/pkg/util/watch/watch.go
index 8610a13..b9e56b4 100644
--- a/pkg/util/watch/watch.go
+++ b/pkg/util/watch/watch.go
@@ -25,7 +25,6 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 	"k8s.io/apimachinery/pkg/runtime"
-	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/util/json"
 )
 
@@ -43,11 +42,7 @@ import (
 // This function blocks until the handler function returns true or either the events channel or the context is closed.
 //
 func HandleStateChanges(ctx context.Context, integration *v1alpha1.Integration, handler func(integration *v1alpha1.Integration) bool) error {
-	gv, err := schema.ParseGroupVersion(integration.APIVersion)
-	if err != nil {
-		return err
-	}
-	dynamicClient, err := customclient.GetDynamicClientFor(gv.Group, gv.Version, integration.Kind, integration.Namespace)
+	dynamicClient, err := customclient.GetDynamicClientFor(v1alpha1.SchemeGroupVersion.Group, v1alpha1.SchemeGroupVersion.Version, "integrations", integration.Namespace)
 	if err != nil {
 		return err
 	}