-
Notifications
You must be signed in to change notification settings - Fork 47
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
cleanup: Fix various issues found by code inspection #1278
base: main
Are you sure you want to change the base?
Conversation
func ListMetrics() []operatormetrics.Metric { | ||
return operatormetrics.ListMetrics() | ||
} |
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.
@machadovilaca , I've found this unused function and removed it. Is this a bug, that it is not used anywhere?
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.
In usually call these functions the tooling to generate the docs, but when setting up multiple metrics, in the registry we only need to list from one. That's why the ListMetrics from metrics/ssp-operator is used but not this one
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.
So, this was not a bug, that the function was not called?
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.
No, we can remove it. On a future release of the operator-observability library, it will support different registries, and then we will improve the docs to setup and list the metrics separately.
res := GetOperatorVersion() | ||
Expect(res).To(Equal("v0.0.1"), "OPERATOR_VERSION should equal") | ||
os.Unsetenv(OperatorVersionKey) |
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 DeferCleanup that so the Env is always unset?
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.
Done.
@@ -130,7 +130,10 @@ func (app *App) Run() { | |||
|
|||
func registerReadinessProbe() { | |||
http.HandleFunc("/readyz", func(resp http.ResponseWriter, req *http.Request) { | |||
fmt.Fprintf(resp, "ok") | |||
_, err := fmt.Fprintf(resp, "ok") | |||
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.
Inline it?
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.
done
@@ -130,7 +130,10 @@ func (app *App) Run() { | |||
|
|||
func registerReadinessProbe() { | |||
http.HandleFunc("/readyz", func(resp http.ResponseWriter, req *http.Request) { | |||
fmt.Fprintf(resp, "ok") | |||
_, err := fmt.Fprintf(resp, "ok") |
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.
resp.Write([]byte("ok"))
would probably achieve the same without an additional dependency.
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 idea, done.
tests/crypto_policy_test.go
Outdated
@@ -204,7 +204,7 @@ func getCaCertificate() []byte { | |||
func tryToAccessEndpoint(pod core.Pod, serviceName string, subpath string, port uint16, tlsConfig clientTLSOptions, insecure bool) (attemptedUrl string, err error) { | |||
conn, err := portForwarder.Connect(&pod, port) | |||
Expect(err).ToNot(HaveOccurred()) | |||
defer conn.Close() | |||
defer Expect(conn.Close()).To(Succeed()) |
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 it run if another Expect fails?
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.
Yes, it will work. A panic can happen during panicking. They will just wrap around each other.
https://go.dev/play/p/Eq5sdpNkDl
tests/port-forwarding.go
Outdated
@@ -43,17 +44,19 @@ func (p *portForwarderImpl) Connect(pod *core.Pod, remotePort uint16) (net.Conn, | |||
headers.Set(core.PortForwardRequestIDHeader, strconv.Itoa(int(requestId))) | |||
errorStream, err := streamConnection.CreateStream(headers) | |||
if err != nil { | |||
streamConnection.Close() | |||
return nil, err | |||
closeErr := streamConnection.Close() |
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.
Inline?
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.
done
tests/port-forwarding.go
Outdated
|
||
headers.Set(core.StreamType, core.StreamTypeData) | ||
dataStream, err := streamConnection.CreateStream(headers) | ||
if err != nil { | ||
streamConnection.Close() | ||
return nil, err | ||
closeErr := streamConnection.Close() |
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.
Same
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.
done
tests/validator_test.go
Outdated
@@ -3,6 +3,7 @@ package tests | |||
import ( | |||
"crypto/tls" | |||
"crypto/x509" | |||
goerrors "errors" |
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.
Import "k8s.io/apimachinery/pkg/api/errors"
as k8serrors
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.
done
c3d1c4b
to
45c1ccc
Compare
In multiple PRs we have problem with the |
/retest |
1 similar comment
/retest |
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.
/approve
Thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 0xFelix The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
They were found by Goland code inspection. Signed-off-by: Andrej Krejcir <[email protected]>
Signed-off-by: Andrej Krejcir <[email protected]>
Signed-off-by: Andrej Krejcir <[email protected]>
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
/hold
@akrejcir Do you want to hold it until you get a response from @machadovilaca to your question about an unused function?
The unhandled errors were found by Goland code inspection. Signed-off-by: Andrej Krejcir <[email protected]>
45c1ccc
to
c7b19d4
Compare
|
/unhold |
/retest |
/lgtm |
@akrejcir: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What this PR does / why we need it:
Fixed:
Release note: