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

Remove use of templates for plugins #834

Merged
merged 1 commit into from
Aug 13, 2019

Conversation

zubron
Copy link
Contributor

@zubron zubron commented Aug 12, 2019

What this PR does / why we need it:
This change removes the use of templates for creating resources when
running plugins and instead creates the objects directly to use with the
Kubernetes API. This change should introduce no change in behaviour. It
is just refactoring in preparation for adding support to customise pod
options.

Special notes for your reviewer:
I have added tests for the new changes in base.go. I have only adapted the existing tests for checking that the manifests are created correctly. I can expand on these tests if needed. I have also tested this manually by comparing the resources created for both Job and DaemonSet plugins before and after this change and they are equivalent.

Release note:

NONE

@zubron zubron changed the title WIRemove use of templates for plugins WIP Remove use of templates for plugins Aug 12, 2019
@@ -1,127 +0,0 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be able to rebase onto upstream/master and this commit shouldn't come up anymore.

@@ -42,23 +45,6 @@ type Base struct {
CustomAnnotations map[string]string
}

// TemplateData is all the fields available to plugin driver templates.
type TemplateData struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 for datatypes we get to remove.

@zubron zubron force-pushed the customise-pod-options-809 branch from ffef814 to aab2214 Compare August 12, 2019 19:49
@codecov-io
Copy link

codecov-io commented Aug 12, 2019

Codecov Report

Merging #834 into master will increase coverage by 2.17%.
The diff coverage is 97.46%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #834      +/-   ##
=========================================
+ Coverage   44.73%   46.9%   +2.17%     
=========================================
  Files          75      75              
  Lines        4565    4667     +102     
=========================================
+ Hits         2042    2189     +147     
+ Misses       2390    2348      -42     
+ Partials      133     130       -3
Impacted Files Coverage Δ
pkg/plugin/driver/base.go 84.07% <100%> (+43.82%) ⬆️
pkg/plugin/driver/job/job.go 73.1% <95.55%> (+16.92%) ⬆️
pkg/plugin/driver/daemonset/daemonset.go 66.25% <96.42%> (+17.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94702fb...4c0bd38. Read the comment docs.

@zubron zubron force-pushed the customise-pod-options-809 branch from 3a2ea2e to 10e31d2 Compare August 13, 2019 14:18
@zubron zubron changed the title WIP Remove use of templates for plugins Remove use of templates for plugins Aug 13, 2019
@@ -19,4 +19,7 @@ package plugin
const (
// GracefulShutdownPeriod is how long plugins have to cleanly finish before they are terminated.
GracefulShutdownPeriod = 60

// ResultsDir is the diectory where results will be available in Sonobuoy plugin containers.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/diectory/directory

}
}
for _, e := range wc.Env {
if e.Name == "NODE_NAME" {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would prefer a switch instead of an if...else...if else....if else...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, and thanks for the suggestion. I'm not particularly happy with this test :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a little odd the way you have subtests but it isn't a table driven test.

The other options it seems:

  • It is testing a single large object so you could dump it into one big test instead of bothering with the sub-tests. The error messages would just provide the context
  • make a table driven test/subtests and split off the larger chunks of logic (which make it hard to read) into little helper funcs. So you'd have:
tc := testCases{
  desc string
  expectFunc func(<types we're checking>) error
}{
  { desc: "Env vars set",
    expectFunc: checkEnvVars},
...
}

The benefit to (1) is that its straight forward to code but the downside it isn't clear when reading any particular section of the test what has been tested, will be tested, could be added, etc.

The benefit of (2) is that you can look at the table and atleast see a list of all the things you intend to test about it (even if only vague details). The downside is you have to reorg the code a bit to put those test functions in an accessible place and it may seem a bit odd since you won't be reusing those functions elsewhere. But you could, within that test itself, define those functions inline and then only make the table at the end:

func TestXYZ(t *testing.T){
  checkEnvVars:= func(...) error{...}
  checkFields:= func(...) error{...}

  tc := testCases {...}{...}
...

I think I would probably prefer (2) if I were writing it, but I wont block it either way.

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 decided to change this test and do it the way you mentioned in (2). Let me know what you think.

@zubron zubron force-pushed the customise-pod-options-809 branch from 10e31d2 to a9efcae Compare August 13, 2019 15:36
}{
{
"Fields set correctly",
checkFields,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I do like reading the test more this way. It is also clear how I could/should expand the functionality if I needed to test something else.

Copy link
Contributor

@johnSchnake johnSchnake 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, going to manually do a run and check how the results look before merging.

This change removes the use of templates for creating resources when
running plugins and instead creates the objects directly to use with the
Kubernetes API. This change should introduce no change in behaviour. It
is just refactoring in preparation for adding support to customise pod
options.

Signed-off-by: Bridget McErlean <[email protected]>
@zubron zubron force-pushed the customise-pod-options-809 branch from a9efcae to 4c0bd38 Compare August 13, 2019 16:28
Copy link
Contributor

@johnSchnake johnSchnake left a comment

Choose a reason for hiding this comment

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

Tested it with my own set of plugins and also the e2e/systemd-logs. All looked great.

@zubron zubron merged commit 4c07889 into vmware-tanzu:master Aug 13, 2019
@zubron zubron deleted the customise-pod-options-809 branch August 13, 2019 17:33
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.

3 participants