diff options
| author | zhangjie <iamkadisi@163.com> | 2020-01-15 20:06:13 +0800 |
|---|---|---|
| committer | zhangjie <iamkadisi@163.com> | 2020-01-15 20:06:13 +0800 |
| commit | 778e8634811e55b868aaef5b71035d282e3ba7d7 (patch) | |
| tree | b29236b19d8a345ef314ea606e34ab7f8a9e3b55 /edgesite | |
| parent | edgesite support --minconfig subcommand (diff) | |
| download | kubeedge-778e8634811e55b868aaef5b71035d282e3ba7d7.tar.gz | |
edgesite support --defaultconfig subcommand
Signed-off-by: zhangjie <iamkadisi@163.com>
Diffstat (limited to 'edgesite')
| -rw-r--r-- | edgesite/cmd/app/flags/flags.go | 105 | ||||
| -rw-r--r-- | edgesite/cmd/app/server.go | 7 |
2 files changed, 4 insertions, 108 deletions
diff --git a/edgesite/cmd/app/flags/flags.go b/edgesite/cmd/app/flags/flags.go deleted file mode 100644 index cac238e93..000000000 --- a/edgesite/cmd/app/flags/flags.go +++ /dev/null @@ -1,105 +0,0 @@ -/* -Copyright 2020 The KubeEdge 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 flags - -import ( - "fmt" - "os" - "strconv" - - flag "github.com/spf13/pflag" - "sigs.k8s.io/yaml" - - "github.com/kubeedge/kubeedge/pkg/apis/edgesite/v1alpha1" -) - -type minConfigValue int - -const ( - MinConfigFalse minConfigValue = 0 - MinConfigTrue minConfigValue = 1 - // TODO support json output (default yaml ) @kadisi -) - -func (m *minConfigValue) IsBoolFlag() bool { - return true -} - -func (m *minConfigValue) Get() interface{} { - return minConfigValue(*m) -} - -func (m *minConfigValue) Set(s string) error { - boolVal, err := strconv.ParseBool(s) - if boolVal { - *m = MinConfigTrue - } else { - *m = MinConfigFalse - } - return err -} - -func (m *minConfigValue) String() string { - return fmt.Sprintf("%v", bool(*m == MinConfigTrue)) -} - -// The type of the flag as required by the pflag.Value interface -func (m *minConfigValue) Type() string { - return "minconfig" -} - -func MinConfigVar(p *minConfigValue, name string, value minConfigValue, usage string) { - *p = value - flag.Var(p, name, usage) - // "--minconfig" will be treated as "--minconfig=true" - flag.Lookup(name).NoOptDefVal = "true" -} - -func minConfig(name string, value minConfigValue, usage string) *minConfigValue { - p := new(minConfigValue) - MinConfigVar(p, name, value, usage) - return p -} - -const minConfigFlagName = "minconfig" - -var ( - minConfigFlag = minConfig(minConfigFlagName, MinConfigFalse, "Print min configuration for reference, users can refer to it to create their own configuration files") -) - -// AddFlags registers this package's flags on arbitrary FlagSets, such that they point to the -// same value as the global flags. -func AddFlags(fs *flag.FlagSet) { - fs.AddFlag(flag.Lookup(minConfigFlagName)) -} - -// PrintMinConfigAndExitIfRequested will check if the -minconfig flag was passed -// and, if so, print the min config and exit. -func PrintMinConfigAndExitIfRequested() { - if *minConfigFlag == MinConfigTrue { - config := v1alpha1.NewMinEdgeSiteConfig() - data, err := yaml.Marshal(config) - if err != nil { - fmt.Printf("Marshal edgesite min config to yaml error %v\n", err) - os.Exit(1) - } - fmt.Println("# With --minconfig , you can easily used this configurations as reference.") - fmt.Println("# It's useful to users who are new to KubeEdge, and you can modify/create your own configs accordingly. ") - fmt.Println("# This configuration is suitable for beginners.") - fmt.Printf("\n%v\n\n", string(data)) - os.Exit(0) - } -} diff --git a/edgesite/cmd/app/server.go b/edgesite/cmd/app/server.go index 25832273d..8a5e9417d 100644 --- a/edgesite/cmd/app/server.go +++ b/edgesite/cmd/app/server.go @@ -14,8 +14,8 @@ import ( "github.com/kubeedge/kubeedge/edge/pkg/common/dbm" "github.com/kubeedge/kubeedge/edge/pkg/edged" "github.com/kubeedge/kubeedge/edge/pkg/metamanager" - "github.com/kubeedge/kubeedge/edgesite/cmd/app/flags" "github.com/kubeedge/kubeedge/edgesite/cmd/app/options" + "github.com/kubeedge/kubeedge/pkg/apis/edgesite/v1alpha1" "github.com/kubeedge/kubeedge/pkg/util/flag" "github.com/kubeedge/kubeedge/pkg/version" "github.com/kubeedge/kubeedge/pkg/version/verflag" @@ -32,7 +32,8 @@ It is also responsible for storing/retrieving metadata to/from a lightweight dat runs on edge nodes and manages containerized applications.`, Run: func(cmd *cobra.Command, args []string) { verflag.PrintAndExitIfRequested() - flags.PrintMinConfigAndExitIfRequested() + flag.PrintMinConfigAndExitIfRequested(v1alpha1.NewMinEdgeSiteConfig()) + flag.PrintDefaultConfigAndExitIfRequested(v1alpha1.NewDefaultEdgeSiteConfig()) flag.PrintFlags(cmd.Flags()) // To help debugging, immediately log version @@ -46,7 +47,7 @@ runs on edge nodes and manages containerized applications.`, fs := cmd.Flags() namedFs := opts.Flags() verflag.AddFlags(namedFs.FlagSet("global")) - flags.AddFlags(namedFs.FlagSet("global")) + flag.AddFlags(namedFs.FlagSet("global")) globalflag.AddGlobalFlags(namedFs.FlagSet("global"), cmd.Name()) for _, f := range namedFs.FlagSets { fs.AddFlagSet(f) |
