Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1668: cancel previous context before issuing a new one #1679

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 77 additions & 5 deletions deploy/camel-catalog-1.5.1-SNAPSHOT-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions deploy/camel-catalog-1.5.1-SNAPSHOT-quarkus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions deploy/resources.go

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions pkg/cmd/modeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/modeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
15 changes: 10 additions & 5 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down