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
The following commit(s) were added to refs/heads/master by this push: new 97d8d72 fix: Dev mode does not show if the build failed 97d8d72 is described below commit 97d8d726d5543f501afb6bd8901345b3127f09ad Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Fri Sep 6 13:39:39 2019 +0100 fix: Dev mode does not show if the build failed fixes #906 --- pkg/cmd/run.go | 28 ++++++++++++++++++++++++---- pkg/util/watch/watch.go | 20 +++++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 0853753..51b7125 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -203,9 +203,29 @@ func (o *runCmdOptions) run(_ *cobra.Command, args []string) error { } } if o.Wait || o.Dev { - err = o.waitForIntegrationReady(integration) - if err != nil { - return err + for { + integrationPhase, err := o.waitForIntegrationReady(integration) + if err != nil { + return err + } + + if *integrationPhase == v1alpha1.IntegrationPhaseRunning || *integrationPhase == v1alpha1.IntegrationPhaseError { + break + } + + // The integration watch timed out so recreate it using the latest integration resource version + clone := integration.DeepCopy() + var key k8sclient.ObjectKey + key, err = k8sclient.ObjectKeyFromObject(clone) + if err != nil { + return err + } + err = c.Get(o.Context, key, clone) + if err != nil { + return err + } + + integration.ObjectMeta.ResourceVersion = clone.ObjectMeta.ResourceVersion } } if o.Logs || o.Dev { @@ -222,7 +242,7 @@ func (o *runCmdOptions) run(_ *cobra.Command, args []string) error { return nil } -func (o *runCmdOptions) waitForIntegrationReady(integration *v1alpha1.Integration) error { +func (o *runCmdOptions) waitForIntegrationReady(integration *v1alpha1.Integration) (*v1alpha1.IntegrationPhase, error) { handler := func(i *v1alpha1.Integration) bool { // // TODO when we add health checks, we should wait until they are passed diff --git a/pkg/util/watch/watch.go b/pkg/util/watch/watch.go index c5c1cf1..00f7baa 100644 --- a/pkg/util/watch/watch.go +++ b/pkg/util/watch/watch.go @@ -43,16 +43,18 @@ import ( // // This function blocks until the handler function returns true or either the events channel or the context is closed. // -func HandleIntegrationStateChanges(ctx context.Context, integration *v1alpha1.Integration, handler func(integration *v1alpha1.Integration) bool) error { +func HandleIntegrationStateChanges(ctx context.Context, integration *v1alpha1.Integration, + handler func(integration *v1alpha1.Integration) bool) (*v1alpha1.IntegrationPhase, error) { dynamicClient, err := customclient.GetDefaultDynamicClientFor("integrations", integration.Namespace) if err != nil { - return err + return nil, err } watcher, err := dynamicClient.Watch(metav1.ListOptions{ - FieldSelector: "metadata.name=" + integration.Name, + FieldSelector: "metadata.name=" + integration.Name, + ResourceVersion: integration.ObjectMeta.ResourceVersion, }) if err != nil { - return err + return nil, err } defer watcher.Stop() @@ -63,29 +65,29 @@ func HandleIntegrationStateChanges(ctx context.Context, integration *v1alpha1.In for { select { case <-ctx.Done(): - return nil + return lastObservedState, nil case e, ok := <-events: if !ok { - return nil + return lastObservedState, nil } if e.Object != nil { if runtimeUnstructured, ok := e.Object.(runtime.Unstructured); ok { jsondata, err := kubernetes.ToJSON(runtimeUnstructured) if err != nil { - return err + return nil, err } copy := integration.DeepCopy() err = json.Unmarshal(jsondata, copy) if err != nil { log.Error(err, "Unexpected error detected when watching resource") - return nil + return lastObservedState, nil } if lastObservedState == nil || *lastObservedState != copy.Status.Phase { lastObservedState = ©.Status.Phase if !handler(copy) { - return nil + return lastObservedState, nil } } }