reduce type conversion and correct variable name

Kubernetes-commit: 13468442bfbdf69a6e6690497fce427317cff790
This commit is contained in:
caozhiyuan 2020-07-29 19:18:05 +08:00 committed by Kubernetes Publisher
parent 67e1ce8f65
commit fa1e013ed0
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