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
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