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

Refactor artifacts logic #91

Merged

Conversation

justinsb
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 16, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 16, 2021
Copy link
Contributor

@amwat amwat left a 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

  1. ephemeral (e.g. os.TempDir() ),
  2. not ephemeral but not upload-worthy (RunDir()),
  3. not ephemeral, usable across runs (os.UserCacheDir() )
  4. 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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()))
Copy link
Contributor

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

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 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea - done!

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 17, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 17, 2021
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 17, 2021
@@ -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 {
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2021
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 19, 2021
Copy link
Contributor Author

@justinsb justinsb left a 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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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()))
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 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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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).
@k8s-ci-robot k8s-ci-robot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Feb 19, 2021
@amwat
Copy link
Contributor

amwat commented Feb 24, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 24, 2021
@k8s-ci-robot k8s-ci-robot merged commit d152169 into kubernetes-sigs:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants