Describe the bug
Fatal error: concurrent map writes
Environments
Version:
OS:
To Reproduce
Steps to reproduce the behavior:
Deploy the helm chart for pvc auto-resizer in any env where controller.args.useK8sMetricsApi : true,
controller.args.prometheusURL is unset and webhook.pvcMutatingWebhook.enabled : false
Expected behavior
i would expect controller to run fine
Describe the bug Fatal error: concurrent map writes
Environments
To Reproduce Steps to reproduce the behavior:
controller.args.useK8sMetricsApi : true
,controller.args.prometheusURL is unset
andwebhook.pvcMutatingWebhook.enabled : false
Expected behavior i would expect controller to run fine
Additional context
Map is created here https://github.com/topolvm/pvc-autoresizer/blob/v0.14.0/internal/runners/k8s_metrics_api_client.go#L44
Go function is called https://github.com/topolvm/pvc-autoresizer/blob/v0.14.0/internal/runners/k8s_metrics_api_client.go#L50
And that function modify the map without locking https://github.com/topolvm/pvc-autoresizer/blob/v0.14.0/internal/runners/k8s_metrics_api_client.go#L87-L88
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"setup","msg":"starting manager"}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.metrics","msg":"Starting metrics server"}
{"level":"info","ts":"2024-06-28T16:05:20Z","msg":"starting server","kind":"health probe","addr":":8081"}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.metrics","msg":"Serving metrics server","bindAddress":":8080","secure":false}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.webhook","msg":"Starting webhook server"}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.certwatcher","msg":"Updated current TLS certificate"}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.webhook","msg":"Serving webhook server","host":"","port":9443}
{"level":"info","ts":"2024-06-28T16:05:20Z","logger":"controller-runtime.certwatcher","msg":"Starting certificate watcher"}
I0628 16:05:20.535385 1 leaderelection.go:250] attempting to acquire leader lease pep-system/49e22f61.topolvm.io...
I0628 16:05:38.710105 1 leaderelection.go:260] successfully acquired lease pep-system/49e22f61.topolvm.io
fatal error: concurrent map writes
goroutine 932 [running]:
github.com/topolvm/pvc-autoresizer/internal/runners.getPVCUsage(0x0?, {0xc00070c380, 0x33}, 0xc000271ef0, {0x1bc23c0, 0xc0021b0000})
github.com/topolvm/pvc-autoresizer/internal/runners.(*k8sMetricsApiClient).GetMetrics.func1()
net.(*netFD).accept(0xc00048c380)
net.(*TCPListener).accept(0xc0003f2580)
net.(*TCPListener).Accept(0xc0003f2580)
crypto/tls.(*listener).Accept(0xc0004a06a8)
net/http.(*Server).Serve(0xc00032c000, {0x1bb8160, 0xc0004a06a8})
sigs.k8s.io/controller-runtime/pkg/webhook.(*DefaultServer).Start(0xc000258000, {0x1bc23c0, 0xc00011def0})
sigs.k8s.io/controller-runtime/pkg/manager.(*runnableGroup).reconcile.func1(0xc0001e7660)
created by sigs.k8s.io/controller-runtime/pkg/manager.(*runnableGroup).reconcile in goroutine 86