Skip to content

Commit

Permalink
fix: delete command
Browse files Browse the repository at this point in the history
There was hard-coded `faas` namespace.
  • Loading branch information
matejvasek authored and lance committed Sep 10, 2020
1 parent 8a60c5e commit 284b77f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
1 change: 0 additions & 1 deletion client.go
Expand Up @@ -8,7 +8,6 @@ import (
)

const (
DefaultNamespace = "faas"
DefaultRegistry = "docker.io"
DefaultRuntime = "go"
DefaultTrigger = "http"
Expand Down
3 changes: 1 addition & 2 deletions cmd/completion_util.go
Expand Up @@ -6,14 +6,13 @@ import (
"os/user"
"path"

"github.com/boson-project/faas"
"github.com/boson-project/faas/buildpacks"
"github.com/boson-project/faas/knative"
"github.com/spf13/cobra"
)

func CompleteFunctionList(cmd *cobra.Command, args []string, toComplete string) (strings []string, directive cobra.ShellCompDirective) {
lister, err := knative.NewLister(faas.DefaultNamespace)
lister, err := knative.NewLister("")
if err != nil {
directive = cobra.ShellCompDirectiveError
return
Expand Down
23 changes: 13 additions & 10 deletions cmd/delete.go
Expand Up @@ -12,6 +12,7 @@ import (
func init() {
root.AddCommand(deleteCmd)
deleteCmd.Flags().StringP("path", "p", cwd(), "Path to the project which should be deleted - $FAAS_PATH")
deleteCmd.Flags().StringP("namespace", "n", "", "Override namespace in which to search for Functions. Default is to use currently active underlying platform setting - $FAAS_NAMESPACE")
deleteCmd.Flags().BoolP("yes", "y", false, "When in interactive mode (attached to a TTY), skip prompting the user. - $FAAS_YES")
}

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

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

remover := knative.NewRemover()
remover := knative.NewRemover(config.Namespace)
remover.Verbose = config.Verbose

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

type deleteConfig struct {
Name string
Path string
Verbose bool
Yes bool
Name string
Namespace string
Path string
Verbose bool
Yes bool
}

// newDeleteConfig returns a config populated from the current execution context
Expand All @@ -55,10 +57,11 @@ func newDeleteConfig(args []string) deleteConfig {
name = args[0]
}
return deleteConfig{
Path: viper.GetString("path"),
Name: deriveName(name, viper.GetString("path")), // args[0] or derived
Verbose: viper.GetBool("verbose"), // defined on root
Yes: viper.GetBool("yes"),
Path: viper.GetString("path"),
Namespace: viper.GetString("namespace"),
Name: deriveName(name, viper.GetString("path")), // args[0] or derived
Verbose: viper.GetBool("verbose"), // defined on root
Yes: viper.GetBool("yes"),
}
}

Expand Down
11 changes: 8 additions & 3 deletions knative/remover.go
Expand Up @@ -3,16 +3,16 @@ package knative
import (
"bytes"
"fmt"
"github.com/boson-project/faas"
"github.com/boson-project/faas/k8s"
"io"
"k8s.io/client-go/tools/clientcmd"
commands "knative.dev/client/pkg/kn/commands"
"os"
"time"
)

func NewRemover() *Remover {
return &Remover{Namespace: faas.DefaultNamespace}
func NewRemover(namespaceOverride string) *Remover {
return &Remover{Namespace: namespaceOverride}
}

type Remover struct {
Expand Down Expand Up @@ -41,6 +41,11 @@ func (remover *Remover) Remove(name string) (err error) {
if err != nil {
return err
}
if remover.Namespace == "" {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
remover.Namespace, _, _ = clientConfig.Namespace()
}
client, err := p.NewServingClient(remover.Namespace)
if err != nil {
return fmt.Errorf("remover failed to create new serving client: %v", err)
Expand Down

0 comments on commit 284b77f

Please sign in to comment.