Skip to content

Commit 3ae44c7

Browse files
committed
[WIP] add structured logs
1 parent 2ce671b commit 3ae44c7

File tree

6 files changed

+58
-43
lines changed

6 files changed

+58
-43
lines changed

cmd/main.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
package main
22

33
import (
4-
"log"
54
"os"
65

6+
"github.com/rs/zerolog/log"
7+
78
"github.com/unagex/kondense/pkg/controller"
89
"github.com/unagex/kondense/pkg/utils"
910
_ "k8s.io/client-go/plugin/pkg/client/auth"
1011
)
1112

1213
func main() {
13-
// create logger.
14-
l := log.Default()
15-
l.SetFlags(log.Lshortfile | log.LstdFlags)
16-
1714
// get pod name and namespace.
1815
name := os.Getenv("HOSTNAME")
1916
namespaceByte, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
2017
if err != nil {
21-
l.Fatal(err)
18+
log.Fatal().Err(err)
2219
}
2320
namespace := string(namespaceByte)
2421

2522
client, err := utils.GetClient()
2623
if err != nil {
27-
l.Fatal(err)
24+
log.Fatal().Err(err)
2825
}
2926
rawClient, err := utils.GetRawClient()
3027
if err != nil {
31-
l.Fatal(err)
28+
log.Fatal().Err(err)
3229
}
3330

3431
bt, err := utils.GetBearerToken()
3532
if err != nil {
36-
l.Fatalf("failed to get k8s bearer token: %s", err)
33+
log.Fatal().Err(err).Msg("failed to get k8s bearer token")
3734
}
3835

3936
reconciler := controller.Reconciler{
4037
Client: client,
4138
RawClient: rawClient,
42-
L: l,
4339

4440
BearerToken: bt,
4541

go.mod

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ require (
88
k8s.io/client-go v0.29.3
99
)
1010

11+
require (
12+
github.com/mattn/go-colorable v0.1.13 // indirect
13+
github.com/mattn/go-isatty v0.0.19 // indirect
14+
)
15+
1116
require (
1217
github.com/davecgh/go-spew v1.1.1 // indirect
1318
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
@@ -28,6 +33,7 @@ require (
2833
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2934
github.com/onsi/ginkgo/v2 v2.17.1 // indirect
3035
github.com/onsi/gomega v1.32.0 // indirect
36+
github.com/rs/zerolog v1.32.0
3137
golang.org/x/net v0.22.0 // indirect
3238
golang.org/x/oauth2 v0.18.0 // indirect
3339
golang.org/x/sys v0.18.0 // indirect

go.sum

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
12
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
23
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
34
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -13,6 +14,7 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
1314
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
1415
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
1516
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
17+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
1618
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
1719
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
1820
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@@ -44,6 +46,11 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4446
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4547
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
4648
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
49+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
50+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
51+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
52+
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
53+
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
4754
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
4855
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
4956
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -55,10 +62,14 @@ github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8
5562
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
5663
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
5764
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
65+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5866
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5967
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6068
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
6169
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
70+
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
71+
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
72+
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
6273
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
6374
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
6475
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -96,6 +107,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
96107
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
97108
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
98109
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
110+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
111+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
112+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99113
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
100114
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
101115
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

pkg/controller/container.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15+
"github.com/rs/zerolog/log"
1516
"github.com/unagex/kondense/pkg/utils"
1617
corev1 "k8s.io/api/core/v1"
1718
)
@@ -26,13 +27,13 @@ func (r *Reconciler) ReconcileContainer(pod *corev1.Pod, container corev1.Contai
2627

2728
err := r.UpdateStats(pod, container)
2829
if err != nil {
29-
r.L.Print(err)
30+
log.Error().Err(err)
3031
return
3132
}
3233

3334
err = r.KondenseContainer(container)
3435
if err != nil {
35-
r.L.Print(err)
36+
log.Error().Err(err)
3637
}
3738
}
3839

@@ -72,7 +73,7 @@ func (r *Reconciler) UpdateStats(pod *corev1.Pod, container corev1.Container) er
7273
}
7374

7475
s := r.CStats[container.Name]
75-
r.L.Printf("container=%s memory_limit=%d memory_time_to_dec=%d memory_total=%d, memory_integral=%d, cpu_limit=%dm, cpu_average=%dm",
76+
log.Info().Msgf("container=%s memory_limit=%d memory_time_to_dec=%d memory_total=%d, memory_integral=%d, cpu_limit=%dm, cpu_average=%dm",
7677
container.Name,
7778
s.Mem.Limit, s.Mem.GraceTicks, s.Mem.PrevTotal, s.Mem.Integral,
7879
s.Cpu.Limit, s.Cpu.Avg,
@@ -230,11 +231,11 @@ func (r *Reconciler) Adjust(containerName string, memFactor float64, cpuFactor f
230231
// renew k8s token
231232
bt, err := utils.GetBearerToken()
232233
if err != nil {
233-
r.L.Fatalf("failed to renew k8s bearer token: %s", err)
234+
log.Fatal().Msgf("failed to renew k8s bearer token: %s", err)
234235
}
235236

236237
r.Mu.Lock()
237-
r.L.Print("renewed k8s bearer token.")
238+
log.Info().Msg("renewed k8s bearer token.")
238239
r.BearerToken = bt
239240
r.Mu.Unlock()
240241

@@ -244,8 +245,7 @@ func (r *Reconciler) Adjust(containerName string, memFactor float64, cpuFactor f
244245
return fmt.Errorf("failed to patch container, want status code: %d, got %d",
245246
http.StatusOK, resp.StatusCode)
246247
}
247-
r.L.Printf("patched container %s with mem factor: %.2f and new memory: %d bytes and with cpu factor : %.2f and new cpu: %dm.",
248-
containerName, memFactor, newMemory, cpuFactor, newCPU)
248+
log.Info().Str("container", containerName).Float64("memFactor", memFactor).Uint64("newMemory", newMemory).Float64("cpuFactor", cpuFactor).Uint64("newCPU", newCPU).Msg("patched container")
249249

250250
s.Mem.Integral = 0
251251

pkg/controller/controller.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package controller
22

33
import (
44
"context"
5-
"log"
65
"net/http"
76
"sync"
87
"time"
98

9+
"github.com/rs/zerolog/log"
1010
corev1 "k8s.io/api/core/v1"
1111
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/client-go/kubernetes"
@@ -15,7 +15,6 @@ import (
1515
type Reconciler struct {
1616
Client *kubernetes.Clientset
1717
RawClient *http.Client
18-
L *log.Logger
1918

2019
Mu sync.Mutex
2120
BearerToken string
@@ -34,11 +33,11 @@ func (r *Reconciler) Reconcile() {
3433

3534
pod, err := r.Client.CoreV1().Pods(r.Namespace).Get(context.TODO(), r.Name, v1.GetOptions{})
3635
if err != nil {
37-
r.L.Println(err)
36+
log.Error().Err(err)
3837
continue
3938
}
4039
if pod.Status.QOSClass != corev1.PodQOSGuaranteed {
41-
r.L.Printf("error kondense is only allowed for pods with a QoS class of Guaranteed, got: %s.", pod.Status.QOSClass)
40+
log.Error().Msgf("error kondense is only allowed for pods with a QoS class of Guaranteed, got: %s.", pod.Status.QOSClass)
4241
continue
4342
}
4443

pkg/controller/init.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88
"strings"
99

10+
"github.com/rs/zerolog/log"
1011
"github.com/unagex/kondense/pkg/utils"
1112
corev1 "k8s.io/api/core/v1"
1213
"k8s.io/apimachinery/pkg/api/resource"
@@ -59,13 +60,13 @@ func (r *Reconciler) getMemoryMin(containerName string) uint64 {
5960
if v, ok := os.LookupEnv(env); ok {
6061
minQ, err := resource.ParseQuantity(v)
6162
if err != nil {
62-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %d microseconds.",
63+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %d microseconds.",
6364
env, env, DefaultMemMin)
6465
return DefaultMemMin
6566
}
6667
min := minQ.Value()
6768
if min <= 0 {
68-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %d microseconds",
69+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %d microseconds",
6970
env, env, DefaultMemMin)
7071
return DefaultMemMin
7172
}
@@ -80,19 +81,18 @@ func (r *Reconciler) getMemoryMax(containerName string) uint64 {
8081
if v, ok := os.LookupEnv(env); ok {
8182
maxQ, err := resource.ParseQuantity(v)
8283
if err != nil {
83-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %d microseconds.",
84+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %d microseconds.",
8485
env, env, DefaultMemMax)
8586
return DefaultMemMax
8687
}
8788
max := maxQ.Value()
8889
if max <= 0 {
89-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %d microseconds",
90+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %d microseconds",
9091
env, env, DefaultMemMax)
9192
return DefaultMemMax
9293
}
9394
return uint64(max)
9495
}
95-
9696
return DefaultMemMax
9797
}
9898

@@ -101,7 +101,7 @@ func (r *Reconciler) getMemoryInterval(containerName string) uint64 {
101101
if v, ok := os.LookupEnv(env); ok {
102102
interval, err := strconv.ParseUint(v, 10, 64)
103103
if err != nil {
104-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
104+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
105105
env, env, DefaultMemInterval)
106106
return DefaultMemInterval
107107
}
@@ -116,12 +116,12 @@ func (r *Reconciler) getMemoryTargetPressure(containerName string) uint64 {
116116
if v, ok := os.LookupEnv(env); ok {
117117
targetPressure, err := strconv.ParseUint(v, 10, 64)
118118
if err != nil {
119-
r.L.Printf("error cannot parse environment variable: %s pressure. Set %s to default value: %d.",
119+
log.Error().Msgf("error cannot parse environment variable: %s pressure. Set %s to default value: %d.",
120120
env, env, DefaultMemTargetPressure)
121121
return DefaultMemTargetPressure
122122
}
123123
if targetPressure == 0 {
124-
r.L.Printf("error environment variable: %s should be more than 0. Set %s to default value: %d.",
124+
log.Error().Msgf("error environment variable: %s should be more than 0. Set %s to default value: %d.",
125125
env, env, DefaultMemTargetPressure)
126126
return DefaultMemTargetPressure
127127
}
@@ -136,12 +136,12 @@ func (r *Reconciler) getMemoryMaxInc(containerName string) float64 {
136136
if v, ok := os.LookupEnv(env); ok {
137137
maxInc, err := strconv.ParseFloat(v, 64)
138138
if err != nil {
139-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
139+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
140140
env, env, DefaultMemMaxInc)
141141
return DefaultMemMaxInc
142142
}
143143
if maxInc <= 0 {
144-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
144+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
145145
env, env, DefaultMemMaxInc)
146146
return DefaultMemMaxInc
147147
}
@@ -156,12 +156,12 @@ func (r *Reconciler) getMemoryMaxDec(containerName string) float64 {
156156
if v, ok := os.LookupEnv(env); ok {
157157
maxDec, err := strconv.ParseFloat(v, 64)
158158
if err != nil {
159-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
159+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
160160
env, env, DefaultMemMaxDec)
161161
return DefaultMemMaxDec
162162
}
163163
if maxDec <= 0 || maxDec >= 1 {
164-
r.L.Printf("error environment variable: %s should be between 0 and 1 exclusive. Set %s to default value: %.2f.",
164+
log.Error().Msgf("error environment variable: %s should be between 0 and 1 exclusive. Set %s to default value: %.2f.",
165165
env, env, DefaultMemMaxDec)
166166
return DefaultMemMaxDec
167167
}
@@ -176,12 +176,12 @@ func (r *Reconciler) getMemoryCoeffInc(containerName string) float64 {
176176
if v, ok := os.LookupEnv(env); ok {
177177
coeffInc, err := strconv.ParseFloat(v, 64)
178178
if err != nil {
179-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
179+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
180180
env, env, DefaultMemCoeffInc)
181181
return DefaultMemCoeffInc
182182
}
183183
if coeffInc <= 0 {
184-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
184+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
185185
env, env, DefaultMemCoeffInc)
186186
return DefaultMemCoeffInc
187187
}
@@ -196,12 +196,12 @@ func (r *Reconciler) getMemoryCoeffDec(containerName string) float64 {
196196
if v, ok := os.LookupEnv(env); ok {
197197
coeffDec, err := strconv.ParseFloat(v, 64)
198198
if err != nil {
199-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
199+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %.2f.",
200200
env, env, DefaultMemCoeffDec)
201201
return DefaultMemCoeffDec
202202
}
203203
if coeffDec <= 0 {
204-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
204+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %.2f.",
205205
env, env, DefaultMemCoeffDec)
206206
return DefaultMemCoeffDec
207207
}
@@ -216,13 +216,13 @@ func (r *Reconciler) getCPUMin(containerName string) uint64 {
216216
if v, ok := os.LookupEnv(env); ok {
217217
minQ, err := resource.ParseQuantity(v)
218218
if err != nil {
219-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %d milliCPU(s).",
219+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %d milliCPU(s).",
220220
env, env, DefaultCPUMin)
221221
return DefaultCPUMin
222222
}
223223
min := minQ.MilliValue()
224224
if min <= 0 {
225-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %d milliCPU(s)",
225+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %d milliCPU(s)",
226226
env, env, DefaultCPUMin)
227227
return DefaultCPUMin
228228
}
@@ -237,13 +237,13 @@ func (r *Reconciler) getCPUMax(containerName string) uint64 {
237237
if v, ok := os.LookupEnv(env); ok {
238238
maxQ, err := resource.ParseQuantity(v)
239239
if err != nil {
240-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %d milliCPU(s).",
240+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %d milliCPU(s).",
241241
env, env, DefaultCPUMax)
242242
return DefaultCPUMax
243243
}
244244
max := maxQ.MilliValue()
245245
if max <= 0 {
246-
r.L.Printf("error environment variable: %s should be bigger than 0. Set %s to default value: %d milliCPU(s)",
246+
log.Error().Msgf("error environment variable: %s should be bigger than 0. Set %s to default value: %d milliCPU(s)",
247247
env, env, DefaultCPUMax)
248248
return DefaultCPUMax
249249
}
@@ -258,7 +258,7 @@ func (r *Reconciler) getCPUInterval(containerName string) uint64 {
258258
if v, ok := os.LookupEnv(env); ok {
259259
interval, err := strconv.ParseUint(v, 10, 64)
260260
if err != nil {
261-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
261+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
262262
env, env, DefaultCPUInterval)
263263
return DefaultCPUInterval
264264
}
@@ -273,7 +273,7 @@ func (r *Reconciler) getCPUCoeff(containerName string) uint64 {
273273
if v, ok := os.LookupEnv(env); ok {
274274
coeff, err := strconv.ParseUint(v, 10, 64)
275275
if err != nil {
276-
r.L.Printf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
276+
log.Error().Msgf("error cannot parse environment variable: %s. Set %s to default value: %ds.",
277277
env, env, DefaultCPUCoeff)
278278
return DefaultCPUCoeff
279279
}

0 commit comments

Comments
 (0)