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

Add Build/Test/Lint/go mod/vendor consistency workflow #328

Merged
merged 16 commits into from
Aug 3, 2021

Conversation

martinkennelly
Copy link
Member

Signed-off-by: Kennelly, Martin [email protected]

#327

@adrianchiris
Copy link
Contributor

adrianchiris commented Mar 31, 2021

With golangci, i think its better to maintain a .golangci.yaml file in the project, then golang-ci uses it when invoked.
(that way you can also invoke it on your machine before submitting PR)
example for .golangci.yaml we use in one of our projects: https://github.com/Mellanox/network-operator/blob/master/.golangci.yml

Also i think it might be better to have this as another job within the test workflow that way we consolidate tests to a single file WDYT?

It would be great if there was also a makefile target for it so its easier for developers to test it before submitting a PR
maybe by replacing the existing make lint target as it covers golint as well.

example of Makefile target:
install golangci: https://github.com/Mellanox/network-operator/blob/eb50b92f07d54f8fd2bc878ea8b1662cbce198a4/Makefile#L114
run lint: https://github.com/Mellanox/network-operator/blob/eb50b92f07d54f8fd2bc878ea8b1662cbce198a4/Makefile#L135

Invoking it locally via Makefile can be done at a later stage though.

@adrianchiris adrianchiris mentioned this pull request Mar 31, 2021
@martinkennelly
Copy link
Member Author

@adrianchiris Good point. Ill rework it to what you suggested.

@martinkennelly martinkennelly changed the title Add static analysis GA WIP: Add static analysis GA Apr 29, 2021
@martinkennelly martinkennelly force-pushed the static_ga branch 2 times, most recently from ddd2e06 to 90a1f96 Compare May 1, 2021 08:56
@martinkennelly martinkennelly changed the title WIP: Add static analysis GA Add Build/Test/Lint workflow May 1, 2021
@martinkennelly
Copy link
Member Author

Will add the makefile updates in a following PR. Thanks for the great input @adrianchiris. Combining build, test, lint it into one workflow is more ergonomic and gives you an overview on a single 'webpage'.

This was referenced May 1, 2021
@martinkennelly martinkennelly changed the title Add Build/Test/Lint workflow Add Build/Test/Lint/go mod/vendor consistency workflow Jun 17, 2021
@adrianchiris
Copy link
Contributor

@martinkennelly will you be able to add another commit to fix the issues discovered in the tests you added ?

martinkennelly and others added 4 commits July 24, 2021 17:30
Workflow added to build binary using multiple
golang versions. Also, executes unit tests and
various static analysis tools.

Golanglint-ci conf file added to repository to enable
local testing.

Signed-off-by: Kennelly, Martin <[email protected]>
Disabled golint due to currently in archive mode.
Sorted imports correctly.
Correctly grammar/format mistakes.
Modified go.(mod|sum) to add context.

Signed-off-by: Martin Kennelly <[email protected]>
Executed go mod vendor to ensure vendor dir is
consistent with go.mod.

Signed-off-by: Martin Kennelly <[email protected]>
@martinkennelly
Copy link
Member Author

@adrianchiris Force push was re-basing against master.
I've reduced 95% of the issues in the static scan outputs. Further reduction will need separate PRs and discussion. If you notice anymore low hanging fruit, let me know.

In the commit "Partial fix for static analysis errors", I needed to add "context" to the go mod file to fix an issue. I then executed go mod tidy in that same commit.

In the next commit, I then added the changes from go mod vendor to a separate commit which may aid your review of all the static scan fixes. Enjoy the review :)...

@@ -104,16 +106,16 @@ func hasDefaultRoute(pciAddr string) (bool, error) {
}

