Skip to content

Commit 284b77f

Browse files
matejvaseklance
authored andcommitted
fix: delete command
There was hard-coded `faas` namespace.
1 parent 8a60c5e commit 284b77f

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

client.go

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
const (
11-
DefaultNamespace = "faas"
1211
DefaultRegistry = "docker.io"
1312
DefaultRuntime = "go"
1413
DefaultTrigger = "http"

cmd/completion_util.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
"os/user"
77
"path"
88

9-
"github.com/boson-project/faas"
109
"github.com/boson-project/faas/buildpacks"
1110
"github.com/boson-project/faas/knative"
1211
"github.com/spf13/cobra"
1312
)
1413

1514
func CompleteFunctionList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) {
16-
lister, err := knative.NewLister(faas.DefaultNamespace)
15+
lister, err := knative.NewLister("")
1716
if err != nil {
1817
directive = cobra.ShellCompDirectiveError
1918
return

cmd/delete.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
func init() {
1313
root.AddCommand(deleteCmd)
1414
deleteCmd.Flags().StringP("path", "p", cwd(), "Path to the project which should be deleted - $FAAS_PATH")
15+
deleteCmd.Flags().StringP("namespace", "n", "", "Override namespace in which to search for Functions. Default is to use currently active underlying platform setting - $FAAS_NAMESPACE")
1516
deleteCmd.Flags().BoolP("yes", "y", false, "When in interactive mode (attached to a TTY), skip prompting the user. - $FAAS_YES")
1617
}
1718

@@ -21,14 +22,14 @@ var deleteCmd = &cobra.Command{
2122
Long: `Removes the deployed Function by name, by explicit path, or by default for the current directory. No local files are deleted.`,
2223
SuggestFor: []string{"remove", "rm", "del"},
2324
ValidArgsFunction: CompleteFunctionList,
24-
PreRunE: bindEnv("path", "yes"),
25+
PreRunE: bindEnv("path", "yes", "namespace"),
2526
RunE: runDelete,
2627
}
2728

2829
func runDelete(cmd *cobra.Command, args []string) (err error) {
2930
config := newDeleteConfig(args).Prompt()
3031

31-
remover := knative.NewRemover()
32+
remover := knative.NewRemover(config.Namespace)
3233
remover.Verbose = config.Verbose
3334

3435
function := faas.Function{Root: config.Path, Name: config.Name}
@@ -41,10 +42,11 @@ func runDelete(cmd *cobra.Command, args []string) (err error) {
4142
}
4243

4344
type deleteConfig struct {
44-
Name string
45-
Path string
46-
Verbose bool
47-
Yes bool
45+
Name string
46+
Namespace string
47+
Path string
48+
Verbose bool
49+
Yes bool
4850
}
4951

5052
// newDeleteConfig returns a config populated from the current execution context
@@ -55,10 +57,11 @@ func newDeleteConfig(args []string) deleteConfig {
5557
name = args[0]
5658
}
5759
return deleteConfig{
58-
Path: viper.GetString("path"),
59-
Name: deriveName(name, viper.GetString("path")), // args[0] or derived
60-
Verbose: viper.GetBool("verbose"), // defined on root
61-
Yes: viper.GetBool("yes"),
60+
Path: viper.GetString("path"),
61+
Namespace: viper.GetString("namespace"),
62+
Name: deriveName(name, viper.GetString("path")), // args[0] or derived
63+
Verbose: viper.GetBool("verbose"), // defined on root
64+
Yes: viper.GetBool("yes"),
6265
}
6366
}
6467

knative/remover.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package knative
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/boson-project/faas"
76
"github.com/boson-project/faas/k8s"
87
"io"
8+
"k8s.io/client-go/tools/clientcmd"
99
commands "knative.dev/client/pkg/kn/commands"
1010
"os"
1111
"time"
1212
)
1313

14-
func NewRemover() *Remover {
15-
return &Remover{Namespace: faas.DefaultNamespace}
14+
func NewRemover(namespaceOverride string) *Remover {
15+
return &Remover{Namespace: namespaceOverride}
1616
}
1717

1818
type Remover struct {
@@ -41,6 +41,11 @@ func (remover *Remover) Remove(name string) (err error) {
4141
if err != nil {
4242
return err
4343
}
44+
if remover.Namespace == "" {
45+
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
46+
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
47+
remover.Namespace, _, _ = clientConfig.Namespace()
48+
}
4449
client, err := p.NewServingClient(remover.Namespace)
4550
if err != nil {
4651
return fmt.Errorf("remover failed to create new serving client: %v", err)

0 commit comments

Comments
 (0)