Conversation
pkg/util/annotation.go
Outdated
|
|
||
| func GetRegion(labels map[string]string) (string, bool) { | ||
| if _, ok := labels[v1.LabelTopologyRegion]; ok { // Label as of 1.17 | ||
| _, ok := labels[v1.LabelTopologyRegion] |
There was a problem hiding this comment.
there is no need to make such change as the original code line is a better approach to me, it create a variable in smaller scope and the memory would be release soon. and it's a common practice in golang.
if _, ok := labels[v1.LabelTopologyRegion]; ok {
There was a problem hiding this comment.
there is no need to make such change as the original code line is a better approach to me, it create a variable in smaller scope and the memory would be release soon. and it's a common practice in golang.
if _, ok := labels[v1.LabelTopologyRegion]; ok {
The original code has a little bit much if-else, which seems is not necessary, so the pr is try to reduce the unnecessary code for making the logic clearn.
Speaking of golang's idioms, on one hand I suppose happy path is the commonly used way in golang for reducing indent and embeded codes, on the other hand the memory will be eventually released after the function returned, just sooner or later, not a big deal.
5686fd6 to
fdc209f
Compare
Signed-off-by: xian-jie.shen <327411586@qq.com>
fdc209f to
76b1202
Compare
Signed-off-by: xian-jie.shen 327411586@qq.com
Pre-Checklist
Description
add ut
New Behavior (screenshots if needed)
[root@dev testing]# go test annotation_test.go annotation.go -v -cover === RUN TestGetRegion === RUN TestGetRegion/base === RUN TestGetRegion/LabelZoneRegion === RUN TestGetRegion/not_found --- PASS: TestGetRegion (0.00s) --- PASS: TestGetRegion/base (0.00s) --- PASS: TestGetRegion/LabelZoneRegion (0.00s) --- PASS: TestGetRegion/not_found (0.00s) === RUN TestGetZone === RUN TestGetZone/base === RUN TestGetZone/LabelZoneFailureDomain === RUN TestGetZone/not_found --- PASS: TestGetZone (0.00s) --- PASS: TestGetZone/base (0.00s) --- PASS: TestGetZone/LabelZoneFailureDomain (0.00s) --- PASS: TestGetZone/not_found (0.00s) === RUN TestGetInstanceType === RUN TestGetInstanceType/base === RUN TestGetInstanceType/LabelInstanceTypeStable === RUN TestGetInstanceType/not_found --- PASS: TestGetInstanceType (0.00s) --- PASS: TestGetInstanceType/base (0.00s) --- PASS: TestGetInstanceType/LabelInstanceTypeStable (0.00s) --- PASS: TestGetInstanceType/not_found (0.00s) === RUN TestGetOperatingSystem === RUN TestGetOperatingSystem/base === RUN TestGetOperatingSystem/betaLabel === RUN TestGetOperatingSystem/not_found --- PASS: TestGetOperatingSystem (0.00s) --- PASS: TestGetOperatingSystem/base (0.00s) --- PASS: TestGetOperatingSystem/betaLabel (0.00s) --- PASS: TestGetOperatingSystem/not_found (0.00s) PASS coverage: 100.0% of statements ok command-line-arguments 0.010s coverage: 100.0% of statements