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

Adds service delete command #63

Merged
merged 2 commits into from
Apr 11, 2019
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
1 change: 1 addition & 0 deletions pkg/kn/commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ func NewServiceCommand(p *KnParams) *cobra.Command {
serviceCmd.AddCommand(NewServiceListCommand(p))
serviceCmd.AddCommand(NewServiceDescribeCommand(p))
serviceCmd.AddCommand(NewServiceCreateCommand(p))
serviceCmd.AddCommand(NewServiceDeleteCommand(p))
return serviceCmd
}
57 changes: 57 additions & 0 deletions pkg/kn/commands/service_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright © 2018 The Knative Authors
//
// Licensed 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 commands

import (
"errors"
"fmt"
"github.com/spf13/cobra"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NewServiceDeleteCommand represent 'service delete' command
func NewServiceDeleteCommand(p *KnParams) *cobra.Command {
serviceDeleteCommand := &cobra.Command{
Use: "delete NAME",
Short: "Delete a service.",
Example: `
# Delete a service 'svc1' in default namespace
kn service delete svc1

# Delete a service 'svc2' in 'ns1' namespace
kn service delete svc2 -n ns1`,

RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
navidshaikh marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("requires the service name.")
}
client, err := p.ServingFactory()
if err != nil {
return err
}
namespace := cmd.Flag("namespace").Value.String()
err = client.Services(namespace).Delete(
args[0],
&v1.DeleteOptions{},
)
if err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Deleted %s in %s namespace.\n", args[0], namespace)
return nil
},
}
return serviceDeleteCommand
}