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

📖 Update tutorial to use cancel context to stop manager #2379

Merged
merged 1 commit into from
Oct 13, 2021

Conversation

erikgb
Copy link
Contributor

@erikgb erikgb commented Oct 13, 2021

This PR introduces a cancellable context in the tutorial controller test suite. This context is used to start the manager in the test suite startup, and context is cancelled before initiating the testEnv shutdown in AfterSuite. This seems to fix kubernetes-sigs/controller-runtime#1571, and I think this issue should be closed - as not a problem (in controller-runtime).

The PR also reverts the workaround for this issue introduced in #2302.

It seems like this pattern is already in use in the webhook test suite, so I also removed some uneeded non-nil error ifs in those files.

Note to reviewer: I am uncertain if more needs to be updated.... It seems like the skaffolding of the controller test suite could include more, but I didn't want to extend it as part of this fix.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 13, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @erikgb!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @erikgb. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 13, 2021
@erikgb
Copy link
Contributor Author

erikgb commented Oct 13, 2021

/cc @camilamacedo86 @estroz

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

/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 Oct 13, 2021
@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

@erikgb while you're at it, also update this line to 1.22.0 so we know this change works with the latest kube-apiserver.

@erikgb erikgb force-pushed the fix-test-shutdown branch 2 times, most recently from 56e04ce to 7bfac29 Compare October 13, 2021 16:09
@erikgb
Copy link
Contributor Author

erikgb commented Oct 13, 2021

@erikgb while you're at it, also update this line to 1.22.0 so we know this change works with the latest kube-apiserver.

@estroz Done, hopefully the build will go through now - if I didn't make another mistake. This fix works in our controller builds now, using K8s 1.22.0.

@erikgb
Copy link
Contributor Author

erikgb commented Oct 13, 2021

@estroz Do you have any idea why all jobs are failing now? It seems like the control-plane never comes up, but I am not sure why...

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

Looking into it.

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

Etcd is not starting locally for me either with 1.22 🤷‍♂️. 1.21.4 works though, so change it to that for now.

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

I didn't notice this error before. (edit: kustomize is being removed by cleanup, this isn't an issue) I'm not sure why this is still failing with the same error, as it works locally for me. Need to investigate more what's happening here.

@erikgb
Copy link
Contributor Author

erikgb commented Oct 13, 2021

@estroz Maybe we should postpone the K8s upgrade? The tests for kubebuilder v2 (that are failing) uses controller-tools v0.3.0, and I do not think that version supports K8s version >= 1.20.

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

Maybe we should postpone the K8s upgrade

Sounds good

@estroz
Copy link
Contributor

estroz commented Oct 13, 2021

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: erikgb, estroz

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 Oct 13, 2021
@tenstad
Copy link

tenstad commented Oct 13, 2021

Not sure what caused the problems with k8s_version=1.21.4, but I believe the resulting error may be caused by a WARNING output from kubectl version in kubectl.go#L143

<*json.SyntaxError | 0xc000098018>: {
            msg: "invalid character 'W' after top-level value",
            Offset: 614,
        }
        invalid character 'W' after top-level value

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kubebuilder/2379/pull-kubebuilder-e2e-k8s-1-14-10/1448334663717228544

I got WARNING: version difference between client (0.21) and server (1.21) exceeds the supported minor version skew of +/-1 locally, after a 626 char json output (kubectl version -o json 2>/dev/null | wc -c). It might not be the same warning in the tests though, but it may be a clue.

@k8s-ci-robot k8s-ci-robot merged commit 29a1280 into kubernetes-sigs:master Oct 13, 2021
@estroz
Copy link
Contributor

estroz commented Oct 14, 2021

@tenstad fixed by #2382

JohnStrunk added a commit to JohnStrunk/volsync that referenced this pull request Nov 8, 2021
This cancels the context to cause the API server to properly shut down
at the conclusion of the tests.

Ref: kubernetes-sigs/controller-runtime#1571
Ref: kubernetes-sigs/kubebuilder#2379

Signed-off-by: John Strunk <jstrunk@redhat.com>
gkurz added a commit to gkurz/sandboxed-containers-operator that referenced this pull request May 17, 2023
PR openshift#307 was too optimistic. The original issue worked around
by 053f866 still exists actually ; `make test` is now
failing with :

  [FAILED] Unexpected error:
      <errors.aggregate | len:1, cap:1>: [
          <*errors.errorString | 0xc0005ebf80>{
              s: "timeout waiting for process kube-apiserver to stop",
          },
      ]
      timeout waiting for process kube-apiserver to stop
  occurred

This is caused by a missing cancellation of the certwatcher in the
controller-runtime. The fix, as documented in [1], is to create
a cancellable context, pass it to envtest and cancel it just before
tearing down the test.

[1] kubernetes-sigs/kubebuilder#2379

Signed-off-by: Greg Kurz <groug@kaod.org>
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout waiting for process kube-apiserver to stop
4 participants