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

run vet and lint in CI #136

Merged
merged 3 commits into from
Jan 10, 2023
Merged

run vet and lint in CI #136

merged 3 commits into from
Jan 10, 2023

Conversation

VinozzZ
Copy link
Contributor

@VinozzZ VinozzZ commented Jan 5, 2023

This PR adds vet and lint stage in github action.
For linting, the PR adds staticcheck into the repo
related to: #131

Signed-off-by: Yingrong Zhao <[email protected]>
@codecov
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #136 (92d7d98) into main (e448eb7) will increase coverage by 0.35%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
+ Coverage   77.95%   78.30%   +0.35%     
==========================================
  Files          12       12              
  Lines        1016     1014       -2     
==========================================
+ Hits          792      794       +2     
+ Misses        142      138       -4     
  Partials       82       82              
Flag Coverage Δ
unit-tests 78.30% <100.00%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/v1/porterconfig_types.go 66.66% <ø> (ø)
controllers/agentaction_controller.go 80.90% <100.00%> (+0.81%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@VinozzZ VinozzZ requested a review from bdegeeter January 5, 2023 17:21
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Looks good! I just have a few questions/nits.

@@ -91,12 +91,12 @@ func MergeMap(target, override map[string]interface{}) map[string]interface{} {

// SecretsConfig is the plugin stanza for secrets.
type SecretsConfig struct {
PluginConfig `json:",squash" yaml:",inline" mapstructure:",squash"`
PluginConfig `json:",inline" yaml:",inline" mapstructure:",squash"`
Copy link
Member

Choose a reason for hiding this comment

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

This is always confusing! 😅

I am pretty sure that the json tag does not support squash or inline. Embedded fields are always inlined and do not require a json entry at all.

I'm pretty sure that the json tag just ignores the ,inline anyway but it may be more clear (so that people aren't tricked into thinking it is doing anything) if we remove that json tag entirely.

Suggested change
PluginConfig `json:",inline" yaml:",inline" mapstructure:",squash"`
PluginConfig `yaml:",inline" mapstructure:",squash"` # json is inline automatically because it's an embedded field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you are right on the embedded fields are always inlined and do not require a json entry when used with encoding/json, the standard library.
However, it looks like the controller-gen requires it to be specified. I found the same `json:,inline; in their doc as well. https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html

Copy link
Member

Choose a reason for hiding this comment

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

Huh I wonder what they are doing that it's used? 🤔

Thanks for checking, I'll try to remember this the next time I'm tempted to remove it!

for _, condition := range job.Status.Conditions {
switch condition.Type {
case batchv1.JobComplete:
action.Status.Phase = porterv1.PhaseSucceeded
setCondition(log, action, porterv1.ConditionComplete, "JobCompleted")
break
break conditions
Copy link
Member

Choose a reason for hiding this comment

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

I'm unclear on the intent of the change and what we want the code to be doing. The way I'm reading this, when a condition on the job is complete/failed, we will call setCondition, and then repeat the entire for loop over again, re-evaluating the original condition that called the goto.

Is there a way we can do this without the goto statement (break to a label)? At the very least we need a lot more comments explaining what's intended and make sure we have a test to validate that this can't cause an infinite loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood the original code. I think the break statement is redundant and I just removed them

tmp, err := ioutil.TempDir("", "porter-docs-test")
require.NoError(t, err)
defer os.RemoveAll(tmp)
tmp := t.TempDir()
Copy link
Member

Choose a reason for hiding this comment

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

So much cleaner! 💯

Signed-off-by: Yingrong Zhao <[email protected]>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Thanks for adding this! I look forward to the day in 2050 when we have all the repos standardized. 😊

@VinozzZ VinozzZ merged commit 4c2faac into getporter:main Jan 10, 2023
@VinozzZ VinozzZ deleted the add-staticcheck branch January 10, 2023 16:10
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