Skip to content

Commit 01ca6fb

Browse files
authored
Merge pull request kubernetes#93529 from latteczy/master
reduce the number of type conversions and correct variable name
2 parents 9ff9e87 + 1346844 commit 01ca6fb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/configmaplock.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ func (cml *ConfigMapLock) Get(ctx context.Context) (*LeaderElectionRecord, []byt
5252
if cml.cm.Annotations == nil {
5353
cml.cm.Annotations = make(map[string]string)
5454
}
55-
recordBytes, found := cml.cm.Annotations[LeaderElectionRecordAnnotationKey]
55+
recordStr, found := cml.cm.Annotations[LeaderElectionRecordAnnotationKey]
56+
recordBytes := []byte(recordStr)
5657
if found {
57-
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
58+
if err := json.Unmarshal(recordBytes, &record); err != nil {
5859
return nil, nil, err
5960
}
6061
}
61-
return &record, []byte(recordBytes), nil
62+
return &record, recordBytes, nil
6263
}
6364

6465
// Create attempts to create a LeaderElectionRecord annotation

staging/src/k8s.io/client-go/tools/leaderelection/resourcelock/endpointslock.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ func (el *EndpointsLock) Get(ctx context.Context) (*LeaderElectionRecord, []byte
4747
if el.e.Annotations == nil {
4848
el.e.Annotations = make(map[string]string)
4949
}
50-
recordBytes, found := el.e.Annotations[LeaderElectionRecordAnnotationKey]
50+
recordStr, found := el.e.Annotations[LeaderElectionRecordAnnotationKey]
51+
recordBytes := []byte(recordStr)
5152
if found {
52-
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
53+
if err := json.Unmarshal(recordBytes, &record); err != nil {
5354
return nil, nil, err
5455
}
5556
}
56-
return &record, []byte(recordBytes), nil
57+
return &record, recordBytes, nil
5758
}
5859

5960
// Create attempts to create a LeaderElectionRecord annotation

0 commit comments

Comments
 (0)