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
The following commit(s) were added to refs/heads/master by this push:
new ec57490 Fix #1446 and #1395: completely update integration resource
on redeploy and print events
ec57490 is described below
commit ec574905307f6ebd843d7235e4edbcf60710467d
Author: Nicola Ferraro <[email protected]>
AuthorDate: Tue May 5 17:38:06 2020 +0200
Fix #1446 and #1395: completely update integration resource on redeploy and
print events
---
deploy/resources.go | 4 +-
pkg/apis/camel/v1/integration_types.go | 2 +
pkg/cmd/run.go | 24 +++++++----
.../integration/integration_controller.go | 1 +
pkg/controller/integration/noop.go | 49 ++++++++++++++++++++++
5 files changed, 71 insertions(+), 9 deletions(-)
diff --git a/deploy/resources.go b/deploy/resources.go
index c9efe1e..0f3469a 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -340,9 +340,9 @@ var assets = func() http.FileSystem {
"/traits.yaml": &vfsgen۰CompressedFileInfo{
name: "traits.yaml",
modTime: time.Time{},
- uncompressedSize: 29816,
+ uncompressedSize: 31547,
- compressedContent:
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd4\x7d\x6d\x6f\x1c\x37\x92\xf0\x77\xff\x0a\x42\xcf\x03\xe8\x05\x33\x2d\x39\x8b\xdd\x64\xf5\xc0\x08\xf4\x28\xce\xae\x9c\xd8\xd6\x59\x4e\xf6\x0e\xb9\x60\x87\xd3\x5d\x33\x4d\x8b\x4d\xf6\x92\xec\x91\x67\x0f\x07\xdc\xdf\xb8\xbf\x77\xbf\xe4\x50\xc5\x97\x66\xcf\x8c\xa4\x96\x1d\x05\x56\xf2\xc1\x1a\xa9\xbb\x58\x55\xac\xf7\x2a\x72\x9c\xe1\xc2\xd9\xd3\x67\x53\xa6\x78\x03\xa7\x8c\x2f\x16\x42\x09\xb7\x7e\xc6\x58\x2b\xb9\x5b\x68\x
[...]
+ compressedContent:
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd4\x7d\xed\x72\x1b\x37\x96\xe8\x7f\x3f\x05\x4a\xf7\x56\x49\x54\x91\x2d\x3b\x53\x33\xc9\xe8\x5e\x6f\x4a\x6b\x3b\x33\x4a\x62\x5b\x6b\x3b\x99\xdd\xca\xa6\x86\x60\xf7\x21\x1b\x21\x1a\xe8\x01\xd0\x94\x99\xad\xad\xda\xd7\xd8\xd7\xdb\x27\xd9\x3a\x07\x1f\x8d\x26\x5b\x12\xe5\x44\xa9\x28\xf9\x61\x51\xea\x3e\x38\x38\x38\xdf\x1f\xa0\x33\x5c\x38\x7b\xfe\x64\xc6\x14\x6f\xe0\x9c\xf1\xe5\x52\x28\xe1\xb6\x4f\x18\x6b\x25\x77\x4b\x6d\x
[...]
},
"/user-cluster-role.yaml": &vfsgen۰CompressedFileInfo{
name: "user-cluster-role.yaml",
diff --git a/pkg/apis/camel/v1/integration_types.go
b/pkg/apis/camel/v1/integration_types.go
index 52cc073..4ca7d9c 100644
--- a/pkg/apis/camel/v1/integration_types.go
+++ b/pkg/apis/camel/v1/integration_types.go
@@ -171,6 +171,8 @@ const (
IntegrationPhaseDeploying IntegrationPhase = "Deploying"
// IntegrationPhaseRunning --
IntegrationPhaseRunning IntegrationPhase = "Running"
+ // IntegrationPhaseUpdating is a phase where the operator is not
supposed to interact with the resource
+ IntegrationPhaseUpdating IntegrationPhase = "Updating"
// IntegrationPhaseError --
IntegrationPhaseError IntegrationPhase = "Error"
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 96718a6..f2ee010 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -33,8 +33,6 @@ import (
"strings"
"syscall"
- "github.com/spf13/pflag"
-
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/client"
"github.com/apache/camel-k/pkg/trait"
@@ -47,6 +45,7 @@ import (
"github.com/magiconair/properties"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -299,6 +298,12 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args
[]string) error {
return err
}
}
+ if o.Logs || o.Dev || o.Wait {
+ go watch.HandleIntegrationEvents(o.Context, integration,
func(event *corev1.Event) bool {
+ fmt.Fprintln(cmd.OutOrStdout(), event.Message)
+ return true
+ })
+ }
if o.Wait || o.Dev {
for {
integrationPhase, err := o.waitForIntegrationReady(cmd,
integration)
@@ -380,11 +385,6 @@ func (o *runCmdOptions) waitForIntegrationReady(cmd
*cobra.Command, integration
return true
}
- go watch.HandleIntegrationEvents(o.Context, integration, func(event
*corev1.Event) bool {
- fmt.Fprintln(cmd.OutOrStdout(), event.Message)
- return true
- })
-
return watch.HandleIntegrationStateChanges(o.Context, integration,
handler)
}
@@ -586,8 +586,18 @@ func (o *runCmdOptions) updateIntegrationCode(c
client.Client, sources []string)
if err != nil {
return nil, err
}
+ // Hold the resource from the operator controller
+ clone.Status.Phase = v1.IntegrationPhaseUpdating
+ err = c.Status().Update(o.Context, clone)
+ // Update the spec
integration.ResourceVersion = clone.ResourceVersion
err = c.Update(o.Context, &integration)
+ if err != nil {
+ return nil, err
+ }
+ // Reset the status
+ integration.Status = v1.IntegrationStatus{}
+ err = c.Status().Update(o.Context, &integration)
}
if err != nil {
diff --git a/pkg/controller/integration/integration_controller.go
b/pkg/controller/integration/integration_controller.go
index dbc9302..96f4e1e 100644
--- a/pkg/controller/integration/integration_controller.go
+++ b/pkg/controller/integration/integration_controller.go
@@ -260,6 +260,7 @@ func (r *ReconcileIntegration) Reconcile(request
reconcile.Request) (reconcile.R
NewDeployAction(),
NewMonitorAction(),
NewErrorAction(),
+ NewNoopAction(),
}
for _, a := range actions {
diff --git a/pkg/controller/integration/noop.go
b/pkg/controller/integration/noop.go
new file mode 100644
index 0000000..94a2663
--- /dev/null
+++ b/pkg/controller/integration/noop.go
@@ -0,0 +1,49 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package integration
+
+import (
+ "context"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+)
+
+// NewNoopAction is used to put an integration resource out of the operator
lifecycle.
+//
+// The resource must be updated by an external entity (e.g. the kamel CLI) to
a new state when ready
+// to start a new workflow.
+func NewNoopAction() Action {
+ return &noopAction{}
+}
+
+type noopAction struct {
+ baseAction
+}
+
+func (action *noopAction) Name() string {
+ return "noop"
+}
+
+func (action *noopAction) CanHandle(integration *v1.Integration) bool {
+ return integration.Status.Phase == v1.IntegrationPhaseUpdating
+}
+
+func (action *noopAction) Handle(ctx context.Context, integration
*v1.Integration) (*v1.Integration, error) {
+ // Do nothing and return no object to update
+ return nil, nil
+}