Merge pull request #93529 from latteczy/master

reduce the number of type conversions and correct variable name
This commit is contained in:
Kubernetes Prow Robot 2020-08-28 06:37:31 -07:00 committed by GitHub
commit 01ca6fb5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -52,13 +52,14 @@ func (cml *ConfigMapLock) Get(ctx context.Context) (*LeaderElectionRecord, []byt
if cml.cm.Annotations == nil {
cml.cm.Annotations = make(map[string]string)
}
recordBytes, found := cml.cm.Annotations[LeaderElectionRecordAnnotationKey]
recordStr, found := cml.cm.Annotations[LeaderElectionRecordAnnotationKey]
recordBytes := []byte(recordStr)
if found {
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
if err := json.Unmarshal(recordBytes, &record); err != nil {
return nil, nil, err
}
}
return &record, []byte(recordBytes), nil
return &record, recordBytes, nil
}
// Create attempts to create a LeaderElectionRecord annotation

View File

@ -47,13 +47,14 @@ func (el *EndpointsLock) Get(ctx context.Context) (*LeaderElectionRecord, []byte
if el.e.Annotations == nil {
el.e.Annotations = make(map[string]string)
}
recordBytes, found := el.e.Annotations[LeaderElectionRecordAnnotationKey]
recordStr, found := el.e.Annotations[LeaderElectionRecordAnnotationKey]
recordBytes := []byte(recordStr)
if found {
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
if err := json.Unmarshal(recordBytes, &record); err != nil {
return nil, nil, err
}
}
return &record, []byte(recordBytes), nil
return &record, recordBytes, nil
}
// Create attempts to create a LeaderElectionRecord annotation