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 2020/09/03 12:30:57 UTC

[camel-k] 01/03: fix #1668: cancel previous context before issuing a new one

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 04237248f7c012b7a631bbc4efdef8b440aa5999
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Mon Aug 31 11:33:15 2020 +0200

    fix #1668: cancel previous context before issuing a new one
---
 deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml    | 82 ++++++++++++++++++++++--
 deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml | 26 ++++++--
 deploy/resources.go                              |  8 +--
 pkg/cmd/modeline.go                              | 18 +++++-
 pkg/cmd/modeline_test.go                         |  8 +--
 pkg/cmd/root.go                                  | 15 +++--
 pkg/cmd/run.go                                   | 14 +++-
 7 files changed, 143 insertions(+), 28 deletions(-)

diff --git a/deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml b/deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml
index 966d5e7..405b36f 100644
--- a/deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml
+++ b/deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml
@@ -21,8 +21,8 @@ metadata:
   name: camel-catalog-1.5.1-snapshot-main
   labels:
     app: camel-k
-    camel.apache.org/catalog.version: 3.4.0
-    camel.apache.org/catalog.loader.version: 3.4.0
+    camel.apache.org/catalog.version: 3.5.0-SNAPSHOT
+    camel.apache.org/catalog.loader.version: 3.5.0-SNAPSHOT
     camel.apache.org/runtime.version: 1.5.1-SNAPSHOT
     camel.apache.org/runtime.provider: main
 spec:
@@ -31,9 +31,9 @@ spec:
     provider: main
     applicationClass: org.apache.camel.k.main.Application
     metadata:
-      camel.version: 3.4.0
-      quarkus.version: 1.6.0.Final
-      camel-quarkus.version: 1.0.0-CR3
+      camel.version: 3.5.0-SNAPSHOT
+      quarkus.version: 1.7.0.Final
+      camel-quarkus.version: 1.0.0
     dependencies:
     - groupId: org.apache.camel.k
       artifactId: camel-k-runtime-main
@@ -94,6 +94,15 @@ spec:
       javaTypes:
       - org.apache.camel.component.azure.blob.BlobServiceComponent
       - org.apache.camel.component.azure.queue.QueueServiceComponent
+    camel-vertx-websocket:
+      groupId: org.apache.camel
+      artifactId: camel-vertx-websocket
+      schemes:
+      - id: vertx-websocket
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.vertx.websocket.VertxWebsocketComponent
     camel-seda:
       groupId: org.apache.camel
       artifactId: camel-seda
@@ -193,6 +202,15 @@ spec:
         passive: false
       javaTypes:
       - org.apache.camel.component.sjms2.Sjms2Component
+    camel-vertx-http:
+      groupId: org.apache.camel
+      artifactId: camel-vertx-http
+      schemes:
+      - id: vertx-http
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.vertx.http.VertxHttpComponent
     camel-facebook:
       groupId: org.apache.camel
       artifactId: camel-facebook
@@ -299,6 +317,15 @@ spec:
         passive: false
       javaTypes:
       - org.apache.camel.component.aws2.iam.IAM2Component
+    camel-jsonata:
+      groupId: org.apache.camel
+      artifactId: camel-jsonata
+      schemes:
+      - id: jsonata
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.jsonata.JsonataComponent
     camel-aws-eks:
       groupId: org.apache.camel
       artifactId: camel-aws-eks
@@ -595,6 +622,15 @@ spec:
         passive: false
       javaTypes:
       - org.apache.camel.component.weka.WekaComponent
+    camel-azure-eventhubs:
+      groupId: org.apache.camel
+      artifactId: camel-azure-eventhubs
+      schemes:
+      - id: azure-eventhubs
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.azure.eventhubs.EventHubsComponent
     camel-jacksonxml:
       groupId: org.apache.camel
       artifactId: camel-jacksonxml
@@ -780,6 +816,15 @@ spec:
         passive: false
       javaTypes:
       - org.apache.camel.component.salesforce.SalesforceComponent
+    camel-minio:
+      groupId: org.apache.camel
+      artifactId: camel-minio
+      schemes:
+      - id: minio
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.minio.MinioComponent
     camel-xj:
       groupId: org.apache.camel
       artifactId: camel-xj
@@ -1288,6 +1333,15 @@ spec:
         passive: false
       javaTypes:
       - org.apache.camel.component.guava.eventbus.GuavaEventBusComponent
+    camel-aws2-sts:
+      groupId: org.apache.camel
+      artifactId: camel-aws2-sts
+      schemes:
+      - id: aws2-sts
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.aws2.sts.STS2Component
     camel-msv:
       groupId: org.apache.camel
       artifactId: camel-msv
