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 2018/10/20 13:13:39 UTC
[camel-k] branch master updated: kamel run --dev mode terminate pod
if pressing ctrl + c
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 7665228 kamel run --dev mode terminate pod if pressing ctrl + c
7665228 is described below
commit 76652286296a14a1a3a69ac3b1829171346c5a44
Author: Dmitry Volodin <dm...@gmail.com>
AuthorDate: Fri Oct 19 12:16:13 2018 +0300
kamel run --dev mode terminate pod if pressing ctrl + c
---
pkg/client/cmd/context_delete.go | 2 +-
pkg/client/cmd/delete.go | 18 ++++--------------
pkg/client/cmd/run.go | 17 +++++++++++++++++
pkg/client/cmd/util.go | 39 +++++++++++++++++++++++++++++++++++++++
4 files changed, 61 insertions(+), 15 deletions(-)
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)
+}