Skip to content

Readiness Tracker Deadlock for Terminating Resources聽#660

Closed

Description

@theMagicalKarp

What

This was brought to my attention and discovered by 馃挭@SimKev2 馃挭

Resources which are marked for termination, on gatekeeper startup, cause gatekeeper to fail its readiness probes indefinitely (assuming gatekeeper is trying to sync those resources). This seems to be because gatekeeper is trying to ensure it has successfully loaded the sync cache before it handles any traffic. However, it "expects" but fails to "observe" terminating resources, resulting in a deadlock for the readiness check.

Steps

  1. Create the following namespace.
apiVersion: v1
kind: Namespace
metadata:
  finalizers:
  - rob.test.io/abcdefg
  name: rob-test
  1. Delete it with kubectl delete ns rob-test (This should hang, since the finalizer won't resolve) The purpose of this is to put a resource permanently into the terminating state.

  2. Ensure Namespace is in the sync config

apiVersion: config.gatekeeper.sh/v1alpha1
kind: Config
metadata:
  name: config
  namespace: gatekeeper-system
spec:
  sync:
    syncOnly:
    - kind: Namespace
      version: v1
  1. Start Gatekeeper

After gatekeeper starts up it should fail its readiness checks indefinitely.

This seems to be because when setting the expectations for the objectTracker we take into consideration the rob-test namespace (even though it's terminating). This becomes a problem later when running the sync controller, since it doesn't observe resources marked for termination.

I think what makes sense is to run Observe on resources which have been marked for termination.

So add this r.tracker.ForData(gvk).Observe(instance) here

if !instance.GetDeletionTimestamp().IsZero() {

FYI @shomron

Environment:

  • Gatekeeper version: v3.1.0-beta.9
  • Kubernetes version: 1.15

Activity

  1. maxsmythe commented on Jun 2, 2020

    @maxsmythe
    Contributor

    Thanks for finding this! We should also call cancel expectations for any observed deletes. Otherwise there is a race condition where an object is deleted sometime after the initial list is gathered but before the operator begins syncing.

  2. maxsmythe commented on Jun 2, 2020

    @maxsmythe
    Contributor

    This also involves modifying the cancel expectation function to short-circuit if expectations already satisfied to avoid a memory leak.

  3. maxsmythe commented on Jun 2, 2020

    @maxsmythe
    Contributor

    It looks like we are already calling CancelExpect for all deleted constraint templates, so short-circuiting-if-populated would fix a memory leak there

  4. shomron commented on Jun 9, 2020

    @shomron
    Contributor

    @theMagicalKarp thank you again!
    @maxsmythe I can pick up the remaining work, need to confirm the scope.

  5. maxsmythe commented on Jun 9, 2020

    @maxsmythe
    Contributor

    ack, lemme know. Happy to help if the scope is too large.

  6. added 2 commits that reference this issue on Jun 15, 2020
    70f59cd
    e509ef6
  7. added a commit that references this issue on Jun 17, 2020
    dc285d8
  8. niroowns commented on Aug 28, 2020

    @niroowns

    Hi @maxsmythe @shomron - is there a work around for this without having to update to the latest image? We're running verison v3.1.0-beta.9 of the controller. We're seeing what appears to be a similar issue impacting the pod resource, but I don't see anything in a "Terminating" state. Removing pods from the config file and deleting the controller pod does allow it to come up and the readiness probe to pass. I'm just not sure which is the offending pod within the cluster that's causing the readiness probe to return a 500. Any help would be appreciated.

  9. shomron commented on Aug 28, 2020

    @shomron
    Contributor

    @niroowns without updating the image, your best bet would be to remove the readinessProbe from the Gatekeeper manifest. But upgrading would be preferable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions