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

kamel run --dev mode terminate pod if pressing ctrl + c #186

Merged
merged 1 commit into from
Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pkg/client/cmd/context_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions pkg/client/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions pkg/client/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions pkg/client/cmd/util.go
Original file line number Diff line number Diff line change
@@ -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)
}