Skip to content

Commit 16e948a

Browse files
[release-1.28] Remove handling code for glog (#2534)
* barbican-kms-plugin: Remove unnecessary klog flag calls The comment here seems to have been left over when this module was extensively reworked in commit 7f1e9ed (#2278). In any case, it's unnecessary: the call to 'klog.InitFlags' with a 'nil' argument results in the flags being registered against the global 'flag.CommandLine' flagset [1], but since cobra uses pflag rather than flag this doesn't do anything useful. You can validate this by simply building the binary without this change: you'll note that we only have '-v' and '-vmodule' arguments, which are actually added by 'cli.Run' [2][3][4]. As such, we can simply remove the calls. [1] https://github.com/kubernetes/klog/blob/v2.100.1/klog.go#L432-L434 [2] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L46 [3] https://github.com/kubernetes/component-base/blob/v0.28.1/cli/run.go#L120 [4] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <[email protected]> * cinder-csi-plugin: Remove handling for glog The kubernetes ecosystem has migrated to klog now and the flags registered are for klog [1]. As such, there is no need to continue translating from glog to klog. [1] https://github.com/kubernetes/component-base/blob/v0.28.1/logs/logs.go#L73-L105 Signed-off-by: Stephen Finucane <[email protected]> * manila-csi-plugin: Remove handling for glog Remove the code to handle translation of legacy glog options to klog options since glog is no longer a thing in kubernetes. Signed-off-by: Stephen Finucane <[email protected]> * client-keystone-auth: Remove handling for glog As with our earlier change to cinder-csi-plugin, the handling code for glog is no longer necessary now that the kubernetes ecosystem has migrated to klog. However, unlike that change, client-keystone-auth is not using cobra but rather plain old pflag. As a result, it is still actually registering all the klog options. We preserve this behavior. Signed-off-by: Stephen Finucane <[email protected]> * k8s-keystone-auth: Remove handling for glog This is quite similar but not identical to the earlier removal of glog handling in client-keystone-auth. As with that utility, we are using pflag rather than cobra here, but unlike that utility the klog options are not being registered. Signed-off-by: Stephen Finucane <[email protected]> --------- Signed-off-by: Stephen Finucane <[email protected]> Co-authored-by: Stephen Finucane <[email protected]>
1 parent a6d00a7 commit 16e948a

File tree

5 files changed

+2
-103
lines changed

5 files changed

+2
-103
lines changed

cmd/barbican-kms-plugin/main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"flag"
2120
"os"
2221
"os/signal"
2322

@@ -35,12 +34,6 @@ var (
3534
)
3635

3736
func main() {
38-
flag.Parse()
39-
40-
// This is a temporary hack to enable proper logging until upstream dependencies
41-
// are migrated to fully utilize klog instead of glog.
42-
klog.InitFlags(nil)
43-
4437
cmd := &cobra.Command{
4538
Use: "barbican-kms-plugin",
4639
Short: "Barbican KMS plugin for Kubernetes",

cmd/cinder-csi-plugin/main.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"flag"
21-
"fmt"
2220
"os"
2321

2422
"github.com/spf13/cobra"
@@ -41,34 +39,9 @@ var (
4139
)
4240

4341
func main() {
44-
if err := flag.CommandLine.Parse([]string{}); err != nil {
45-
klog.Fatalf("Unable to parse flags: %v", err)
46-
}
47-
4842
cmd := &cobra.Command{
4943
Use: "Cinder",
5044
Short: "CSI based Cinder driver",
51-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
52-
// Glog requires this otherwise it complains.
53-
if err := flag.CommandLine.Parse(nil); err != nil {
54-
return fmt.Errorf("unable to parse flags: %w", err)
55-
}
56-
57-
// This is a temporary hack to enable proper logging until upstream dependencies
58-
// are migrated to fully utilize klog instead of glog.
59-
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
60-
klog.InitFlags(klogFlags)
61-
62-
// Sync the glog and klog flags.
63-
cmd.Flags().VisitAll(func(f1 *pflag.Flag) {
64-
f2 := klogFlags.Lookup(f1.Name)
65-
if f2 != nil {
66-
value := f1.Value.String()
67-
_ = f2.Value.Set(value)
68-
}
69-
})
70-
return nil
71-
},
7245
Run: func(cmd *cobra.Command, args []string) {
7346
handle()
7447
},
@@ -99,7 +72,6 @@ func main() {
9972
}
10073

10174
func handle() {
102-
10375
// Initialize cloud
10476
d := cinder.NewDriver(endpoint, cluster)
10577
openstack.InitOpenStackProvider(cloudConfig, httpEndpoint)

cmd/client-keystone-auth/main.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,6 @@ func argumentsAreSet(url, user, project, password, domain, applicationCredential
138138
}
139139

140140
func main() {
141-
// Glog requires this otherwise it complains.
142-
if err := flag.CommandLine.Parse(nil); err != nil {
143-
klog.Fatalf("Unable to parse flags: %v", err)
144-
}
145-
// This is a temporary hack to enable proper logging until upstream dependencies
146-
// are migrated to fully utilize klog instead of glog.
147-
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
148-
klog.InitFlags(klogFlags)
149-
150-
// Sync the glog and klog flags.
151-
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
152-
f2 := klogFlags.Lookup(f1.Name)
153-
if f2 != nil {
154-
value := f1.Value.String()
155-
_ = f2.Value.Set(value)
156-
}
157-
})
158-
159141
var url string
160142
var domain string
161143
var user string
@@ -186,6 +168,8 @@ func main() {
186168

187169
logs.AddFlags(pflag.CommandLine)
188170

171+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
172+
klog.InitFlags(klogFlags)
189173
pflag.CommandLine.AddGoFlagSet(klogFlags)
190174

191175
kflag.InitFlags()

cmd/k8s-keystone-auth/main.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
package main
1616

1717
import (
18-
"flag"
1918
"fmt"
2019
"os"
2120

@@ -29,32 +28,12 @@ import (
2928
)
3029

3130
func main() {
32-
// Glog requires this otherwise it complains.
33-
err := flag.CommandLine.Parse(nil)
34-
if err != nil {
35-
klog.Fatalf("Unable to parse flags: %v", err)
36-
}
37-
3831
var showVersion bool
3932
pflag.BoolVar(&showVersion, "version", false, "Show current version and exit")
4033

41-
// This is a temporary hack to enable proper logging until upstream dependencies
42-
// are migrated to fully utilize klog instead of glog.
43-
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
44-
klog.InitFlags(klogFlags)
45-
4634
logs.AddFlags(pflag.CommandLine)
4735
keystone.AddExtraFlags(pflag.CommandLine)
4836

49-
// Sync the glog and klog flags.
50-
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
51-
f2 := klogFlags.Lookup(f1.Name)
52-
if f2 != nil {
53-
value := f1.Value.String()
54-
_ = f2.Value.Set(value)
55-
}
56-
})
57-
5837
logs.InitLogs()
5938
defer logs.FlushLogs()
6039

cmd/manila-csi-plugin/main.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"flag"
2120
"fmt"
2221
"os"
2322
"strings"
2423

2524
"github.com/spf13/cobra"
26-
"github.com/spf13/pflag"
2725
"k8s.io/cloud-provider-openstack/pkg/csi/manila"
2826
"k8s.io/cloud-provider-openstack/pkg/csi/manila/csiclient"
2927
"k8s.io/cloud-provider-openstack/pkg/csi/manila/manilaclient"
@@ -66,34 +64,9 @@ func validateShareProtocolSelector(v string) error {
6664
}
6765

6866
func main() {
69-
if err := flag.CommandLine.Parse([]string{}); err != nil {
70-
klog.Fatalf("Unable to parse flags: %v", err)
71-
}
72-
7367
cmd := &cobra.Command{
7468
Use: os.Args[0],
7569
Short: "CSI Manila driver",
76-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
77-
// Glog requires this otherwise it complains.
78-
if err := flag.CommandLine.Parse(nil); err != nil {
79-
return fmt.Errorf("unable to parse flags: %w", err)
80-
}
81-
82-
// This is a temporary hack to enable proper logging until upstream dependencies
83-
// are migrated to fully utilize klog instead of glog.
84-
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
85-
klog.InitFlags(klogFlags)
86-
87-
// Sync the glog and klog flags.
88-
cmd.Flags().VisitAll(func(f1 *pflag.Flag) {
89-
f2 := klogFlags.Lookup(f1.Name)
90-
if f2 != nil {
91-
value := f1.Value.String()
92-
_ = f2.Value.Set(value)
93-
}
94-
})
95-
return nil
96-
},
9770
Run: func(cmd *cobra.Command, args []string) {
9871
if err := validateShareProtocolSelector(protoSelector); err != nil {
9972
klog.Fatalf(err.Error())
@@ -128,8 +101,6 @@ func main() {
128101
Version: version.Version,
129102
}
130103

131-
cmd.Flags().AddGoFlagSet(flag.CommandLine)
132-
133104
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "unix://tmp/csi.sock", "CSI endpoint")
134105

135106
cmd.PersistentFlags().StringVar(&driverName, "drivername", "manila.csi.openstack.org", "name of the driver")

0 commit comments

Comments
 (0)