@@ -2200,6 +2254,15 @@ spec:
       - groovy
       javaTypes:
       - org.apache.camel.language.groovy.GroovyLanguage
+    camel-arangodb:
+      groupId: org.apache.camel
+      artifactId: camel-arangodb
+      schemes:
+      - id: arangodb
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.arangodb.ArangoDbComponent
     camel-saga:
       groupId: org.apache.camel
       artifactId: camel-saga
@@ -2794,6 +2857,15 @@ spec:
       - grok
       javaTypes:
       - org.apache.camel.component.grok.GrokDataFormat
+    camel-oaipmh:
+      groupId: org.apache.camel
+      artifactId: camel-oaipmh
+      schemes:
+      - id: oaipmh
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.oaipmh.component.OAIPMHComponent
     camel-mvel:
       groupId: org.apache.camel
       artifactId: camel-mvel
diff --git a/deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml b/deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml
index 7e18efe..db61e37 100644
--- a/deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml
+++ b/deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml
@@ -21,8 +21,8 @@ metadata:
   name: camel-catalog-1.5.1-snapshot-quarkus
   labels:
     app: camel-k
-    camel.apache.org/catalog.version: 3.4.0
-    camel.apache.org/catalog.loader.version: 3.4.0
+    camel.apache.org/catalog.version: 3.5.0-SNAPSHOT
+    camel.apache.org/catalog.loader.version: 3.5.0-SNAPSHOT
     camel.apache.org/runtime.version: 1.5.1-SNAPSHOT
     camel.apache.org/runtime.provider: quarkus
 spec:
@@ -31,9 +31,9 @@ spec:
     provider: quarkus
     applicationClass: io.quarkus.runner.GeneratedMain
     metadata:
-      camel.version: 3.4.0
-      quarkus.version: 1.6.0.Final
-      camel-quarkus.version: 1.0.0-CR3
+      camel.version: 3.5.0-SNAPSHOT
+      quarkus.version: 1.7.0.Final
+      camel-quarkus.version: 1.0.0
     dependencies:
     - groupId: org.apache.camel.k
       artifactId: camel-k-runtime-quarkus
@@ -1045,6 +1045,13 @@ spec:
       - zipfile
       javaTypes:
       - org.apache.camel.dataformat.zipfile.ZipFileDataFormat
+    camel-quarkus-grok:
+      groupId: org.apache.camel.quarkus
+      artifactId: camel-quarkus-grok
+      dataformats:
+      - grok
+      javaTypes:
+      - org.apache.camel.component.grok.GrokDataFormat
     camel-quarkus-servlet:
       groupId: org.apache.camel.quarkus
       artifactId: camel-quarkus-servlet
@@ -1128,6 +1135,15 @@ spec:
       - org.apache.camel.component.openstack.neutron.NeutronComponent
       - org.apache.camel.component.openstack.nova.NovaComponent
       - org.apache.camel.component.openstack.swift.SwiftComponent
+    camel-quarkus-jpa:
+      groupId: org.apache.camel.quarkus
+      artifactId: camel-quarkus-jpa
+      schemes:
+      - id: jpa
+        http: false
+        passive: false
+      javaTypes:
+      - org.apache.camel.component.jpa.JpaComponent
     camel-quarkus-consul:
       groupId: org.apache.camel.quarkus
       artifactId: camel-quarkus-consul
diff --git a/deploy/resources.go b/deploy/resources.go
index 0741e84..d6b8d97 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -91,16 +91,16 @@ var assets = func() http.FileSystem {
 		"/camel-catalog-1.5.1-SNAPSHOT-main.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel-catalog-1.5.1-SNAPSHOT-main.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 89178,
+			uncompressedSize: 91183,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x7d\x5b\x77\xdb\x38\xb2\xee\x7b\x7e\x05\xd7\xe4\x65\xef\x75\x86\x35\xdd\xce\xcc\xf4\xd9\x7d\x9e\x6c\x39\x4e\xec\xd8\x8e\x3b\xf2\x24\x99\x79\xe9\x05\x91\x90\x04\x8b\x24\x68\x00\x92\x65\xff\xfa\xb3\x70\xe1\x55\x10\x24\x12\x86\xd7\xf6\x83\x49\x11\x55\x5f\xb1\x08\x12\x97\x42\xa1\xea\x7d\x14\xbf\xde\xdf\xbb\xf7\xd1\x35\x49\x70\xc1\x71\x1a\x09\x1a\x89\x25\x8e\x4e\x4b\x94\x2c\x71\x34\xa5\x73\xf1\x84\x18\x8e\x2e\xe8\xba\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x7d\x5b\x77\xdb\x38\xb2\xee\x7b\x7e\x05\xd7\xe4\x65\xef\x75\x46\x35\xdd\xce\xcc\xf4\xd9\x7d\x9e\x6c\x39\x4e\xec\xd8\x8e\x3b\xf4\x24\x99\x79\xe9\x05\x91\x90\x04\x8b\x24\x68\x00\x92\x65\xff\xfa\xb3\x70\xe1\x55\x10\x24\x12\x86\xd7\xf6\x83\x49\x11\x55\x5f\xb1\x08\x12\x97\x42\xa1\xea\x7d\x34\x79\xbd\xbf\x77\xef\xa3\x6b\x92\xe0\x82\xe3\x34\x12\x34\x12\x4b\x1c\x9d\x96\x28\x59\xe2\x28\xa6\x73\xf1\x84\x18\x8e\x2e\xe8\xba\x [...]
 		},
 		"/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 49034,
