Skip to content

Commit eb3c30a

Browse files
authored
Configure controller-runtime to log with klog (#626)
Signed-off-by: Richard Wall <[email protected]>
1 parent ab786eb commit eb3c30a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

hack/e2e/values.venafi-kubernetes-agent.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ authentication:
1010

1111
extraArgs:
1212
- --logging-format=json
13+
- --log-level=2

pkg/client/client_venconn.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/http"
1313
"time"
1414

15-
"github.com/go-logr/logr"
1615
venapi "github.com/jetstack/venafi-connection-lib/api/v1alpha1"
1716
"github.com/jetstack/venafi-connection-lib/venafi_client"
1817
"github.com/jetstack/venafi-connection-lib/venafi_client/auth"
@@ -22,7 +21,6 @@ import (
2221
"k8s.io/apimachinery/pkg/types"
2322
"k8s.io/client-go/rest"
2423
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
25-
ctrlruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
2624

2725
"github.com/jetstack/preflight/api"
2826
"github.com/jetstack/preflight/pkg/version"
@@ -57,11 +55,6 @@ type VenConnClient struct {
5755
// `restcfg` is not mutated. `trustedCAs` is only used for connecting to Venafi
5856
// Cloud and Vault and can be left nil.
5957
func NewVenConnClient(restcfg *rest.Config, agentMetadata *api.AgentMetadata, installNS, venConnName, venConnNS string, trustedCAs *x509.CertPool, disableCompression bool) (*VenConnClient, error) {
60-
// TODO(mael): The rest of the codebase uses the standard "log" package,
61-
// venafi-connection-lib uses "go-logr/logr", and client-go uses "klog". We
62-
// should standardize on one of them, probably "slog".
63-
ctrlruntimelog.SetLogger(logr.Logger{})
64-
6558
if installNS == "" {
6659
return nil, errors.New("programmer mistake: installNS must be provided")
6760
}

pkg/logs/logs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"k8s.io/component-base/logs"
1515
logsapi "k8s.io/component-base/logs/api/v1"
1616
_ "k8s.io/component-base/logs/json/register"
17+
"k8s.io/klog/v2"
18+
ctrlruntimelog "sigs.k8s.io/controller-runtime/pkg/log"
1719
)
1820

1921
// venafi-kubernetes-agent follows [Kubernetes Logging Conventions] and writes
@@ -131,6 +133,11 @@ func Initialize() error {
131133
// to the global log logger. It can be removed when this is fixed upstream
132134
// in vcert: https://github.com/Venafi/vcert/pull/512
133135
vcertLog.SetPrefix("")
136+
137+
// The venafi-connection-lib client uses various controller-runtime packages
138+
// which emit log messages. Make sure those log messages are not discarded.
139+
ctrlruntimelog.SetLogger(klog.Background().WithValues("source", "controller-runtime"))
140+
134141
return nil
135142
}
136143

0 commit comments

Comments
 (0)