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

Json output for logs #94

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/component-base v0.24.1
k8s.io/klog/v2 v2.120.0
sigs.k8s.io/secrets-store-csi-driver v1.4.0
sigs.k8s.io/yaml v1.4.0
Expand All @@ -20,6 +21,7 @@ require (
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.2.0
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.7 // indirect
Expand All @@ -35,6 +37,10 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
Expand All @@ -52,4 +58,4 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
)
174 changes: 0 additions & 174 deletions go.sum

This file was deleted.

15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"google.golang.org/grpc"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/component-base/config"
jlogs "k8s.io/component-base/logs/json"
"k8s.io/klog/v2"
csidriver "sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"

Expand All @@ -22,6 +24,7 @@ import (
var (
endpointDir = flag.String("provider-volume", "/etc/kubernetes/secrets-store-csi-providers", "Rendezvous directory for provider socket")
driverWriteSecrets = flag.Bool("driver-writes-secrets", false, "The driver will do the write instead of the plugin")
logFormatJSON = flag.Bool("log-format-json", false, "set log formatter to json")
qps = flag.Int("qps", 5, "Maximum query per second to the Kubernetes API server. To mount the requested secret on the pod, the AWS CSI provider lookups the region of the pod and the role ARN associated with the service account by calling the K8s APIs. Increase the value if the provider is throttled by client-side limit to the API server.")
burst = flag.Int("burst", 10, "Maximum burst for throttle. To mount the requested secret on the pod, the AWS CSI provider lookups the region of the pod and the role ARN associated with the service account by calling the K8s APIs. Increase the value if the provider is throttled by client-side limit to the API server.")
)
Expand All @@ -30,11 +33,19 @@ var (
// rountine starts up the gRPC server that will listen for incoming mount
// requests.
func main() {

klog.Infof("Starting %s version %s", auth.ProviderName, server.Version)
klog.InitFlags(nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

We're concerned about these init flags conflicting with future changes to our repository. If they are not necessary, can you remove them?

Copy link
Author

Choose a reason for hiding this comment

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

but there is in the klog documentation:
Use klog.InitFlags(nil) explicitly for initializing global flags as we no longer use init() method to register the flags

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong but we dont use klog.init() anywhere in the first place (i.e. we don't initialize global flags for klog).

defer klog.Flush()

flag.Parse() // Parse command line flags

if *logFormatJSON {
jsonFactory := json.Factory{}
logger, _ := jsonFactory.Create(config.LoggingConfiguration{Format: "json"})
klog.SetLogger(logger)
}

klog.Infof("Starting %s version %s", auth.ProviderName, server.Version)

//socket on which to listen to for driver calls
endpoint := fmt.Sprintf("%s/aws.sock", *endpointDir)
os.Remove(endpoint) // Make sure to start clean.
Expand Down