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 eed2abf387e3e784e539c7fc38237d47e9206a2a Author: Dmitry Volodin <[email protected]> AuthorDate: Wed Sep 19 12:32:27 2018 +0300 Add delete integration option --- pkg/client/cmd/delete.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++ pkg/client/cmd/root.go | 7 ++-- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/pkg/client/cmd/delete.go b/pkg/client/cmd/delete.go new file mode 100644 index 0000000..3b0f25a --- /dev/null +++ b/pkg/client/cmd/delete.go @@ -0,0 +1,101 @@ +/* +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 ( + "errors" + "fmt" + "os" + + "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" + "github.com/operator-framework/operator-sdk/pkg/sdk" + "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// NewCmdDelete -- +func newCmdDelete(rootCmdOptions *RootCmdOptions) *cobra.Command { + options := deleteCmdOptions{ + RootCmdOptions: rootCmdOptions, + } + cmd := cobra.Command{ + Use: "delete", + Short: "Delete integrations deployed on Kubernetes", + RunE: options.run, + } + + cmd.Flags().StringVar(&options.integrationName, "name", "", "The integration name") + cmd.Flags().BoolVar(&options.deleteAll, "all", false, "Delete all integrations") + cmd.ParseFlags(os.Args) + + return &cmd +} + +type deleteCmdOptions struct { + *RootCmdOptions + integrationName string + deleteAll bool +} + +func (o *deleteCmdOptions) run(cmd *cobra.Command, args []string) error { + namespace := o.Namespace + + integrationList := v1alpha1.IntegrationList{ + TypeMeta: metav1.TypeMeta{ + APIVersion: v1alpha1.SchemeGroupVersion.String(), + Kind: v1alpha1.IntegrationKind, + }, + } + + integration := v1alpha1.Integration{ + TypeMeta: metav1.TypeMeta{ + Kind: v1alpha1.IntegrationKind, + APIVersion: v1alpha1.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: namespace, + Name: o.integrationName, + }, + } + + if o.integrationName != "" && !o.deleteAll { + err := sdk.Delete(&integration) + if err != nil { + return err + } + + fmt.Println("Integration " + integration.GetName() + " deleted") + } else if o.deleteAll { + //Looks like Operator SDK doesn't support deletion of all objects with one command + err := sdk.List(namespace, &integrationList) + if err != nil { + return err + } + for _, integration := range integrationList.Items { + err := sdk.Delete(&integration) + if err != nil { + return err + } + } + } else { + err := errors.New("An integration name or --all option must be specified") + return err + } + + return nil +} diff --git a/pkg/client/cmd/root.go b/pkg/client/cmd/root.go index 7fbeeef..4c3e574 100644 --- a/pkg/client/cmd/root.go +++ b/pkg/client/cmd/root.go @@ -46,9 +46,9 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) { Context: ctx, } var cmd = cobra.Command{ - Use: "kamel", - Short: "Kamel is a awesome client tool for running Apache Camel integrations natively on Kubernetes", - Long: kamelCommandLongDescription, + Use: "kamel", + Short: "Kamel is a awesome client tool for running Apache Camel integrations natively on Kubernetes", + Long: kamelCommandLongDescription, BashCompletionFunction: bashCompletionFunction, } @@ -76,6 +76,7 @@ func NewKamelCommand(ctx context.Context) (*cobra.Command, error) { cmd.AddCommand(newCmdVersion()) cmd.AddCommand(newCmdRun(&options)) cmd.AddCommand(newCmdGet(&options)) + cmd.AddCommand(newCmdDelete(&options)) cmd.AddCommand(newCmdInstall(&options)) cmd.AddCommand(newCmdContext(&options))
