Skip to content

Commit d3ce152

Browse files
authored
Merge pull request #897 from luomingmeng/dev/fix-cnr-reporter-name
fix(cnrreporter): rename newCNR references to cnr for consistency
2 parents 2479e2d + 86daacb commit d3ce152

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

pkg/agent/resourcemanager/reporter/cnr/cnrreporter.go

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import (
4747
)
4848

4949
const (
50-
cnrReporterName = "newCNR-reporter"
50+
cnrReporterName = "cnr-reporter"
5151

52-
// cnrUpdateMaxRetryTimes update newCNR retry time.
52+
// cnrUpdateMaxRetryTimes update cnr retry time.
5353
cnrUpdateMaxRetryTimes = 3
5454
)
5555

@@ -64,7 +64,7 @@ const (
6464
metricsNameUpdateCNRStatusCost = "update_cnr_status_cost"
6565
)
6666

67-
// cnrReporterImpl is to report newCNR content to remote
67+
// cnrReporterImpl is to report cnr content to remote
6868
type cnrReporterImpl struct {
6969
cnrName string
7070

@@ -86,7 +86,7 @@ type cnrReporterImpl struct {
8686
refreshLatestCNRPeriod time.Duration
8787
}
8888

89-
// NewCNRReporter create a newCNR reporter
89+
// NewCNRReporter create a cnr reporter
9090
func NewCNRReporter(genericClient *client.GenericClientSet, metaServer *metaserver.MetaServer,
9191
emitter metrics.MetricEmitter, conf *config.Configuration,
9292
) (reporter.Reporter, error) {
@@ -106,7 +106,7 @@ func NewCNRReporter(genericClient *client.GenericClientSet, metaServer *metaserv
106106
return c, nil
107107
}
108108

109-
// Run start newCNR reporter
109+
// Run start cnr reporter
110110
func (c *cnrReporterImpl) Run(ctx context.Context) {
111111
go wait.JitterUntilWithContext(ctx, c.refreshLatestCNR, c.refreshLatestCNRPeriod, refreshLatestCNRJitterFactor, true)
112112
<-ctx.Done()
@@ -123,20 +123,20 @@ func (c *cnrReporterImpl) GetCNR(ctx context.Context) (*nodev1alpha1.CustomNodeR
123123
return c.client.NodeV1alpha1().CustomNodeResources().Get(ctx, c.cnrName, metav1.GetOptions{ResourceVersion: "0"})
124124
}
125125

126-
// Update is to update remote newCNR according to reported fields
126+
// Update is to update remote cnr according to reported fields
127127
func (c *cnrReporterImpl) Update(ctx context.Context, fields []*v1alpha1.ReportField) error {
128128
beginWithLock := time.Now()
129129
c.mux.Lock()
130130
beginWithoutLock := time.Now()
131131

132132
defer func() {
133133
costs := time.Since(beginWithoutLock)
134-
klog.InfoS("finished update newCNR without lock", "costs", costs)
134+
klog.InfoS("finished update cnr without lock", "costs", costs)
135135

136136
c.mux.Unlock()
137137

138138
costs = time.Since(beginWithLock)
139-
klog.InfoS("finished update newCNR with lock", "costs", costs)
139+
klog.InfoS("finished update cnr with lock", "costs", costs)
140140
_ = c.emitter.StoreInt64(metricsNameUpdateCNRCost, costs.Microseconds(), metrics.MetricTypeNameRaw)
141141
}()
142142

@@ -148,16 +148,16 @@ func (c *cnrReporterImpl) Update(ctx context.Context, fields []*v1alpha1.ReportF
148148

149149
for i := 0; i < cnrUpdateMaxRetryTimes; i++ {
150150
if err := c.tryUpdateCNR(ctx, fields, i); err != nil {
151-
klog.Errorf("error updating newCNR, will retry: %v", err)
151+
klog.Errorf("error updating cnr, will retry: %v", err)
152152
} else {
153153
return nil
154154
}
155155
}
156156

157-
return fmt.Errorf("attempt to update newCNR failed with total retries of %d", cnrUpdateMaxRetryTimes)
157+
return fmt.Errorf("attempt to update cnr failed with total retries of %d", cnrUpdateMaxRetryTimes)
158158
}
159159

160-
// RegisterNotifier register a notifier to newCNR reporter
160+
// RegisterNotifier register a notifier to cnr reporter
161161
func (c *cnrReporterImpl) RegisterNotifier(name string, notifier metaservercnr.CNRNotifier) error {
162162
c.mux.Lock()
163163
defer c.mux.Unlock()
@@ -170,7 +170,7 @@ func (c *cnrReporterImpl) RegisterNotifier(name string, notifier metaservercnr.C
170170
return nil
171171
}
172172

173-
// UnregisterNotifier unregister a notifier from newCNR reporter
173+
// UnregisterNotifier unregister a notifier from cnr reporter
174174
func (c *cnrReporterImpl) UnregisterNotifier(name string) error {
175175
c.mux.Lock()
176176
defer c.mux.Unlock()
@@ -183,35 +183,35 @@ func (c *cnrReporterImpl) UnregisterNotifier(name string) error {
183183
return nil
184184
}
185185

186-
// refreshLatestCNR get latest newCNR from remote, because newCNR in cache may not have been updated.
186+
// refreshLatestCNR get latest cnr from remote, because cnr in cache may not have been updated.
187187
func (c *cnrReporterImpl) refreshLatestCNR(ctx context.Context) {
188188
c.mux.Lock()
189189
defer c.mux.Unlock()
190190

191191
begin := time.Now()
192192
defer func() {
193193
costs := time.Since(begin)
194-
klog.Infof("finished refresh newCNR (%v)", costs)
194+
klog.Infof("finished refresh cnr (%v)", costs)
195195
_ = c.emitter.StoreInt64(metricsNameRefreshCNRCost, costs.Microseconds(), metrics.MetricTypeNameRaw)
196196
}()
197197

198198
cnr, err := c.client.NodeV1alpha1().CustomNodeResources().Get(ctx, c.cnrName, metav1.GetOptions{ResourceVersion: "0"})
199199
if err == nil {
200200
c.latestUpdatedCNR = cnr.DeepCopy()
201201
} else if !c.resetCNRIfNeeded(err) {
202-
klog.Errorf("refresh local newCNR cache failed with error: %v", err)
202+
klog.Errorf("refresh local cnr cache failed with error: %v", err)
203203
}
204204
}
205205

206-
// tryUpdateCNR update newCNR according reported fields, first update newCNR try will use cached latestUpdatedCNR,
207-
// if there are some errors such as conflict happened, it will retry by getting newCNR from api server
206+
// tryUpdateCNR update cnr according reported fields, first update cnr try will use cached latestUpdatedCNR,
207+
// if there are some errors such as conflict happened, it will retry by getting cnr from api server
208208
func (c *cnrReporterImpl) tryUpdateCNR(ctx context.Context, fields []*v1alpha1.ReportField, tryIdx int) error {
209209
var (
210210
cnr *nodev1alpha1.CustomNodeResource
211211
err error
212212
)
213213

214-
// only get newCNR from api server iff latest updated newCNR is nil or tryIdx > 0
214+
// only get cnr from api server iff latest updated cnr is nil or tryIdx > 0
215215
if c.latestUpdatedCNR == nil || tryIdx > 0 {
216216
c.countMetricsWithBaseTags("reporter_update_retry")
217217

@@ -224,12 +224,12 @@ func (c *cnrReporterImpl) tryUpdateCNR(ctx context.Context, fields []*v1alpha1.R
224224
return err
225225
}
226226

227-
// NotFound to create newCNR
227+
// NotFound to create cnr
228228
if err != nil {
229229
cnr, err = c.createCNR(ctx, fields)
230230
if err != nil {
231231
c.countMetricsWithBaseTags("reporter_update_failed")
232-
return fmt.Errorf("create newCNR failed: %s", err)
232+
return fmt.Errorf("create cnr failed: %s", err)
233233
}
234234
}
235235

@@ -239,7 +239,7 @@ func (c *cnrReporterImpl) tryUpdateCNR(ctx context.Context, fields []*v1alpha1.R
239239
}
240240

241241
if cnr == nil {
242-
return fmt.Errorf("nil %q newCNR object", c.cnrName)
242+
return fmt.Errorf("nil %q cnr object", c.cnrName)
243243
}
244244

245245
originCNR := cnr.DeepCopy()
@@ -251,7 +251,7 @@ func (c *cnrReporterImpl) tryUpdateCNR(ctx context.Context, fields []*v1alpha1.R
251251
// todo: consider whether we need to handle update error automatically
252252
// i.e. use queue to push and pop those failed items
253253

254-
// try patch spec and metadata first, because the update of newCNR will change the ResourceVersion in ObjectMeta
254+
// try patch spec and metadata first, because the update of cnr will change the ResourceVersion in ObjectMeta
255255
originCNR, err = c.tryUpdateCNRSpecAndMetadata(ctx, originCNR, cnr)
256256
if err != nil && !c.resetCNRIfNeeded(err) {
257257
return err
@@ -276,16 +276,16 @@ func (c *cnrReporterImpl) tryUpdateCNRSpecAndMetadata(ctx context.Context,
276276
)
277277

278278
if cnrSpecHasChanged(&originCNR.Spec, &currentCNR.Spec) || cnrMetadataHasChanged(&originCNR.ObjectMeta, &currentCNR.ObjectMeta) {
279-
klog.Infof("newCNR spec or metadata changed, try to patch it")
279+
klog.Infof("cnr spec or metadata changed, try to patch it")
280280

281281
begin := time.Now()
282282
defer func() {
283283
costs := time.Since(begin)
284-
klog.Infof("finished update newCNR spec and metadata (%v)", costs)
284+
klog.Infof("finished update cnr spec and metadata (%v)", costs)
285285
_ = c.emitter.StoreInt64(metricsNameUpdateCNRSpecMetadataCost, costs.Microseconds(), metrics.MetricTypeNameRaw)
286286
}()
287287

288-
// patch newCNR spec and metadata
288+
// patch cnr spec and metadata
289289
cnr, err = c.updater.PatchCNRSpecAndMetadata(ctx, c.cnrName, originCNR, currentCNR)
290290
if err != nil {
291291
c.countMetricsWithBaseTags("reporter_update",
@@ -302,12 +302,12 @@ func (c *cnrReporterImpl) tryUpdateCNRSpecAndMetadata(ctx context.Context,
302302
"status": "success",
303303
})...)
304304

305-
klog.Infof("patch newCNR spec and metadata success\n old newCNR spec: %#v, metadata: %#v,\n "+
306-
"new newCNR spec: %#v, metadata: %#v",
305+
klog.Infof("patch cnr spec and metadata success\n old cnr spec: %#v, metadata: %#v,\n "+
306+
"new cnr spec: %#v, metadata: %#v",
307307
originCNR.Spec, originCNR.ObjectMeta, cnr.Spec, cnr.ObjectMeta)
308308
c.latestUpdatedCNR = cnr.DeepCopy()
309309

310-
// notify newCNR spec and metadata update
310+
// notify cnr spec and metadata update
311311
for _, notifier := range c.notifiers {
312312
notifier.OnCNRUpdate(cnr)
313313
}
@@ -327,16 +327,16 @@ func (c *cnrReporterImpl) tryUpdateCNRStatus(ctx context.Context,
327327
)
328328

329329
if cnrStatusHasChanged(&originCNR.Status, &currentCNR.Status) {
330-
klog.Infof("newCNR status changed, try to patch it")
330+
klog.Infof("cnr status changed, try to patch it")
331331

332332
begin := time.Now()
333333
defer func() {
334334
costs := time.Since(begin)
335-
klog.Infof("finished update newCNR status (%v)", costs)
335+
klog.Infof("finished update cnr status (%v)", costs)
336336
_ = c.emitter.StoreInt64(metricsNameUpdateCNRStatusCost, costs.Microseconds(), metrics.MetricTypeNameRaw)
337337
}()
338338

339-
// patch newCNR status
339+
// patch cnr status
340340
cnr, err = c.updater.PatchCNRStatus(ctx, c.cnrName, originCNR, currentCNR)
341341
if err != nil {
342342
c.countMetricsWithBaseTags("reporter_update",
@@ -354,12 +354,12 @@ func (c *cnrReporterImpl) tryUpdateCNRStatus(ctx context.Context,
354354
})...)
355355

356356
if klog.V(6).Enabled() {
357-
klog.Infof("patch newCNR status success old status: %#v,\n new status: %#v", originCNR.Status, cnr.Status)
357+
klog.Infof("patch cnr status success old status: %#v,\n new status: %#v", originCNR.Status, cnr.Status)
358358
}
359359

360360
c.latestUpdatedCNR = cnr.DeepCopy()
361361

362-
// notify newCNR status update
362+
// notify cnr status update
363363
for _, notifier := range c.notifiers {
364364
notifier.OnCNRStatusUpdate(cnr)
365365
}
@@ -370,13 +370,13 @@ func (c *cnrReporterImpl) tryUpdateCNRStatus(ctx context.Context,
370370
return cnr, nil
371371
}
372372

373-
// resetCNRIfNeeded reset newCNR if unmarshal type error, it will initialize
374-
// local newCNR cache to make sure the content of newCNR always is true
373+
// resetCNRIfNeeded reset cnr if unmarshal type error, it will initialize
374+
// local cnr cache to make sure the content of cnr always is true
375375
// todo if $ref is supported in CRD, we can skip this since api-server will help with validations
376376
func (c *cnrReporterImpl) resetCNRIfNeeded(err error) bool {
377377
if general.IsUnmarshalTypeError(err) {
378378
c.latestUpdatedCNR = c.defaultCNR()
379-
klog.Infof("success re-initialize local newCNR cache")
379+
klog.Infof("success re-initialize local cnr cache")
380380
return true
381381
}
382382

@@ -397,10 +397,10 @@ func (c *cnrReporterImpl) createCNR(ctx context.Context, fields []*v1alpha1.Repo
397397

398398
err := setCNR(nil, cnr, fields, c.mergeValueFunc)
399399
if err != nil {
400-
return nil, fmt.Errorf("set newCNR failed: %s", err)
400+
return nil, fmt.Errorf("set cnr failed: %s", err)
401401
}
402402

403-
klog.Infof("try to create newCNR: %#v", cnr)
403+
klog.Infof("try to create cnr: %#v", cnr)
404404

405405
cnr, err = c.client.NodeV1alpha1().CustomNodeResources().Create(ctx, cnr, metav1.CreateOptions{})
406406
if err != nil {
@@ -420,7 +420,7 @@ func setCNR(originCNR, newCNR *nodev1alpha1.CustomNodeResource, fields []*v1alph
420420
continue
421421
}
422422

423-
// initialize need report newCNR field first
423+
// initialize need report cnr field first
424424
if !initializedFields.Has(f.FieldName) {
425425
err := initializeFieldToCNR(newCNR, *f)
426426
if err != nil {
@@ -431,7 +431,7 @@ func setCNR(originCNR, newCNR *nodev1alpha1.CustomNodeResource, fields []*v1alph
431431
initializedFields.Insert(f.FieldName)
432432
}
433433

434-
// parse report field to newCNR by merge function
434+
// parse report field to cnr by merge function
435435
_, err := parseReportFieldToCNR(newCNR, *f, mergeFunc)
436436
if err != nil {
437437
errList = append(errList, err)
@@ -450,7 +450,7 @@ func setCNR(originCNR, newCNR *nodev1alpha1.CustomNodeResource, fields []*v1alph
450450
return nil
451451
}
452452

453-
// reviseCNR revises the field of newCNR by origin newCNR to make sure it is not redundant and
453+
// reviseCNR revises the field of cnr by origin cnr to make sure it is not redundant and
454454
// support merge operation
455455
func reviseCNR(originCNR, newCNR *nodev1alpha1.CustomNodeResource) error {
456456
if newCNR == nil {
@@ -478,9 +478,9 @@ func (c *cnrReporterImpl) countMetricsWithBaseTags(key string, tags ...metrics.M
478478
_ = c.emitter.StoreInt64(key, 1, metrics.MetricTypeNameCount, tags...)
479479
}
480480

481-
// initializeFieldToCNR initialize newCNR fields to nil
481+
// initializeFieldToCNR initialize cnr fields to nil
482482
func initializeFieldToCNR(cnr *nodev1alpha1.CustomNodeResource, field v1alpha1.ReportField) error {
483-
// get need report value of newCNR
483+
// get need report value of cnr
484484
originValue, err := getCNRField(cnr, field)
485485
if err != nil {
486486
return err
@@ -490,15 +490,15 @@ func initializeFieldToCNR(cnr *nodev1alpha1.CustomNodeResource, field v1alpha1.R
490490
return nil
491491
}
492492

493-
// parseReportFieldToCNR parse reportField and merge to origin newCNR by mergeFunc
493+
// parseReportFieldToCNR parse reportField and merge to origin cnr by mergeFunc
494494
func parseReportFieldToCNR(cnr *nodev1alpha1.CustomNodeResource, reportField v1alpha1.ReportField,
495495
mergeFunc func(src reflect.Value, dst reflect.Value) error,
496496
) (*nodev1alpha1.CustomNodeResource, error) {
497497
if cnr == nil {
498-
return nil, fmt.Errorf("newCNR is nil")
498+
return nil, fmt.Errorf("cnr is nil")
499499
}
500500

501-
// get need report value of newCNR
501+
// get need report value of cnr
502502
originValue, err := getCNRField(cnr, reportField)
503503
if err != nil {
504504
return nil, err
@@ -518,7 +518,7 @@ func parseReportFieldToCNR(cnr *nodev1alpha1.CustomNodeResource, reportField v1a
518518
return cnr, nil
519519
}
520520

521-
// getCNRField only support to parse first-level fields in newCNR now;
521+
// getCNRField only support to parse first-level fields in cnr now;
522522
// todo: support to parse nested fields in the future.
523523
func getCNRField(cnr *nodev1alpha1.CustomNodeResource, reportField v1alpha1.ReportField) (reflect.Value, error) {
524524
var el reflect.Value

0 commit comments

Comments
 (0)