nicolaferraro closed pull request #186: kamel run --dev mode terminate pod if
pressing ctrl + c
URL: https://github.com/apache/camel-k/pull/186
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pkg/client/cmd/context_delete.go b/pkg/client/cmd/context_delete.go
index 86e754d..ff98837 100644
--- a/pkg/client/cmd/context_delete.go
+++ b/pkg/client/cmd/context_delete.go
@@ -36,7 +36,7 @@ func newContextDeleteCmd(rootCmdOptions *RootCmdOptions)
*cobra.Command {
cmd := cobra.Command{
Use: "delete",
Short: "Delete an Integration Context",
- Long: `Delete anIntegration Context.`,
+ Long: `Delete an Integration Context.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := impl.validate(cmd, args); err != nil {
return err
diff --git a/pkg/client/cmd/delete.go b/pkg/client/cmd/delete.go
index 2a9a0f3..5d74114 100644
--- a/pkg/client/cmd/delete.go
+++ b/pkg/client/cmd/delete.go
@@ -29,7 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
-// NewCmdDelete --
+// newCmdDelete --
func newCmdDelete(rootCmdOptions *RootCmdOptions) *cobra.Command {
impl := deleteCmdOptions{
RootCmdOptions: rootCmdOptions,
@@ -74,26 +74,16 @@ func (command *deleteCmdOptions) run(cmd *cobra.Command,
args []string) error {
if len(args) != 0 && !command.deleteAll {
for _, arg := range args {
- integration := v1alpha1.Integration{
- TypeMeta: metav1.TypeMeta{
- Kind: v1alpha1.IntegrationKind,
- APIVersion:
v1alpha1.SchemeGroupVersion.String(),
- },
- ObjectMeta: metav1.ObjectMeta{
- Namespace: command.Namespace,
- Name: arg,
- },
- }
- err := sdk.Delete(&integration)
+ err := DeleteIntegration(arg, command.Namespace)
if err != nil {
if k8errors.IsNotFound(err) {
- fmt.Println("Integration " +
integration.GetName() + " not found. Skipped.")
+ fmt.Println("Integration " + arg + "
not found. Skipped.")
} else {
return err
}
} else {
- fmt.Println("Integration " +
integration.GetName() + " deleted")
+ fmt.Println("Integration " + arg + " deleted")
}
}
} else if command.deleteAll {
diff --git a/pkg/client/cmd/run.go b/pkg/client/cmd/run.go
index 1d030d5..de99443 100644
--- a/pkg/client/cmd/run.go
+++ b/pkg/client/cmd/run.go
@@ -22,9 +22,11 @@ import (
"io/ioutil"
"net/http"
"os"
+ "os/signal"
"regexp"
"strconv"
"strings"
+ "syscall"
"github.com/apache/camel-k/pkg/trait"
"github.com/apache/camel-k/pkg/util"
@@ -137,6 +139,21 @@ func (o *runCmdOptions) run(cmd *cobra.Command, args
[]string) error {
if err != nil {
return err
}
+
+ if o.Dev {
+ c := make(chan os.Signal)
+ signal.Notify(c, os.Interrupt, syscall.SIGTERM)
+ go func() {
+ <-c
+ fmt.Printf("Run integration terminating\n")
+ err := DeleteIntegration(integration.Name,
integration.Namespace)
+ if err != nil {
+ fmt.Println(err)
+ }
+ os.Exit(1)
+ }()
+ }
+
if o.Sync || o.Dev {
err = o.syncIntegration(args[0])
if err != nil {
diff --git a/pkg/client/cmd/util.go b/pkg/client/cmd/util.go
new file mode 100644
index 0000000..e99aac9
--- /dev/null
+++ b/pkg/client/cmd/util.go
@@ -0,0 +1,39 @@
+/*
+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 cmd
+
+import (
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ "github.com/operator-framework/operator-sdk/pkg/sdk"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// DeleteIntegration --
+func DeleteIntegration(name string, namespace string) error {
+ integration := v1alpha1.Integration{
+ TypeMeta: metav1.TypeMeta{
+ Kind: v1alpha1.IntegrationKind,
+ APIVersion: v1alpha1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: namespace,
+ Name: name,
+ },
+ }
+ return sdk.Delete(&integration)
+}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services