+			uncompressedSize: 49504,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x7d\x5d\x77\xdb\xaa\xf2\xf7\x7d\x3e\x85\x56\x73\x73\xce\x5a\x5b\xec\x7d\xd2\xb3\xf7\x45\x9f\xab\x24\x6d\xda\xa4\x4d\x9a\xc6\x39\x6d\xf7\xbe\xe9\xc2\x12\xb6\x89\x25\x50\x00\xd9\x4e\x3e\xfd\xb3\x40\xc8\x92\x6c\x65\xf4\x12\xf0\x3f\x17\x91\x2c\x86\xdf\xc0\x80\x60\x34\xcc\xc0\x71\x10\xba\xfb\x3b\x3a\x0e\xbe\xd0\x88\x30\x49\xe2\x40\xf1\x40\x2d\x48\x70\x9a\xe1\x68\x41\x82\x09\x9f\xa9\x35\x16\x24\xb8\xe0\x39\x8b\xb1\xa2\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xc4\x7d\x5d\x77\xdb\xaa\xd2\xff\x7d\x3e\x85\x56\x73\x73\xce\x5a\x5b\xec\x7d\xd2\xff\xde\xff\xb5\xfa\x5c\x25\x69\xd3\x26\x6d\x5e\x5a\xe7\xb4\xdd\xfb\xa6\x0b\x4b\xd8\x26\x96\x40\x01\x64\x3b\xf9\xf4\xcf\x02\x21\x4b\xb2\x95\xd1\x4b\xc0\x4f\x2e\x22\x59\x0c\xbf\x81\x01\xc1\x68\x98\x81\xe3\x20\x74\xf7\x77\x74\x1c\x7c\xa1\x11\x61\x92\xc4\x81\xe2\x81\x5a\x90\xe0\x34\xc3\xd1\x82\x04\x13\x3e\x53\x6b\x2c\x48\x70\xc1\x73\x16\x63\x [...]
 		},
 		"/cr-example.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "cr-example.yaml",
