Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove handling code for glog #2325

Merged
merged 7 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions cmd/barbican-kms-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"flag"
"os"
"os/signal"

Expand All @@ -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",
Expand Down
28 changes: 0 additions & 28 deletions cmd/cinder-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package main

import (
"flag"
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer note: This copies all the options from the commandLine flagset defined here to klogFlags.

This includes --log_dir, --log_file, et al.


// 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)
}
})
Comment on lines -63 to -69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This iterates over the cobra flags. For each one it looks up a correspondingly named klog flag and sets its value to the value of the cobra flag.

IOW it has no effect on the cobra flags, which are the only flags now in use.

return nil
},
Run: func(cmd *cobra.Command, args []string) {
handle()
},
Expand Down Expand Up @@ -99,7 +72,6 @@ func main() {
}

func handle() {

// Initialize cloud
d := cinder.NewDriver(endpoint, cluster)
openstack.InitOpenStackProvider(cloudConfig, httpEndpoint)
Expand Down
23 changes: 3 additions & 20 deletions cmd/client-keystone-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now done below, so we keep the same flags.


// 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)
}
})
Comment on lines -151 to -157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets flags in flag.CommandLine with a corresponding klogflag to the value of the klog flag.

Nothing is now using these flags, so this is redundant.


var url string
var domain string
var user string
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if showVersion {
fmt.Println(version.Version)
Expand Down
34 changes: 6 additions & 28 deletions cmd/k8s-keystone-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
package main

import (
"flag"
"fmt"
"os"

Expand All @@ -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)
}
})
Comment on lines -49 to -56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to set values in flag.CommandLine, although nothing is using it?

Copy link
Member Author

@stephenfin stephenfin Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it's used alright: the kflag.InitFlags call below adds flag.CommandLine as a flagset. However, it's not doing anything useful since no upstream dependency should be using glog any more, which means there's nothing valuable to copy. You can test this by sticking some debug printf calls in here (which is what I did 😅)


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)
Expand Down
29 changes: 0 additions & 29 deletions cmd/manila-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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")
Expand Down