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 local markdown tests inside an isolated container #882

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

fmuyassarov
Copy link
Member

@fmuyassarov fmuyassarov commented Sep 2, 2022

When working on a patch that touches docs/, there is no way to test changes against markdown checks before submitting a PR. In fact, we have a makefile target mdlint but it has a prerequisite of having mdl installed on the developer machine. What do you think of swapping the tasks of mdlint Makefile target with scripts/test-infra/mdlint.sh script with minor modifications so that developer can just run make mdlint which calls scripts/test-infra/mdlint.sh and the tests get executed within a container. Once execution is completed the temporary container gets removed so that we don't have garbage collected. I've chosen ruby:slim image (70.39 MB), which is almost five times smaller than ruby:2.7 (321.36 MB) that we use in our Prow tests.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 2, 2022
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 2, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @fmuyassarov. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 2, 2022
Copy link
Contributor

@ArangoGutierrez ArangoGutierrez left a comment

Choose a reason for hiding this comment

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

Test run on an isolated container at https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes-sigs/node-feature-discovery/node-feature-discovery-presubmits.yaml#L38.
If what you want is a devel make target, then you need to have in consideration the above.

@fmuyassarov
Copy link
Member Author

fmuyassarov commented Sep 2, 2022

Test run on an isolated container at https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes-sigs/node-feature-discovery/node-feature-discovery-presubmits.yaml#L38.

If what you want is a devel make target, then you need to have in consideration the above.

Yes, so my plan is run it in a container when testing locally. If I am not wrong, this won't break Prow tests too, it is just that there will be an extra container created within prowJob container.

@marquiz
Copy link
Contributor

marquiz commented Sep 5, 2022

I think the idea makes sense. Makes life easier for most of the people

If I am not wrong, this won't break Prow tests too, it is just that there will be an extra container created within prowJob container.

I think the idea behind he scripts under scripts/test-infra has been to keep them as simple and possible and only have strictly prow-specific stuff there. One possibility:

  1. put the one-liner from the makefile into a separate script (say scripts/mdlint.sh)
  2. call this^ script from scripts/test-infra/mdlint.sh
  3. write another script for running mdlint from a container (say hack/mdlint-containerized.sh that runs scripts/mdlint.sh inside a container)
  4. Makefile mdlint: target would call hack/mdlint-containerized.sh

WDYT?

@fmuyassarov
Copy link
Member Author

I think the idea makes sense. Makes life easier for most of the people

If I am not wrong, this won't break Prow tests too, it is just that there will be an extra container created within prowJob container.

I think the idea behind he scripts under scripts/test-infra has been to keep them as simple and possible and only have strictly prow-specific stuff there. One possibility:

Got it.

  1. put the one-liner from the makefile into a separate script (say scripts/mdlint.sh)
  2. call this^ script from scripts/test-infra/mdlint.sh
  3. write another script for running mdlint from a container (say hack/mdlint-containerized.sh that runs scripts/mdlint.sh inside a container)
  4. Makefile mdlint: target would call hack/mdlint-containerized.sh

WDYT?

Yes this should work and I'm fine with this. I will just mention that, we can reuse the same scripts/test-infra/mdlint.sh for both local and Prow tests. When running on Prow, we just have to add variable in test infra with IS_CONTAINER=true. What I don't like with duplication is that we always have to take care two sets of the same things and we have to be careful that they don't diverge. But as said, it is not a big deal at all and I'm ok to decouple the piece for local runs.

@marquiz
Copy link
Contributor

marquiz commented Sep 6, 2022

Got it.

And to put it in other words, the stuff under scripts/test-infra is only supposed to be called from prow 😄

  1. put the one-liner from the makefile into a separate script (say scripts/mdlint.sh)
  2. call this^ script from scripts/test-infra/mdlint.sh
  3. write another script for running mdlint from a container (say hack/mdlint-containerized.sh that runs scripts/mdlint.sh inside a container)
  4. Makefile mdlint: target would call hack/mdlint-containerized.sh

WDYT?

Yes this should work and I'm fine with this. I will just mention that, we can reuse the same scripts/test-infra/mdlint.sh for both local and Prow tests. When running on Prow, we just have to add variable in test infra with IS_CONTAINER=true. What I don't like with duplication is that we always have to take care two sets of the same things and we have to be careful that they don't diverge. But as said, it is not a big deal at all and I'm ok to decouple the piece for local runs.

Yeah, I think this is fine. No need to have two separate scripts

@marquiz
Copy link
Contributor

marquiz commented Sep 6, 2022

Got it.