diff --git a/pkg/cmd/modeline.go b/pkg/cmd/modeline.go
index 7d6a848..0833511 100644
--- a/pkg/cmd/modeline.go
+++ b/pkg/cmd/modeline.go
@@ -38,6 +38,12 @@ var (
 	nonRunOptions = map[string]bool{
 		"language": true, // language is a marker modeline option for other tools
 	}
+	disallowedOptions = map[string]bool{
+		"dev":  true,
+		"wait": true,
+		"logs": true,
+		"sync": true,
+	}
 
 	// file options must be considered relative to the source files they belong to
 	fileOptions = map[string]bool{
@@ -116,6 +122,10 @@ func createKamelWithModelineCommand(ctx context.Context, args []string, processe
 			return nil, nil, errors.Wrapf(err, "cannot process file %s", f)
 		}
 		for i, o := range ops {
+			if disallowedOptions[o.Name] {
+				return nil, nil, fmt.Errorf("option %q is disallowed in modeline", o.Name)
+			}
+
 			if fileOptions[o.Name] && isLocal(f) {
 				refPath := o.Value
 				if !filepath.IsAbs(refPath) {
@@ -157,8 +167,12 @@ func createKamelWithModelineCommand(ctx context.Context, args []string, processe
 		if len(o.Name) > 1 {
 			prefix = "--"
 		}
-		args = append(args, fmt.Sprintf("%s%s", prefix, o.Name))
-		args = append(args, o.Value)
+		// Using the k=v syntax to avoid issues with booleans
+		if len(o.Value) > 0 {
+			args = append(args, fmt.Sprintf("%s%s=%s", prefix, o.Name, o.Value))
+		} else {
+			args = append(args, fmt.Sprintf("%s%s", prefix, o.Name))
+		}
 	}
 
 	return createKamelWithModelineCommand(ctx, args, processedFiles)
diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go
index 09ff8c3..20e91bd 100644
--- a/pkg/cmd/modeline_test.go
+++ b/pkg/cmd/modeline_test.go
@@ -42,7 +42,7 @@ func TestModelineRunSimple(t *testing.T) {
 	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
 	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--dependency", "mvn:org.my/lib:1.0"}, flags)
+	assert.Equal(t, []string{"run", fileName, "--dependency=mvn:org.my/lib:1.0"}, flags)
 }
 
 func TestModelineRunHelp(t *testing.T) {
@@ -73,7 +73,7 @@ func TestModelineRunChain(t *testing.T) {
 	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", "-d", "mvn:org.my/lib2:1.0", fileName})
 	assert.NoError(t, err)
 	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", "-d", "mvn:org.my/lib2:1.0", fileName, "--dependency", "mvn:org.my/lib:2.0"}, flags)
+	assert.Equal(t, []string{"run", "-d", "mvn:org.my/lib2:1.0", fileName, "--dependency=mvn:org.my/lib:2.0"}, flags)
 }
 
 func TestModelineRunMultipleFiles(t *testing.T) {
@@ -98,7 +98,7 @@ func TestModelineRunMultipleFiles(t *testing.T) {
 	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
 	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--source", fileName2, "--dependency", "mvn:org.my/lib:3.0"}, flags)
+	assert.Equal(t, []string{"run", fileName, "--source=" + fileName2, "--dependency=mvn:org.my/lib:3.0"}, flags)
 }
 
 func TestModelineRunPropertyFiles(t *testing.T) {
@@ -127,5 +127,5 @@ func TestModelineRunPropertyFiles(t *testing.T) {
 	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
 	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--property-file", propFileName}, flags)
+	assert.Equal(t, []string{"run", fileName, "--property-file=" + propFileName}, flags)
 }
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index 0ff0b15..35592bd 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -35,16 +35,21 @@ superpowers.
 
 // RootCmdOptions --
 type RootCmdOptions struct {
-	Context    context.Context `mapstructure:"-"`
-	_client    client.Client   `mapstructure:"-"`
-	KubeConfig string          `mapstructure:"kube-config"`
-	Namespace  string          `mapstructure:"namespace"`
+	RootContext   context.Context    `mapstructure:"-"`
+	Context       context.Context    `mapstructure:"-"`
+	ContextCancel context.CancelFunc `mapstructure:"-"`
+	_client       client.Client      `mapstructure:"-"`
+	KubeConfig    string             `mapstructure:"kube-config"`
+	Namespace     string             `mapstructure:"namespace"`
 }
 
 // NewKamelCommand --
 func NewKamelCommand(ctx context.Context) (*cobra.Command, error) {
+	childCtx, childCancel := context.WithCancel(ctx)
 	options := RootCmdOptions{
-		Context: ctx,
+		RootContext:   ctx,
+		Context:       childCtx,
+		ContextCancel: childCancel,
 	}
 
 	var err error
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index deb845b..f86545c 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -280,6 +280,10 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
 		signal.Notify(cs, os.Interrupt, syscall.SIGTERM)
 		go func() {
 			<-cs
+			if o.Context.Err() != nil {
+				// Context canceled
+				return
+			}
 			fmt.Printf("Run integration terminating\n")
 			err := DeleteIntegration(o.Context, c, integration.Name, integration.Namespace)
 			if err != nil {
@@ -338,9 +342,9 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
 		}
 	}
 
-	if o.Sync && !o.Logs && !o.Dev {
+	if o.Sync || o.Logs || o.Dev {
 		// Let's add a Wait point, otherwise the script terminates
-		<-o.Context.Done()
+		<-o.RootContext.Done()
 	}
 
 	return nil
@@ -408,7 +412,7 @@ func (o *runCmdOptions) syncIntegration(c client.Client, sources []string, catal
 						return
 					case <-changes:
 						// let's create a new command to parse modeline changes and update our integration
-						newCmd, _, err := createKamelWithModelineCommand(o.Context, os.Args[1:], make(map[string]bool))
+						newCmd, _, err := createKamelWithModelineCommand(o.RootContext, os.Args[1:], make(map[string]bool))
 						if err != nil {
 							fmt.Println("Unable to sync integration: ", err.Error())
 							continue
@@ -420,6 +424,10 @@ func (o *runCmdOptions) syncIntegration(c client.Client, sources []string, catal
 							return err
 						}
 						newCmd.PostRunE = nil
+
+						// cancel the existing command to release watchers
+						o.ContextCancel()
+						// run the new one
 						err = newCmd.Execute()
 						if err != nil {
 							fmt.Println("Unable to sync integration: ", err.Error())