Merge pull request #93529 from latteczy/master

reduce the number of type conversions and correct variable name

Kubernetes-commit: 01ca6fb5c951df5154d1496c2f402c44a5809d33
This commit is contained in:
Kubernetes Publisher 2020-08-28 06:37:31 -07:00
commit e4aeb38be1
5 changed files with 12 additions and 10 deletions

2
Godeps/Godeps.json generated
View File

@ -444,7 +444,7 @@
}, },
{ {
"ImportPath": "k8s.io/apimachinery", "ImportPath": "k8s.io/apimachinery",
"Rev": "598f8782ef6f" "Rev": "c43a9f02c641"
}, },
{ {
"ImportPath": "k8s.io/gengo", "ImportPath": "k8s.io/gengo",

4
go.mod
View File

@ -27,7 +27,7 @@ require (
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 golang.org/x/time v0.0.0-20191024005414-555d28b269f0
k8s.io/api v0.0.0-20200828051551-f7be94ed4426 k8s.io/api v0.0.0-20200828051551-f7be94ed4426
k8s.io/apimachinery v0.0.0-20200828051414-598f8782ef6f k8s.io/apimachinery v0.0.0-20200828171410-c43a9f02c641
k8s.io/klog/v2 v2.2.0 k8s.io/klog/v2 v2.2.0
k8s.io/utils v0.0.0-20200729134348-d5654de09c73 k8s.io/utils v0.0.0-20200729134348-d5654de09c73
sigs.k8s.io/yaml v1.2.0 sigs.k8s.io/yaml v1.2.0
@ -35,5 +35,5 @@ require (
replace ( replace (
k8s.io/api => k8s.io/api v0.0.0-20200828051551-f7be94ed4426 k8s.io/api => k8s.io/api v0.0.0-20200828051551-f7be94ed4426
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200828051414-598f8782ef6f k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200828171410-c43a9f02c641
) )

2
go.sum
View File

@ -334,7 +334,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
k8s.io/api v0.0.0-20200828051551-f7be94ed4426/go.mod h1:Eof5ZBY8Afte3+74dUzF8SySMRjc2uj3osb9bq8B3HI= k8s.io/api v0.0.0-20200828051551-f7be94ed4426/go.mod h1:Eof5ZBY8Afte3+74dUzF8SySMRjc2uj3osb9bq8B3HI=
k8s.io/apimachinery v0.0.0-20200828051414-598f8782ef6f/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA= k8s.io/apimachinery v0.0.0-20200828171410-c43a9f02c641/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0 h1:XRvcwJozkgZ1UQJmfMGpvRthQHOvihEhYtDfAaxMz/A= k8s.io/klog/v2 v2.2.0 h1:XRvcwJozkgZ1UQJmfMGpvRthQHOvihEhYtDfAaxMz/A=

View File

@ -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

View File

@ -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