@@ -11,6 +11,7 @@ import (
11
11
"crypto/x509/pkix"
12
12
"encoding/pem"
13
13
"errors"
14
+ "flag"
14
15
"fmt"
15
16
"math/big"
16
17
"net"
@@ -31,7 +32,7 @@ import (
31
32
"github.com/go-logr/logr"
32
33
grpc_runtime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
33
34
"github.com/spf13/cobra"
34
- flag "github.com/spf13/pflag"
35
+ "github.com/spf13/pflag"
35
36
"github.com/spf13/viper"
36
37
gitopsv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1"
37
38
"github.com/weaveworks/go-checkpoint"
@@ -81,6 +82,7 @@ import (
81
82
"k8s.io/client-go/informers"
82
83
"k8s.io/client-go/kubernetes"
83
84
k8scache "k8s.io/client-go/tools/cache"
85
+ "k8s.io/klog/v2"
84
86
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
85
87
ctrl "sigs.k8s.io/controller-runtime"
86
88
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -143,6 +145,7 @@ type Params struct {
143
145
CostEstimationFilters string `mapstructure:"cost-estimation-filters"`
144
146
CostEstimationAPIRegion string `mapstructure:"cost-estimation-api-region"`
145
147
CostEstimationFilename string `mapstructure:"cost-estimation-csv-file"`
148
+ KLogVerbosity string `mapstructure:"klog-verbosity"`
146
149
}
147
150
148
151
type OIDCAuthenticationOptions struct {
@@ -227,12 +230,13 @@ func NewAPIServerCommand(log logr.Logger, tempDir string) *cobra.Command {
227
230
cmdFlags .Bool ("use-k8s-cached-clients" , true , "Enables the use of cached clients" )
228
231
cmdFlags .String ("ui-config" , "" , "UI configuration, JSON encoded" )
229
232
cmdFlags .String ("pipeline-controller-address" , pipelines .DefaultPipelineControllerAddress , "Pipeline controller address" )
233
+ cmdFlags .String ("klog-verbosity" , "0" , "Set the logging of the klog library" )
230
234
231
235
cmdFlags .String ("cost-estimation-filters" , "" , "Cost estimation filters" )
232
236
cmdFlags .String ("cost-estimation-api-region" , "" , "API region for cost estimation queries" )
233
237
cmdFlags .String ("cost-estimation-csv-file" , "" , "Filename to parse as Cost Estimation data" )
234
238
235
- cmdFlags .VisitAll (func (fl * flag .Flag ) {
239
+ cmdFlags .VisitAll (func (fl * pflag .Flag ) {
236
240
if strings .HasPrefix (fl .Name , "cost-estimation" ) {
237
241
cobra .CheckErr (cmdFlags .MarkHidden (fl .Name ))
238
242
}
@@ -306,10 +310,33 @@ func initializeConfig(cmd *cobra.Command) error {
306
310
return nil
307
311
}
308
312
309
- func StartServer (ctx context.Context , log logr.Logger , tempDir string , p Params ) error {
313
+ // configureKlogVerbosity sets the klog verbosity level.
314
+ // This log is used by the client-go k8s libraries and can be useful for debugging
315
+ // client-go's network requests.
316
+ //
317
+ // v=5 - log CRD cache things?
318
+ // v=6 - log requests (e.g. GET url)
319
+ // v=7 - log req/res headers
320
+ // v=8 - log res body
321
+ func configureKLogVerbosity (v string ) error {
322
+ klog .InitFlags (nil )
323
+ err := flag .Set ("v" , v )
324
+ if err != nil {
325
+ return fmt .Errorf ("could not set klog verbosity: %w" , err )
326
+ }
327
+ flag .Parse ()
328
+ return nil
329
+ }
310
330
331
+ func StartServer (ctx context.Context , log logr.Logger , tempDir string , p Params ) error {
311
332
featureflags .SetFromEnv (os .Environ ())
312
333
334
+ log .Info ("Setting klog verbosity" , "verbosity" , p .KLogVerbosity )
335
+ err := configureKLogVerbosity (p .KLogVerbosity )
336
+ if err != nil {
337
+ return fmt .Errorf ("could not configure klog verbosity: %w" , err )
338
+ }
339
+
313
340
if p .CAPITemplatesNamespace == "" {
314
341
return errors .New ("CAPI templates namespace not set" )
315
342
}
@@ -327,7 +354,7 @@ func StartServer(ctx context.Context, log logr.Logger, tempDir string, p Params)
327
354
schemeBuilder = append (schemeBuilder , capiv1 .AddToScheme )
328
355
}
329
356
330
- err : = schemeBuilder .AddToScheme (scheme )
357
+ err = schemeBuilder .AddToScheme (scheme )
331
358
if err != nil {
332
359
return err
333
360
}
0 commit comments