7
7
"strconv"
8
8
"strings"
9
9
10
+ "github.com/rs/zerolog/log"
10
11
"github.com/unagex/kondense/pkg/utils"
11
12
corev1 "k8s.io/api/core/v1"
12
13
"k8s.io/apimachinery/pkg/api/resource"
@@ -59,13 +60,13 @@ func (r *Reconciler) getMemoryMin(containerName string) uint64 {
59
60
if v , ok := os .LookupEnv (env ); ok {
60
61
minQ , err := resource .ParseQuantity (v )
61
62
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." ,
63
64
env , env , DefaultMemMin )
64
65
return DefaultMemMin
65
66
}
66
67
min := minQ .Value ()
67
68
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" ,
69
70
env , env , DefaultMemMin )
70
71
return DefaultMemMin
71
72
}
@@ -80,19 +81,18 @@ func (r *Reconciler) getMemoryMax(containerName string) uint64 {
80
81
if v , ok := os .LookupEnv (env ); ok {
81
82
maxQ , err := resource .ParseQuantity (v )
82
83
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." ,
84
85
env , env , DefaultMemMax )
85
86
return DefaultMemMax
86
87
}
87
88
max := maxQ .Value ()
88
89
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" ,
90
91
env , env , DefaultMemMax )
91
92
return DefaultMemMax
92
93
}
93
94
return uint64 (max )
94
95
}
95
-
96
96
return DefaultMemMax
97
97
}
98
98
@@ -101,7 +101,7 @@ func (r *Reconciler) getMemoryInterval(containerName string) uint64 {
101
101
if v , ok := os .LookupEnv (env ); ok {
102
102
interval , err := strconv .ParseUint (v , 10 , 64 )
103
103
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." ,
105
105
env , env , DefaultMemInterval )
106
106
return DefaultMemInterval
107
107
}
@@ -116,12 +116,12 @@ func (r *Reconciler) getMemoryTargetPressure(containerName string) uint64 {
116
116
if v , ok := os .LookupEnv (env ); ok {
117
117
targetPressure , err := strconv .ParseUint (v , 10 , 64 )
118
118
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." ,
120
120
env , env , DefaultMemTargetPressure )
121
121
return DefaultMemTargetPressure
122
122
}
123
123
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." ,
125
125
env , env , DefaultMemTargetPressure )
126
126
return DefaultMemTargetPressure
127
127
}
@@ -136,12 +136,12 @@ func (r *Reconciler) getMemoryMaxInc(containerName string) float64 {
136
136
if v , ok := os .LookupEnv (env ); ok {
137
137
maxInc , err := strconv .ParseFloat (v , 64 )
138
138
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." ,
140
140
env , env , DefaultMemMaxInc )
141
141
return DefaultMemMaxInc
142
142
}
143
143
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." ,
145
145
env , env , DefaultMemMaxInc )
146
146
return DefaultMemMaxInc
147
147
}
@@ -156,12 +156,12 @@ func (r *Reconciler) getMemoryMaxDec(containerName string) float64 {
156
156
if v , ok := os .LookupEnv (env ); ok {
157
157
maxDec , err := strconv .ParseFloat (v , 64 )
158
158
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." ,
160
160
env , env , DefaultMemMaxDec )
161
161
return DefaultMemMaxDec
162
162
}
163
163
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." ,
165
165
env , env , DefaultMemMaxDec )
166
166
return DefaultMemMaxDec
167
167
}
@@ -176,12 +176,12 @@ func (r *Reconciler) getMemoryCoeffInc(containerName string) float64 {
176
176
if v , ok := os .LookupEnv (env ); ok {
177
177
coeffInc , err := strconv .ParseFloat (v , 64 )
178
178
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." ,
180
180
env , env , DefaultMemCoeffInc )
181
181
return DefaultMemCoeffInc
182
182
}
183
183
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." ,
185
185
env , env , DefaultMemCoeffInc )
186
186
return DefaultMemCoeffInc
187
187
}
@@ -196,12 +196,12 @@ func (r *Reconciler) getMemoryCoeffDec(containerName string) float64 {
196
196
if v , ok := os .LookupEnv (env ); ok {
197
197
coeffDec , err := strconv .ParseFloat (v , 64 )
198
198
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." ,
200
200
env , env , DefaultMemCoeffDec )
201
201
return DefaultMemCoeffDec
202
202
}
203
203
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." ,
205
205
env , env , DefaultMemCoeffDec )
206
206
return DefaultMemCoeffDec
207
207
}
@@ -216,13 +216,13 @@ func (r *Reconciler) getCPUMin(containerName string) uint64 {
216
216
if v , ok := os .LookupEnv (env ); ok {
217
217
minQ , err := resource .ParseQuantity (v )
218
218
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)." ,
220
220
env , env , DefaultCPUMin )
221
221
return DefaultCPUMin
222
222
}
223
223
min := minQ .MilliValue ()
224
224
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)" ,
226
226
env , env , DefaultCPUMin )
227
227
return DefaultCPUMin
228
228
}
@@ -237,13 +237,13 @@ func (r *Reconciler) getCPUMax(containerName string) uint64 {
237
237
if v , ok := os .LookupEnv (env ); ok {
238
238
maxQ , err := resource .ParseQuantity (v )
239
239
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)." ,
241
241
env , env , DefaultCPUMax )
242
242
return DefaultCPUMax
243
243
}
244
244
max := maxQ .MilliValue ()
245
245
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)" ,
247
247
env , env , DefaultCPUMax )
248
248
return DefaultCPUMax
249
249
}
@@ -258,7 +258,7 @@ func (r *Reconciler) getCPUInterval(containerName string) uint64 {
258
258
if v , ok := os .LookupEnv (env ); ok {
259
259
interval , err := strconv .ParseUint (v , 10 , 64 )
260
260
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." ,
262
262
env , env , DefaultCPUInterval )
263
263
return DefaultCPUInterval
264
264
}
@@ -273,7 +273,7 @@ func (r *Reconciler) getCPUCoeff(containerName string) uint64 {
273
273
if v , ok := os .LookupEnv (env ); ok {
274
274
coeff , err := strconv .ParseUint (v , 10 , 64 )
275
275
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." ,
277
277
env , env , DefaultCPUCoeff )
278
278
return DefaultCPUCoeff
279
279
}
0 commit comments