Azure / Azure/kubernetes-kms

log-format-json throws panic in v0.5.0

Open
#312 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
181
Forks
72
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When trying to use the `-log-format-json=true` flag, kms panics:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xafb309]

goroutine 1 [running]:
k8s.io/component-base/logs/json.(*nopSync).Write(0x8?, {0xc0000fec00?, 0x0?, 0xc9a865?})
:1 +0x29
go.uber.org/zap/zapcore.(*lockedWriteSyncer).Write(0xc000352990, {0xc0000fec00?, 0x23348a0?, 0x12a8c20?})
/go/pkg/mod/go.uber.org/zap@v1.24.0/zapcore/write_syncer.go:66 +0x72
go.uber.org/zap/zapcore.(*ioCore).Write(0xc00031d260, {0x0, {0xc1461a375222ccdc, 0x23348a0, 0x12a8c20}, {0x0, 0x0}, {0xc9df10, 0xf}, {0x1, ...}, ...}, ...)
/go/pkg/mod/go.uber.org/zap@v1.24.0/zapcore/core.go:99 +0xb5
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc00035a1a0, {0xc000364000, 0x2, 0x2})
/go/pkg/mod/go.uber.org/zap@v1.24.0/zapcore/entry.go:255 +0x1d9
github.com/go-logr/zapr.(*zapLogger).Info(0xc00031d2f0, 0x0, {0xc9df10?, 0x5a3522?}, {0xc0003564e0, 0x2, 0x2})
/go/pkg/mod/github.com/go-logr/zapr@v1.2.3/zapr.go:210 +0xa5
github.com/go-logr/logr.Logger.Info({{0xdc20c8?, 0xc00031d2f0?}, 0x0?}, {0xc9df10, 0xf}, {0xc0003564e0, 0x2, 0x2})
/go/pkg/mod/github.com/go-logr/logr@v1.2.4/logr.go:278 +0xe4
k8s.io/klog/v2.(*loggingT).infoS(0x3?, 0x20?, {0x0?, 0x0?}, 0xc00025dad0?, {0xc9df10?, 0xdbd568?}, {0xc0003564e0, 0x2, 0x2})
/go/pkg/mod/k8s.io/klog/v2@v2.100.1/klog.go:780 +0x113
k8s.io/klog/v2.InfoS(...)
/go/pkg/mod/k8s.io/klog/v2@v2.100.1/klog.go:1512
github.com/Azure/kubernetes-kms/pkg/metrics.InitMetricsExporter({0xc9a865, 0xa}, {0xc9472b, 0x4})
/workspace/pkg/metrics/exporter.go:17 +0xf6
main.main()
/workspace/main.go:82 +0x195
```

**Steps To Reproduce**
`/kubernetes-kms -log-format-json=true`

**Expected behavior**
Does not panic

**KMS Plugin for Key Vault version**
v0.5.0

**Kubernetes version**
v1.26.9

Contributor guide

Open the contributing guide

Research direction

Start with pkg/metrics/exporter.go:17, where the stack trace shows the panic during metrics initialization, then inspect main.go:82 and reproduce with /kubernetes-kms -log-format-json=true. Done means the command no longer panics when JSON logging is enabled, with the reported behavior covered by an appropriate test if the repository provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend, observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.