mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #93529 from latteczy/master
reduce the number of type conversions and correct variable name
This commit is contained in:
commit
01ca6fb5c9
@ -52,13 +52,14 @@ func (cml *ConfigMapLock) Get(ctx context.Context) (*LeaderElectionRecord, []byt
|
|||||||
if cml.cm.Annotations == nil {
|
if cml.cm.Annotations == nil {
|
||||||
cml.cm.Annotations = make(map[string]string)
|
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 found {
|
||||||
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
|
if err := json.Unmarshal(recordBytes, &record); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &record, []byte(recordBytes), nil
|
return &record, recordBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create attempts to create a LeaderElectionRecord annotation
|
// Create attempts to create a LeaderElectionRecord annotation
|
||||||
|
@ -47,13 +47,14 @@ func (el *EndpointsLock) Get(ctx context.Context) (*LeaderElectionRecord, []byte
|
|||||||
if el.e.Annotations == nil {
|
if el.e.Annotations == nil {
|
||||||
el.e.Annotations = make(map[string]string)
|
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 found {
|
||||||
if err := json.Unmarshal([]byte(recordBytes), &record); err != nil {
|
if err := json.Unmarshal(recordBytes, &record); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &record, []byte(recordBytes), nil
|
return &record, recordBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create attempts to create a LeaderElectionRecord annotation
|
// Create attempts to create a LeaderElectionRecord annotation
|
||||||
|
Loading…
Reference in New Issue
Block a user