-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[YUNIKORN-2651]Update the unchecked error for make lint warnings #850
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SophieTech88 thanks for this patch!
@@ -58,7 +59,10 @@ func NewNamespaceCache(namespaces informersv1.NamespaceInformer) *NamespaceCache | |||
nameSpaces: make(map[string]nsFlags), | |||
} | |||
if namespaces != nil { | |||
namespaces.Informer().AddEventHandler(&namespaceUpdateHandler{cache: nsc}) | |||
_, err := namespaces.Informer().AddEventHandler(&namespaceUpdateHandler{cache: nsc}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto. I don't think admission controller should start with those failures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Good insight. Updated in the new commit.
pkg/admission/conf/am_conf.go
Outdated
_, err := configMaps.Informer().AddEventHandler(&configMapUpdateHandler{conf: acc}) | ||
if err != nil { | ||
log.Log(log.AdmissionConf).Fatal("Failed to create Register handler", zap.Error(err)) | ||
os.Exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can return error instead of breaking program here, since the caller may want to do something cleanup before leaving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to return error for NewNamespaceCache and RegisterHandler functions back to main(), and it will stop the process. Check the new commit.
Another question: what about the cleanup here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fatal()
itself calls os.Exit()
, so just a simple return
does not change anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question: what about the cleanup here?
It seems to me propagating the error to callers allow them to do more actions. For example, log with more details or sent event or release resources. At any rate, exiting program in the middle of call chain is anti-pattern to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good insight. Many thanks. Allow NewNamespaceCache, RegisterHandlers functions to pass error back, and deal with the error in main(). The code is updated.
AddEventHandlerWithResyncPeriod(handler, resyncPeriod) | ||
} | ||
|
||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we fail to add handler, the initialization should be viewed as "failure"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Many thanks.
pkg/client/apifactory.go
Outdated
@@ -166,34 +167,42 @@ func (s *APIFactory) AddEventHandler(handlers *ResourceEventHandlers) { | |||
} | |||
|
|||
log.Log(log.ShimClient).Info("registering event handler", zap.Stringer("type", handlers.Type)) | |||
s.addEventHandlers(handlers.Type, h, 0) | |||
if err := s.addEventHandlers(handlers.Type, h, 0); err != nil { | |||
log.Log(log.AdmissionConf).Fatal("Failed to initialize event handlers", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to exit here? Or delegate to the code in main.go()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delegate to the code in main.go()?
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Appreciated. Earlier I only return the error for addEventHandlers
, but forgot to check AddEventHandler
, when there is error returned, it should not exit in the middle.
I check the AddEventHandler
, it is called by 3 functionss: RegisterHandlers, NewPriorityClassCache, NewNamespaceCache in main. When the AddEventHandler pass the error back, those 3 functions will return errors, too, and we can make the decision how to deal with the errors in main(). So it is great.
…s. Fix the typo in main().
@@ -53,7 +54,7 @@ func (t Type) String() string { | |||
|
|||
type APIProvider interface { | |||
GetAPIs() *Clients | |||
AddEventHandler(handlers *ResourceEventHandlers) | |||
AddEventHandler(handlers *ResourceEventHandlers) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an API change here. It's probably OK but this type has been there for a long time.
cc @wilfred-s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. When we change the AddEventHandler
to return error, it affects the APIProvider interface
, too. If there is any suggestion for this part, please let me know. Many thanks.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #850 +/- ##
==========================================
- Coverage 67.33% 66.95% -0.38%
==========================================
Files 70 70
Lines 7598 7635 +37
==========================================
- Hits 5116 5112 -4
- Misses 2271 2303 +32
- Partials 211 220 +9 ☔ View full report in Codecov by Sentry. |
@SophieTech88 Could you please propagate the error by yunikorn-k8shim/pkg/cache/context.go Line 114 in 58adfe9
By that change We can handle the error in the main function |
Many thanks for your suggestion. It is a good catch. The function But I see I just update the code to fix the return error in func |
priorityClasses.Informer().AddEventHandler(&priorityClassUpdateHandler{cache: pcc}) | ||
_, err := priorityClasses.Informer().AddEventHandler(&priorityClassUpdateHandler{cache: pcc}) | ||
if err != nil { | ||
log.Log(log.AdmissionConf).Error("Error adding event handler", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need it as caller has log, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Many Thanks. Update the code to delete the useless log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What is this PR for?
There are many different errors or warnings for
make lint
.This PR tries to solve the unchecked error which relates to 5 files, goconst error and unused error in
yunikorn-k8shim
repo.There are 11
errcheck
looks like below:pkg/admission/conf/am_conf.go:121:39: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandler
is not checked (errcheck)configMaps.Informer().AddEventHandler(&configMapUpdateHandler{conf: acc})
^
pkg/admission/namespace_cache.go:61:40: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandler
is not checked (errcheck)namespaces.Informer().AddEventHandler(&namespaceUpdateHandler{cache: nsc})
^
pkg/admission/priority_class_cache.go:44:45: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandler
is not checked (errcheck)priorityClasses.Informer().AddEventHandler(&priorityClassUpdateHandler{cache: pcc})
^
test/e2e/framework/helpers/k8s/k8s_utils.go:719:46: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandler
is not checked (errcheck)configMapInformer.Informer().AddEventHandler(eventHandler)
^
pkg/client/apifactory.go:177:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:180:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:183:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:186:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:189:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:192:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
pkg/client/apifactory.go:195:35: Error return value of
(k8s.io/client-go/tools/cache.SharedInformer).AddEventHandlerWithResyncPeriod
is not checked (errcheck)AddEventHandlerWithResyncPeriod(handler, resyncPeriod)
^
There are 4
goconst
errors as below:pkg/common/si_helper_test.go:71:13: string
pod-resource-test-00001
has 3 occurrences, make it a constant (goconst)podName := "pod-resource-test-00001"
^
pkg/common/si_helper_test.go:72:15: string
important
has 3 occurrences, make it a constant (goconst)namespace := "important"
^
pkg/cache/application_test.go:562:13: string
task02
has 3 occurrences, make it a constant (goconst)taskID2 := "task02"
^
pkg/shim/scheduler_test.go:42:16: string `
partitions:
queues:
submitacl: "*"
queues:
resources:
guaranteed:
memory: 100000000
vcore: 10
max:
memory: 150000000
vcore: 20
has 3 occurrences, make it a constant (goconst) configData :=
^
There is 1
unused
error as below :pkg/shim/scheduler_mock_test.go:165:26: func
(*MockScheduler).removeApplication
is unused (unused)func (fc *MockScheduler) removeApplication(appId string) error {
^
Actions:
unchecked
errors in 5 files.RegisterHandler
andNewNamespaceCache
, this error should be viewed as fatal, pass the error message back to main(), and we should propagate it to stop k8shime. At same time, update the unit test forNewNamespaceCache
func.min-occurrences = 5
in .golangci.yml file to increase the thresholdfunc (fc *MockScheduler) removeApplication(appId string) error{}
What type of PR is it?
Todos
What is the Jira issue?
https://issues.apache.org/jira/browse/YUNIKORN-2651
How should this be tested?
It should pass all CI test.
make test
passed locally.Screenshots (if appropriate)
Questions: