-
Notifications
You must be signed in to change notification settings - Fork 39
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
Tooling updates + add Proxy support to httpclient.DefaultTransport #414
base: main
Are you sure you want to change the base?
Conversation
6e6567e
to
8d1a4b3
Compare
go.mod
Outdated
@@ -1,6 +1,6 @@ | |||
module github.com/bmc-toolbox/bmclib/v2 | |||
|
|||
go 1.21 | |||
go 1.23 |
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.
I recommend that we don't bump this version to 1.23
. This version doesn't correspond to Go's supported versions but "The minimum version of Go required to compile packages in this module." - ref.
The current bmclib policy is, "As a library we will only bump the version of Go in the go.mod file when there are required dependencies in bmclib that necessitate a version bump." - ref
From this PR, the only thing I can tell that needs the version to increment is for x := range 5
. I believe this was introduced in Go 1.22. So the conversation should be around whether to go from 1.21
to 1.22
and not 1.21
to 1.23
. I am onboard with going to 1.22
but not 1.23
.
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.
Right, but no one should be running go <1.23 anyway. I kind of see it as a chicken/egg situation. When 1.25 comes out I'd like to bump this to 1.24 and then make use of go tool
support to run various tools (like golangci-lint) via native go pinning.
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.
Sorry, that's not the policy. As a library, we shouldn't dictate the version clients use. Per the policy, go tool
support isn't a reason to update this. There are many examples of older Go versions in large active Go module repos in the wild. https://github.com/spf13/cobra, for example.
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.
oh til! well will back this out then
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.
there's also the copyloopvar
change that came in from 1.22 that affects this repo (albeit just one line). I'll back this out and have a separate PR for 1.22 + enabling those linters.
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.
Alright dropped back down to 1.21 and undid changes
providers/asrockrack/helpers.go
Outdated
@@ -602,7 +600,7 @@ func (a *ASRockRack) queryHTTPS(ctx context.Context, endpoint, method string, pa | |||
} | |||
|
|||
// add headers | |||
req.Header.Add("X-CSRFTOKEN", a.loginSession.CSRFToken) | |||
req.Header.Add("X-Csrftoken", a.loginSession.CSRFToken) |
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.
What's motivating this change? I believe there was a code comment elsewhere that referenced old firmware needing some specific casing. Regardless, the HTTP spec says that headers are case-insensitive. ref
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.
this was an autofix from one of the linters, can do the magic comment to have it ignore this but I'd like some clarity before going that route.
I'm not seeing anything in the code base about old firmware expecting specific case of headers, are you thinking about supermicro with form-data fields https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/floppy.go#L91-L96?
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.
I'd recommend the headers are left as is, unless a change is required in practice
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.
will do
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.
should be back to original format
internal/redfishwrapper/task.go
Outdated
@@ -76,13 +74,13 @@ func (c *Client) ConvertTaskState(state string) constants.TaskState { | |||
switch strings.ToLower(state) { | |||
case "starting", "downloading", "downloaded", "scheduling": | |||
return constants.Initializing | |||
case "running", "stopping", "cancelling": | |||
case "running", "stopping", "canceling": |
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.
I don't think these should change as they are States that correspond to the gofish library. https://github.com/stmcginnis/gofish/blob/4b51c15f0a3df649821f9fc395a82483ff60bb2a/redfish/task.go#L16-L55
It is spelled Cancelling
in that library. We should probably be using the const from that package anyway.
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.
uggh good catch will back out. We are using the consts from that package already. The problem is we are converting that package's types <-> string when it should be done by that package itself (via stringer imo).
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.
should be back to original (plus //nolint:
directive)
client.go
Outdated
client := *old | ||
transport, ok := client.Transport.(*http.Transport) | ||
if !ok { | ||
panic("old client's transport is not expected type") |
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.
hmm...I'm concerned about this panic. I know we weren't even checking the type assert before, and it could have implicitly caused a panic already, but could we introduce a more graceful way to handle the bad type assert? Maybe a return error or something similar?
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.
I don't think its worth it, changing to an error return is going to have wide effect when done for registerASRRProvider
and probably others (bubbling the error up). Its never really going to be a problem either since we aren't really using different implementations. If it ever changes then it'll be caught early at startup instead of later at runtime.
Not a whole lot of benefit imo.
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.
This does seem like an exceptional case, can the panic message include a clearer message, along the lines of "expected a http client of the http.Transport type, got $blah instead"?
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.
I've updated the panic message
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.
Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited
client.go
Outdated
client := *old | ||
transport, ok := client.Transport.(*http.Transport) | ||
if !ok { | ||
panic("old client's transport is not expected type") |
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.
This does seem like an exceptional case, can the panic message include a clearer message, along the lines of "expected a http client of the http.Transport type, got $blah instead"?
Automated using the following command: ``` git ls-files '*.go' | xargs -I% sh -c ' sed "/^import (/,/^)/ { /^\s*$/ d }" % >%.tmp && goimports -w %.tmp && (if cmp -s % %.tmp; then rm %.tmp; else mv %.tmp %; fi)' ```
I'm going to drop new features from this PR and just do the format/lint fixes, aka the cleaning part |
Going to go from disable-all,enable-some to enable-all,disable-some so we are going to want to avoid golangci-lint changing out from under us.
Drop enabling govets shadow because it's too annoying
I've trimmed things down and also split the commits a little bit so that they are easier to review. I split out what was previously "automatic fixes + manual fixes" into multiple ones. The first iteration was all together so that each commit would still pass linting so it was quite large. Now a couple of intermediate commits won't pass but makes for smaller diffs. |
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.
This looks fine 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.
Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited
I don't think multiple commits was what @joelrebel was driving at here. Limiting scope would be, for example, creating a PR just for the linting changes, one for the small pedantic differences you prefer, and another for just the proxy support.
@@ -93,7 +94,7 @@ func Test_setComponentUpdateMisc(t *testing.T) { | |||
return | |||
} | |||
|
|||
assert.Nil(t, err) | |||
assert.NoError(t, 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.
The use of require.NoError
and assert.NoError
seems arbitrary. When to use which is not clear. Is this something that golangci-lint
catches? If not, I recommend either creating a doc for when one should be used over the other, or just stick to one.
case constants.PowerCycleHost, constants.Unknown: | ||
fallthrough |
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.
For what is this optimizing? Why is this needed if it's just going to fallthrough to the default? Won't the default case be called regardless of whether this case exists or not?
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.
Oh, is this to satisfy a linting complaint? If so, I recommend a code comment to improve understandability and the required cognitive load.
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.
constants.PowerCycleHost
and constants.Unknown
should not be part of the switch case since they are not Redfish task states,
could we have this case removed?
What does this PR implement/change/remove?
Spring cleaning changes are annoyingly large but mostly mechanical, either via
gofumpt
orgolangci-lint run --fix
, there were some manual fixes I made to avoid disabling linters that complained about a handful of things.I also added Proxy config to the DefaultTransport just like the DefaultTransport in the http package does. This setup will make it so http requests will go via a proxy when HTTPS_PROXY env var exists. This way we can debug redfish over https using mitmproxy or similar setup.
I added the binaries to .gitignore because they should have been there from the beginning.
Description for changelog/release notes