And to put it in other words, the stuff under scripts/test-infra is only supposed to be called from prow 😄

  1. put the one-liner from the makefile into a separate script (say scripts/mdlint.sh)
  2. call this^ script from scripts/test-infra/mdlint.sh
  3. write another script for running mdlint from a container (say hack/mdlint-containerized.sh that runs scripts/mdlint.sh inside a container)
  4. Makefile mdlint: target would call hack/mdlint-containerized.sh

WDYT?

Yes this should work and I'm fine with this. I will just mention that, we can reuse the same scripts/test-infra/mdlint.sh for both local and Prow tests. When running on Prow, we just have to add variable in test infra with IS_CONTAINER=true. What I don't like with duplication is that we always have to take care two sets of the same things and we have to be careful that they don't diverge. But as said, it is not a big deal at all and I'm ok to decouple the piece for local runs.

Yeah, I think this is fine. No need to have two separate scripts

Hmm, actually what I don't like in this is the recursive nature of the script. With a small mistake end up with infinite loop of nested containers... There should be no duplication with the scripts: one script simply runs mdlint, another script runs the first one in a container environment, and test-infra script simply calls the first one as well. WDYT?

@fmuyassarov
Copy link
Member Author

fmuyassarov commented Sep 6, 2022

Got it.

And to put it in other words, the stuff under scripts/test-infra is only supposed to be called from prow smile

  1. put the one-liner from the makefile into a separate script (say scripts/mdlint.sh)
  2. call this^ script from scripts/test-infra/mdlint.sh
  3. write another script for running mdlint from a container (say hack/mdlint-containerized.sh that runs scripts/mdlint.sh inside a container)
  4. Makefile mdlint: target would call hack/mdlint-containerized.sh

WDYT?

Yes this should work and I'm fine with this. I will just mention that, we can reuse the same scripts/test-infra/mdlint.sh for both local and Prow tests. When running on Prow, we just have to add variable in test infra with IS_CONTAINER=true. What I don't like with duplication is that we always have to take care two sets of the same things and we have to be careful that they don't diverge. But as said, it is not a big deal at all and I'm ok to decouple the piece for local runs.

Yeah, I think this is fine. No need to have two separate scripts

Hmm, actually what I don't like in this is the recursive nature of the script. With a small mistake end up with infinite loop of nested containers... There should be no duplication with the scripts: one script simply runs mdlint, another script runs the first one in a container environment, and test-infra script simply calls the first one as well. WDYT?

Sorry perhaps I confused you. But I'm not changing how we run tests in Prow, because in prow config, we will have IS_CONTAINER=true which will execute

if [ "${IS_CONTAINER}" != "false" ]; then
    # Install mdl
    gem install mdl -v 0.11.0
    # Run verify steps
    find docs/ -path docs/vendor -prune -false -o -name '*.md' -exec mdl -s docs/mdl-style.rb {} \+ 

Basically nothing changes from the Prow's perspective and we are not having nested containers.

As a developer who wants to test locally, we would just run make mdlint which will create a container and
run the tests inside, exactly the same as Prow (1:1). So, this patch is only an addition I would say.

@fmuyassarov
Copy link
Member Author

fmuyassarov commented Sep 6, 2022

As a developer who wants to test locally, we would just run make mdlint which will create a container and run the tests inside, exactly the same as Prow (1:1). So, this patch is only an addition I would say.

It is the same as Prow, because ProwJob also creates the same temporary container with the same container image that we are using here(ruby:slim)

@fmuyassarov
Copy link
Member Author

I've updated kubernetes/test-infra#27376 to match the changes. Let know what you think. Thanks

scripts/test-infra/mdlint.sh Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Signed-off-by: Feruzjon Muyassarov <feruzjon.muyassarov@intel.com>
@fmuyassarov
Copy link
Member Author

Thanks for reviews Markus. Updated as per suggestion.

Copy link
Contributor

@marquiz marquiz 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 reviews Markus. Updated as per suggestion.

Thanks, looks quite simple and clean to me now 😎 Others might see it otherwisem though....

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 6, 2022
@marquiz
Copy link
Contributor

marquiz commented Sep 6, 2022

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 6, 2022
Copy link
Contributor

@ArangoGutierrez ArangoGutierrez left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 6, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ArangoGutierrez, fmuyassarov, marquiz

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 merged commit 42b593f into kubernetes-sigs:master Sep 6, 2022
@fmuyassarov
Copy link
Member Author

/cherry-pick release-0.11

@k8s-infra-cherrypick-robot

@fmuyassarov: #882 failed to apply on top of branch "release-0.11":

Applying: Run local markdown tests inside an isolated container
Using index info to reconstruct a base tree...
M	Makefile
Falling back to patching base and 3-way merge...
Auto-merging Makefile
CONFLICT (content): Merge conflict in Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Run local markdown tests inside an isolated container
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick release-0.11

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@fmuyassarov
Copy link
Member Author

well, I will do it manually:)

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants