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

Refactor/klogs #8

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

Refactor/klogs #8

wants to merge 34 commits into from

Conversation

jskazinski
Copy link
Member

@jskazinski jskazinski commented Jun 10, 2022

Related to https://kubernetes.io/blog/2022/05/25/contextual-logging/ and https://github.com/kubernetes/enhancements/blob/master/keps/sig-instrumentation/1602-structured-logging/README.md

The main reason for this change is to allow drivers and libraries to use the same klog logging package, and to switch to using structured logging throughout the library. From my understanding, klog is the most common Kubernetes logger and this allows consistent log output for CSI drivers and the iSCSI library.

Signed-off-by: Joe Skazinski [email protected]

What type of PR is this?
/kind feature

What this PR does / why we need it:

Converts the library to using "k8s.io/klog/v2" and specifically structured logging.
Addresses one issue allowing the code to work with older and newer versions of lsblk.

Which issue(s) this PR fixes:

Special notes for your reviewer:
This change does not disable logging by default, but does allow the user to set their own io.Writer. This is a change from the prior default behavior. This change uses structured logging and captures the same information with no loss, but with the possibility of additional information being provided where it proves useful in the particular context.

Does this PR introduce a user-facing change?:
Yes, the structure of the log information is presented in the klog format versus the prior formatting. Each log entry contains the same relevant information, such as timestamp and level (Info vs Error), and library values, but the the text outline is changed and will affect any scripts scraping the logs.

Refactored to use klog/v2 and structured logging.

  • Switched to using go 1.18
  • using k8s.io/klog/v2 klog replacing log.Logger
  • init() prints a version message but does not disable logging
  • EnableDebugLogging() allows a caller to set their own io.Writer
  • debug.Printf calls are replaced with klog.InfoS and klog.ErrorS (according to info versus error)
  • getMultipathDevice() was altered to work with older versions of lsblk output and newer versions. See lsblk inconsistent behavior kubernetes-csi/csi-lib-iscsi#34

View rendered README.md

humblec and others added 30 commits May 19, 2021 15:56
Build issue#

vendor/github.com/kubernetes-csi/csi-lib-iscsi/iscsi/iscsi.go:379:7:
no new variables on left side of :=
Building iscsiplugin for GOOS= GOARCH= failed, see error(s) above.
make: *** [release-tools/build.make:81: build-iscsiplugin] Error 1

Signed-off-by: Humble Chirammal <[email protected]>
example/main.go:36:3: unknown field 'TargetIqn' in struct literal of type iscsi.Connector
example/main.go:38:3: unknown field 'TargetPortals' in struct literal of type iscsi.Connector
example/main.go:74:20: c.TargetIqn undefined (type iscsi.Connector has no field or method TargetIqn)
example/main.go:74:33: c.TargetPortals undefined (type iscsi.Connector has no field or method TargetPortals)
make: *** [Makefile:11: build] Error 2

Signed-off-by: Humble Chirammal <[email protected]>
Signed-off-by: Humble Chirammal <[email protected]>
 Fix unknown struct field reference and variable assignment in iscsi library
- fix example/main.go
- add go.mod to simplify local development
- always control devices through the Device class
- add checks on devices
- store all used devices instead of mounted one only
- filter device by transport to keep iSCSI devices only
- refactor connector's functions to use it as a receiver
- refactor waitForPathToExists
- refactor Connect to make it smaller and more readable
- include error code
- remove unused properties
- retrieve specific columns including device size
- always output as JSON
Signed-off-by: Humble Chirammal <[email protected]>
This commit use error wrapping checkfunctions in error comparison
Handle error conditions in iscsi admin functions.

Also, remove path,pathgroup structs which are unused

Signed-off-by: Humble Chirammal <[email protected]>
Do error checking and error wrapping in the connector functions.
@jskazinski jskazinski self-assigned this Jun 10, 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.

5 participants