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

🐛 Fix flake TestMachineSetReconciler test #11728

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

Karthik-K-N
Copy link
Contributor

What this PR does / why we need it:
Fixes flake TestMachineSetReconciler_syncReplicas_WithErrors test by explicitly use scheme in flake client.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #11722

/area testing

@k8s-ci-robot k8s-ci-robot added area/testing Issues or PRs related to testing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 22, 2025
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 22, 2025
@Karthik-K-N Karthik-K-N changed the title Fix flake TestMachineSetReconciler test 🐛 Fix flake TestMachineSetReconciler test Jan 22, 2025
@sbueringer
Copy link
Member

Thank you very much!

/test pull-cluster-api-e2e-main

/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 Jan 22, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 12148c02e167f2d321cd30f2c47add5142542900

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

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 Jan 22, 2025
@sbueringer
Copy link
Member

Triggered the wrong test

/test pull-cluster-api-test-main

@Karthik-K-N
Copy link
Contributor Author

@sbueringer For my better understanding, May I know how using scheme explicitly avoids test flake?

@k8s-ci-robot k8s-ci-robot merged commit 664518a into kubernetes-sigs:main Jan 22, 2025
25 of 26 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.10 milestone Jan 22, 2025
@sbueringer
Copy link
Member

sbueringer commented Jan 22, 2025

@sbueringer For my better understanding, May I know how using scheme explicitly avoids test flake?

My understanding from the error in https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/kubernetes-sigs_cluster-api/11718/pull-cluster-api-test-main/1881643904957157376 is the following

The fake client is writing to a map in the scheme here:

Write at 0x00c0005e1800 by goroutine 1838:
  runtime.mapassign()
      /home/prow/go/pkg/mod/golang.org/[email protected]/src/runtime/map.go:615 +0x0
  k8s.io/apimachinery/pkg/runtime.(*Scheme).AddKnownTypeWithName()
      /home/prow/go/pkg/mod/k8s.io/[email protected]/pkg/runtime/scheme.go:181 +0x4c9
  sigs.k8s.io/controller-runtime/pkg/client/fake.(*fakeClient).List()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/fake/client.go:577 +0x447
  sigs.k8s.io/controller-runtime/pkg/client/interceptor.interceptor.List()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/interceptor/intercept.go:64 +0x113
  sigs.k8s.io/controller-runtime/pkg/client/interceptor.(*interceptor).List()

At the same time a predicate from a CAPI controller is reading the scheme here:

Previous read at 0x00c0005e1800 by goroutine 568:
  runtime.mapaccess2()
      /home/prow/go/pkg/mod/golang.org/[email protected]/src/runtime/map.go:479 +0x0
  k8s.io/apimachinery/pkg/runtime.(*Scheme).ObjectKinds()
      /home/prow/go/pkg/mod/k8s.io/[email protected]/pkg/runtime/scheme.go:263 +0x14c
  sigs.k8s.io/controller-runtime/pkg/client/apiutil.GVKForObject()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/apiutil/apimachinery.go:118 +0x367
  sigs.k8s.io/cluster-api/internal/controllers/machine.(*Reconciler).SetupWithManager.All.TypedAll[go.shape.493eaa36ea897cf119aa27fb4a184e0362e48e8c7a3357c23a939a6ebd5c05c7].func15()
      /home/prow/go/src/sigs.k8s.io/cluster-api/util/predicates/generic_predicates.go:70 +0x185

By not using the same scheme in both cases they don't read/write the same map in the same scheme anymore

(if scheme is not set the fake client uses some global default scheme)

@Karthik-K-N
Copy link
Contributor Author

@sbueringer For my better understanding, May I know how using scheme explicitly avoids test flake?

My understanding from the error in https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/kubernetes-sigs_cluster-api/11718/pull-cluster-api-test-main/1881643904957157376 is the following

The fake client is writing to a map in the scheme here:

Write at 0x00c0005e1800 by goroutine 1838:
  runtime.mapassign()
      /home/prow/go/pkg/mod/golang.org/[email protected]/src/runtime/map.go:615 +0x0
  k8s.io/apimachinery/pkg/runtime.(*Scheme).AddKnownTypeWithName()
      /home/prow/go/pkg/mod/k8s.io/[email protected]/pkg/runtime/scheme.go:181 +0x4c9
  sigs.k8s.io/controller-runtime/pkg/client/fake.(*fakeClient).List()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/fake/client.go:577 +0x447
  sigs.k8s.io/controller-runtime/pkg/client/interceptor.interceptor.List()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/interceptor/intercept.go:64 +0x113
  sigs.k8s.io/controller-runtime/pkg/client/interceptor.(*interceptor).List()

At the same time a predicate from a CAPI controller is reading the scheme here:

Previous read at 0x00c0005e1800 by goroutine 568:
  runtime.mapaccess2()
      /home/prow/go/pkg/mod/golang.org/[email protected]/src/runtime/map.go:479 +0x0
  k8s.io/apimachinery/pkg/runtime.(*Scheme).ObjectKinds()
      /home/prow/go/pkg/mod/k8s.io/[email protected]/pkg/runtime/scheme.go:263 +0x14c
  sigs.k8s.io/controller-runtime/pkg/client/apiutil.GVKForObject()
      /home/prow/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/client/apiutil/apimachinery.go:118 +0x367
  sigs.k8s.io/cluster-api/internal/controllers/machine.(*Reconciler).SetupWithManager.All.TypedAll[go.shape.493eaa36ea897cf119aa27fb4a184e0362e48e8c7a3357c23a939a6ebd5c05c7].func15()
      /home/prow/go/src/sigs.k8s.io/cluster-api/util/predicates/generic_predicates.go:70 +0x185

By not using the same scheme in both cases they don't read/write the same map in the same scheme anymore

(if scheme is not set the fake client uses some global default scheme)

Got the point, Thanks for the explanation.

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. area/testing Issues or PRs related to testing 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/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.

TestMachineSetReconciler is flaky
3 participants