Skip to content

Commit

Permalink
Revert knative#173 and knative#139, reinstating having a config file. (
Browse files Browse the repository at this point in the history
…knative#193)

* Revert knative#173 and knative#139

* Change default layout to have a hidden kn dir

* Update deps
  • Loading branch information
sixolet authored and knative-prow-robot committed Jun 20, 2019
1 parent 8a1d412 commit 32ccc33
Show file tree
Hide file tree
Showing 155 changed files with 24,562 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/cmd/kn.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.
### Options

```
--config string config file (default is $HOME/.kn/config.yaml)
-h, --help help for kn
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ kn completion [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Revision command group
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_revision_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kn revision describe NAME [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_revision_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kn revision list [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Service command group
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ kn service create NAME --image IMAGE [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ kn service delete NAME [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kn service describe NAME [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kn service list [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ kn service update NAME [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kn version [flags]
### Options inherited from parent commands

```
--config string config file (default is $HOME/.kn/config.yaml)
--kubeconfig string kubectl config file (default is $HOME/.kube/config)
```

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1 // indirect
github.com/spf13/viper v1.3.1
github.com/stretchr/objx v0.2.0 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/kn/commands/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.`,
if params.Output != nil {
rootCmd.SetOutput(params.Output)
}
rootCmd.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is $HOME/.kn.yaml)")
rootCmd.PersistentFlags().StringVar(&KubeCfgFile, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)")

rootCmd.AddCommand(subCommand)
Expand Down
3 changes: 3 additions & 0 deletions pkg/kn/commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

// CfgFile is Kn's config file is the path for the Kubernetes config
var CfgFile string

// KubeCfgFile is the path for the Kubernetes config
var KubeCfgFile string

Expand Down
31 changes: 31 additions & 0 deletions pkg/kn/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
"flag"
"fmt"
"os"
"path"
"path/filepath"

"github.com/knative/client/pkg/kn/commands"
"github.com/knative/client/pkg/kn/commands/revision"
"github.com/knative/client/pkg/kn/commands/service"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
)
Expand Down Expand Up @@ -62,6 +64,7 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.`,
if p.Output != nil {
rootCmd.SetOutput(p.Output)
}
rootCmd.PersistentFlags().StringVar(&commands.CfgFile, "config", "", "config file (default is $HOME/.kn/config.yaml)")
rootCmd.PersistentFlags().StringVar(&commands.KubeCfgFile, "kubeconfig", "", "kubectl config file (default is $HOME/.kube/config)")

rootCmd.AddCommand(service.NewServiceCommand(p))
Expand All @@ -75,7 +78,9 @@ Eventing: Manage event subscriptions and channels. Connect up event sources.`,
}

func InitializeConfig() {
cobra.OnInitialize(initConfig)
cobra.OnInitialize(initKubeConfig)

}

func initKubeConfig() {
Expand All @@ -93,3 +98,29 @@ func initKubeConfig() {
commands.KubeCfgFile = filepath.Join(home, ".kube", "config")
}
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if commands.CfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(commands.CfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

// Search config in home directory with name ".kn" (without extension).
viper.AddConfigPath(path.Join(home, ".kn"))
viper.SetConfigName("config")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/fsnotify/fsnotify/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32ccc33

Please sign in to comment.