-
Notifications
You must be signed in to change notification settings - Fork 103
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
Refactor artifacts logic #91
Refactor artifacts logic #91
Conversation
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.
Huge +1 to this, Thanks!
Ideally we want to expose different options, so deployers can decide for themselves which artifacts are
- ephemeral (e.g. os.TempDir() ),
- not ephemeral but not upload-worthy (RunDir()),
- not ephemeral, usable across runs (os.UserCacheDir() )
- not ephemeral, upload-worthy (ArtifactsDir()).
/lgtm
/approve
/hold for a few nits
@@ -260,14 +233,14 @@ func (o *options) ShouldTest() bool { | |||
return o.test != "" | |||
} | |||
|
|||
func (o *options) ArtifactsDir() string { |
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.
we might need to expose this again in the future if this and rundir are decoupled.
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.
Agree, but now we should use artifacts.BaseDir()
(note that we've moved the flag there, invoked by artifacts.BindFlags()
)
@@ -120,7 +120,7 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
exec.InheritOutput(test) | |||
|
|||
envsForTester := os.Environ() | |||
envsForTester = append(envsForTester, fmt.Sprintf("%s=%s", "ARTIFACTS", opts.ArtifactsDir())) | |||
envsForTester = append(envsForTester, fmt.Sprintf("%s=%s", "ARTIFACTS", opts.RunDir())) |
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.
let's also additionally expose this as KUBETEST2_RUN_DIR
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 like that - setting us up for the future cleanup (I like the 4 directories you suggested in your comment - just wanted to keep the PR focused). Added!
@@ -72,7 +73,12 @@ func (t *Tester) AcquireTestPackage() error { | |||
} | |||
|
|||
func (t *Tester) extractBinaries(downloadPath string) error { | |||
// finally, search for the test package and extract it | |||
// ensure the artifacts dir | |||
if err := os.MkdirAll(artifacts.BaseDir(), os.ModePerm); 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.
I think we already do this as part of the main kubetest2 app code.
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, but kubetest2-test-kops calls this directly
@@ -57,12 +57,12 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
// TODO(bentheelder): signal handling & timeout | |||
|
|||
// ensure the artifacts dir | |||
if err := os.MkdirAll(opts.ArtifactsDir(), os.ModePerm); err != nil { | |||
if err := os.MkdirAll(opts.RunDir(), os.ModePerm); 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.
we ensure the directory exists, can drop from ginkgo tester.
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.
nit: Also update that comment on 59 to match*
Do we ensure it exists with correct permissions?
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.
@MushuEE Updated the comment.
@amwat I actually added it to the ginkgo tester because I hit the directory not existing, because the ginkgo tester might be invoked from e.g. kubetest2-tester-kops and doesn't necessarily go through this path (though I'm still learning how this all fits together, so could be wrong here).
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 if you invoke the kubetest2-tester-kops binary directly (not recommended) then you would hit this.
but if you invoke it as kubetest2 kops --test=kops
then it should go through the kubetest2 lifecycle.
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.
/hold cancel
interested in getting this in, can be cleaned up later.
@@ -57,12 +57,12 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
// TODO(bentheelder): signal handling & timeout | |||
|
|||
// ensure the artifacts dir | |||
if err := os.MkdirAll(opts.ArtifactsDir(), os.ModePerm); err != nil { | |||
if err := os.MkdirAll(opts.RunDir(), os.ModePerm); 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.
nit: since we are already changing stuff related to this
let's klog.Infof(opts.RunDir())
similar to how we log the runID on lin 87 for consistency
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!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amwat, justinsb 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 |
@@ -57,12 +57,12 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
// TODO(bentheelder): signal handling & timeout | |||
|
|||
// ensure the artifacts dir | |||
if err := os.MkdirAll(opts.ArtifactsDir(), os.ModePerm); err != nil { | |||
if err := os.MkdirAll(opts.RunDir(), os.ModePerm); 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.
nit: Also update that comment on 59 to match*
Do we ensure it exists with correct permissions?
for { | ||
// Put this check before any break condition so we don't | ||
// accidentally incorrectly error | ||
if foundTestPackage && foundBinary { | ||
if len(extracted) == len(extract) { |
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.
Do you want to return here or break to also get the double check on the downloadPath check?
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 call - I think I get away with it, but a break is cleaner. Changed!
2562ddf
to
5440fc8
Compare
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 - pushed updates!
@@ -57,12 +57,12 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
// TODO(bentheelder): signal handling & timeout | |||
|
|||
// ensure the artifacts dir | |||
if err := os.MkdirAll(opts.ArtifactsDir(), os.ModePerm); err != nil { | |||
if err := os.MkdirAll(opts.RunDir(), os.ModePerm); 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.
@MushuEE Updated the comment.
@amwat I actually added it to the ginkgo tester because I hit the directory not existing, because the ginkgo tester might be invoked from e.g. kubetest2-tester-kops and doesn't necessarily go through this path (though I'm still learning how this all fits together, so could be wrong here).
@@ -57,12 +57,12 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
// TODO(bentheelder): signal handling & timeout | |||
|
|||
// ensure the artifacts dir | |||
if err := os.MkdirAll(opts.ArtifactsDir(), os.ModePerm); err != nil { | |||
if err := os.MkdirAll(opts.RunDir(), os.ModePerm); 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.
Good idea - done!
@@ -120,7 +120,7 @@ func RealMain(opts types.Options, d types.Deployer, tester types.Tester) (result | |||
exec.InheritOutput(test) | |||
|
|||
envsForTester := os.Environ() | |||
envsForTester = append(envsForTester, fmt.Sprintf("%s=%s", "ARTIFACTS", opts.ArtifactsDir())) | |||
envsForTester = append(envsForTester, fmt.Sprintf("%s=%s", "ARTIFACTS", opts.RunDir())) |
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 like that - setting us up for the future cleanup (I like the 4 directories you suggested in your comment - just wanted to keep the PR focused). Added!
@@ -260,14 +233,14 @@ func (o *options) ShouldTest() bool { | |||
return o.test != "" | |||
} | |||
|
|||
func (o *options) ArtifactsDir() string { |
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.
Agree, but now we should use artifacts.BaseDir()
(note that we've moved the flag there, invoked by artifacts.BindFlags()
)
@@ -72,7 +73,12 @@ func (t *Tester) AcquireTestPackage() error { | |||
} | |||
|
|||
func (t *Tester) extractBinaries(downloadPath string) error { | |||
// finally, search for the test package and extract it | |||
// ensure the artifacts dir | |||
if err := os.MkdirAll(artifacts.BaseDir(), os.ModePerm); 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.
Yes, but kubetest2-test-kops calls this directly
for { | ||
// Put this check before any break condition so we don't | ||
// accidentally incorrectly error | ||
if foundTestPackage && foundBinary { | ||
if len(extracted) == len(extract) { |
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 call - I think I get away with it, but a break is cleaner. Changed!
In particular this makes the distinction between the artifacts dir and the run dir (but doesn't change the logic yet), but also allows us to download and run ginkgo without requiring it to be in the PATH (if ARTIFACTS is not set).
5440fc8
to
7f5e6db
Compare
/lgtm |
In particular this makes the distinction between the artifacts dir and the
run dir (but doesn't change the logic yet), but also allows us to download
and run ginkgo without requiring it to be in the PATH (if ARTIFACTS is not
set).
Builds on #90