if len(ifNames) > 0 { // there's at least one interface name found
for _, ifName := range ifNames {
link, err := netlink.LinkByName(ifName)
for iIfName := range ifNames {
Copy link
Contributor

Choose a reason for hiding this comment

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

not really a fan of this, do you recall which CI check complains for the string copy here ?
i dont think these memory optimizations should be a strict requirement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Linter message:
hugeParam: X is heavy (C bytes); consider passing it by pointer (gocritic)

yeah - I did it just to silence the CI check output. Definitely agree it shouldn't be a strict requirement since this software is just a control plane component and it's dealing with objects in memory that are relatively small mem footprint (~300bytes) and are few in number.

Do you not like it because it reduces readability? I think it's fine but happy to revert if you want.

Copy link
Contributor

@adrianchiris adrianchiris Jul 27, 2021

Choose a reason for hiding this comment

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

Do you not like it because it reduces readability?

yes exactly. so essentially i prefer to ignore this check or make it less restrictive so it would work in most cases.
perhaps just set a bigger threshold for this.

from gocritic docs:

@hugeParam.sizeThreshold size in bytes that makes the warning trigger (default 80)

so maybe set this to a higher number ? (512?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

DeviceType DeviceType `json:"deviceType,omitempty"`
Selectors *json.RawMessage `json:"selectors,omitempty"`
SelectorObj interface{}
ResourcePrefix string `json:"resourcePrefix,omitempty"` // optional resource prefix that will overwrite
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can put long comments above the variable, I think its clearer that way, especially for multiline comments

Copy link
Member Author

Choose a reason for hiding this comment

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

done

name: Hadolint
steps:
- uses: actions/checkout@v2
- uses: brpaz/[email protected]
Copy link
Contributor

@adrianchiris adrianchiris Jul 25, 2021

Choose a reason for hiding this comment

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

should we just ignore DL3018 for now ?
alternative is to just fix the packages we install to whatever is being installed today.
(this has its downside though...)

Copy link
Member Author

@martinkennelly martinkennelly Jul 26, 2021

Choose a reason for hiding this comment

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

I don't think we should ignore it because it will reduce the need for a discussion and outcome. I will create an issue following this PR to get consensus for this issue. We may just want to ignore it..

Pros for setting it to a version:
We get a version we know that works - more deterministic.
Cons for settings it to a version:
We need to update the version before its no longer available in the package managers repo or it will break our builds.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes +1 on opening an issue and meanwhile ignore so check passes with current state of things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Ignored following community response on the issue.

@adrianchiris
Copy link
Contributor

looking at ShellCheck issues, they seem relatively straight forward.

most remaining golang-ci issues dont seem to be too complex, but are not instant fixes.
(some may need a localy ignore in code IMO). Im fine with following up on remaining issue.

Disabled because we are not using any complicated flags in
entrypoint.sh. Did not want to replace with printf. We are
set to alpines almquist shell by default in our images and ash
supports "-e" flag.

Signed-off-by: Martin Kennelly <[email protected]>
This partially reverts commit
aa3d514 pointless
memory optimisation.

Signed-off-by: Martin Kennelly <[email protected]>
This is a control plane component. As such, we are
moving relatively little data in memory and there is
no "hot path". Strictly following the gocritic advice
reduces readability when pure perf isn't that
important.

Signed-off-by: Martin Kennelly <[email protected]>
As a community, we decided not to pin pkg versions.
If we do not pin, we consume pkg fixes.
If we do not pin, we test against latest pkgs.
We wish to let downstream pin if they wish.

Signed-off-by: Martin Kennelly <[email protected]>
Use COPY instead of ADD per DL3020.
Ignore pinning version per GH issue 368.

Signed-off-by: Martin Kennelly <[email protected]>
@martinkennelly
Copy link
Member Author

martinkennelly commented Jul 30, 2021

@adrianchiris I needed to bump hadolint version to get ignore option and then it showed up issues in rhel7 dockerfile. Corrected them minor issue and needed to add an ignore tag for yum to hadolint. I think we are good for merge. Thanks for all your support here.

Edit: There's a lot of commits. Don't mind squashing but there is some value in them as well.. Leave it up to you.

@adrianchiris
Copy link
Contributor

Thanks for working on this Martin !
I will sort out remaining lint issues once we merge this.

I see Mellanox CI is failing on this PR with error deploying device plugin.
@martinkennelly did you encounter any issue running device plugin from your PR ?

flag provided but not defined: -v 10 --log_dir /var/log/sriovdp --alsologtostderr
Usage of /usr/bin//sriovdp:
  -alsologtostderr
    	log to standard error as well as files
  -config-file string
    	JSON device pool config file location (default "/etc/pcidp/config.json")
  -log_backtrace_at value
    	when logging hits line file:N, emit a stack trace
  -log_dir string
    	If non-empty, write log files in this directory
  -logtostderr
    	log to standard error instead of files
  -resource-prefix string
    	resource name prefix used for K8s extended resource (default "intel.com")
  -stderrthreshold value
    	logs at or above this threshold go to stderr
  -v value
    	log level for V logs
  -vmodule value
    	comma-separated list of pattern=N settings for file-filtered logging

Incorrectly passing args to SRIOV DP binary using
exec. Ignored shellcheck error as word splitting
is desirable. Globbing is disabled.

Fix could be converting to an array but it is too
much work for no gain.

Signed-off-by: Martin Kennelly <[email protected]>
@adrianchiris
Copy link
Contributor

Thanks Martin !

LGTM, I will followup with a fix for remaining golangci-lint issues.

@adrianchiris adrianchiris merged commit d0b252a into k8snetworkplumbingwg:master Aug 3, 2021
@martinkennelly
Copy link
Member Author

martinkennelly commented Aug 3, 2021

@martinkennelly did you encounter any issue running device plugin from your PR ?

@adrianchiris Embarrassingly, I did not. Lesson learned.

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.

2 participants