diff --git a/cmd/barbican-kms-plugin/main.go b/cmd/barbican-kms-plugin/main.go index a5c4df4fd7..42a186d380 100644 --- a/cmd/barbican-kms-plugin/main.go +++ b/cmd/barbican-kms-plugin/main.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "flag" "os" "os/signal" @@ -35,12 +34,6 @@ var ( ) func main() { - flag.Parse() - - // This is a temporary hack to enable proper logging until upstream dependencies - // are migrated to fully utilize klog instead of glog. - klog.InitFlags(nil) - cmd := &cobra.Command{ Use: "barbican-kms-plugin", Short: "Barbican KMS plugin for Kubernetes", diff --git a/cmd/cinder-csi-plugin/main.go b/cmd/cinder-csi-plugin/main.go index be60568599..c257bce9da 100644 --- a/cmd/cinder-csi-plugin/main.go +++ b/cmd/cinder-csi-plugin/main.go @@ -17,8 +17,6 @@ limitations under the License. package main import ( - "flag" - "fmt" "os" "github.com/spf13/cobra" @@ -41,34 +39,9 @@ var ( ) func main() { - if err := flag.CommandLine.Parse([]string{}); err != nil { - klog.Fatalf("Unable to parse flags: %v", err) - } - cmd := &cobra.Command{ Use: "Cinder", Short: "CSI based Cinder driver", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // Glog requires this otherwise it complains. - if err := flag.CommandLine.Parse(nil); err != nil { - return fmt.Errorf("unable to parse flags: %w", err) - } - - // This is a temporary hack to enable proper logging until upstream dependencies - // are migrated to fully utilize klog instead of glog. - klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) - klog.InitFlags(klogFlags) - - // Sync the glog and klog flags. - cmd.Flags().VisitAll(func(f1 *pflag.Flag) { - f2 := klogFlags.Lookup(f1.Name) - if f2 != nil { - value := f1.Value.String() - _ = f2.Value.Set(value) - } - }) - return nil - }, Run: func(cmd *cobra.Command, args []string) { handle() }, @@ -99,7 +72,6 @@ func main() { } func handle() { - // Initialize cloud d := cinder.NewDriver(endpoint, cluster) openstack.InitOpenStackProvider(cloudConfig, httpEndpoint) diff --git a/cmd/client-keystone-auth/main.go b/cmd/client-keystone-auth/main.go index d219de556e..33193c4be3 100644 --- a/cmd/client-keystone-auth/main.go +++ b/cmd/client-keystone-auth/main.go @@ -138,24 +138,6 @@ func argumentsAreSet(url, user, project, password, domain, applicationCredential } func main() { - // Glog requires this otherwise it complains. - if err := flag.CommandLine.Parse(nil); err != nil { - klog.Fatalf("Unable to parse flags: %v", err) - } - // This is a temporary hack to enable proper logging until upstream dependencies - // are migrated to fully utilize klog instead of glog. - klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) - klog.InitFlags(klogFlags) - - // Sync the glog and klog flags. - flag.CommandLine.VisitAll(func(f1 *flag.Flag) { - f2 := klogFlags.Lookup(f1.Name) - if f2 != nil { - value := f1.Value.String() - _ = f2.Value.Set(value) - } - }) - var url string var domain string var user string @@ -186,10 +168,11 @@ func main() { logs.AddFlags(pflag.CommandLine) + klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) + klog.InitFlags(klogFlags) pflag.CommandLine.AddGoFlagSet(klogFlags) - kflag.InitFlags() - pflag.Parse() + kflag.InitFlags() if showVersion { fmt.Println(version.Version) diff --git a/cmd/k8s-keystone-auth/main.go b/cmd/k8s-keystone-auth/main.go index 8b34a9fb8b..fd6cdefe60 100644 --- a/cmd/k8s-keystone-auth/main.go +++ b/cmd/k8s-keystone-auth/main.go @@ -15,7 +15,6 @@ limitations under the License. package main import ( - "flag" "fmt" "os" @@ -29,46 +28,25 @@ import ( ) func main() { - // Glog requires this otherwise it complains. - err := flag.CommandLine.Parse(nil) - if err != nil { - klog.Fatalf("Unable to parse flags: %v", err) - } - var showVersion bool pflag.BoolVar(&showVersion, "version", false, "Show current version and exit") - // This is a temporary hack to enable proper logging until upstream dependencies - // are migrated to fully utilize klog instead of glog. - klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) - klog.InitFlags(klogFlags) - logs.AddFlags(pflag.CommandLine) keystone.AddExtraFlags(pflag.CommandLine) - // Sync the glog and klog flags. - flag.CommandLine.VisitAll(func(f1 *flag.Flag) { - f2 := klogFlags.Lookup(f1.Name) - if f2 != nil { - value := f1.Value.String() - _ = f2.Value.Set(value) - } - }) - - pflag.Parse() - - if showVersion { - fmt.Println(version.Version) - os.Exit(0) - } - logs.InitLogs() defer logs.FlushLogs() config := keystone.NewConfig() config.AddFlags(pflag.CommandLine) + kflag.InitFlags() + if showVersion { + fmt.Println(version.Version) + os.Exit(0) + } + if err := config.ValidateFlags(); err != nil { klog.Errorf("%v", err) os.Exit(1) diff --git a/cmd/manila-csi-plugin/main.go b/cmd/manila-csi-plugin/main.go index d0d2377056..1087a3326c 100644 --- a/cmd/manila-csi-plugin/main.go +++ b/cmd/manila-csi-plugin/main.go @@ -17,13 +17,11 @@ limitations under the License. package main import ( - "flag" "fmt" "os" "strings" "github.com/spf13/cobra" - "github.com/spf13/pflag" "k8s.io/cloud-provider-openstack/pkg/csi/manila" "k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient" "k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient" @@ -66,34 +64,9 @@ func validateShareProtocolSelector(v string) error { } func main() { - if err := flag.CommandLine.Parse([]string{}); err != nil { - klog.Fatalf("Unable to parse flags: %v", err) - } - cmd := &cobra.Command{ Use: os.Args[0], Short: "CSI Manila driver", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - // Glog requires this otherwise it complains. - if err := flag.CommandLine.Parse(nil); err != nil { - return fmt.Errorf("unable to parse flags: %w", err) - } - - // This is a temporary hack to enable proper logging until upstream dependencies - // are migrated to fully utilize klog instead of glog. - klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) - klog.InitFlags(klogFlags) - - // Sync the glog and klog flags. - cmd.Flags().VisitAll(func(f1 *pflag.Flag) { - f2 := klogFlags.Lookup(f1.Name) - if f2 != nil { - value := f1.Value.String() - _ = f2.Value.Set(value) - } - }) - return nil - }, Run: func(cmd *cobra.Command, args []string) { if err := validateShareProtocolSelector(protoSelector); err != nil { klog.Fatalf(err.Error()) @@ -128,8 +101,6 @@ func main() { Version: version.Version, } - cmd.Flags().AddGoFlagSet(flag.CommandLine) - cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "unix://tmp/csi.sock", "CSI endpoint") cmd.PersistentFlags().StringVar(&driverName, "drivername", "manila.csi.openstack.org", "name of the driver")