Skip to content
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

Move logger initialization before k8s client creation #264

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

ykulazhenkov
Copy link
Collaborator

ctrl.Log var contains noop logger until logger instance is
explicitly set with ctrl.SetLogger function

If error happen during k8s client creation it will be not logged
because ctrl.SetLogger is called after.

Move logger initialization step before k8s client
creation to be able to log client initialization errors.

Log messages when kubecofig unavailable
Before patch:

go run main.go                                                                                
exit status 1  

After patch:

go run main.go 
2022-03-09T18:40:27.941+0300    ERROR   controller-runtime.client.config        unable to get kubeconfig        {"error": "invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable", "errorCauses": [{"error": "no configuration has been provided, try setting KUBERNETES_MASTER environment variable"}]}
github.com/go-logr/zapr.(*zapLogger).Error
        /home/user/go/code/sriov-network-operator/vendor/github.com/go-logr/zapr/zapr.go:132
sigs.k8s.io/controller-runtime/pkg/log.(*DelegatingLogger).Error
        /home/user/go/code/sriov-network-operator/vendor/sigs.k8s.io/controller-runtime/pkg/log/deleg.go:144
sigs.k8s.io/controller-runtime/pkg/client/config.GetConfigOrDie
        /home/user/go/code/sriov-network-operator/vendor/sigs.k8s.io/controller-runtime/pkg/client/config/config.go:154
main.main
        /home/user/go/code/sriov-network-operator/main.go:83
runtime.main
        /usr/local/go/src/runtime/proc.go:255
exit status 1

ctrl.Log var contains noop logger until logger instance is
explicitly set with ctrl.SetLogger function

If error happen during k8s client creation it will be not logged
because ctrl.SetLogger is called after.

Move logger initialization step before k8s client
creation to be able to log client initialization errors.

Signed-off-by: Yury Kulazhenkov <[email protected]>
@github-actions
Copy link

github-actions bot commented Mar 9, 2022

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

Copy link
Collaborator

@e0ne e0ne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adrianchiris
Copy link
Collaborator

merging per 2 approvals

@adrianchiris adrianchiris merged commit 28d7a35 into k8snetworkplumbingwg:master Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants