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: prevent concurrent build to edit the same namespace #6953

Merged
merged 1 commit into from
Apr 3, 2020

Commits on Apr 3, 2020

  1. fix: prevent concurrent build to edit the same namespace

    This PR prevents builds to edit the same namespace at the same time.
    
    Such a behavior could lead to a namespace to be accidentally wiped out.
    
    Only `jx step helm apply` is locked.
    
    A ConfigMap `jx-lock-{namespace}` is used as a lock. No other build can run while this configmap exists. Waiting builds can edit the data of the ConfigMap in order to be the next one to run. If a build sees that the locking or waiting build is "higher", it will fail. When the build finished, the ConfigMap is removed. A waiting build can also remove the ConfigMap if the lokcing pod has finished.
    
    The algorithm is approximately:
    ```
        Label: CREATE
        try to create the ConfigMap
        if it succeeds:
            return
        Label: READ
        get the ConfigMap and the locking Pod
        if the locking Pod has finished
            remove the ConfigMap
            goto CREATE
        if the ConfigMap references a "higher" build
            fail
        if the ConfigMap references a "lower" build
            update the ConfigMap
        wait for the ConfigMap or the Pod to be updated
            if the ConfigMap is delete
                goto CREATE
            if the ConfigMap references a different build
                goto READ
            if the Pod has finished
                goto CREATE
    ```
    
    fixes jenkins-x#6167
    
    Signed-off-by: Aurélien Lambert <[email protected]>
    aure-olli committed Apr 3, 2020
    Configuration menu
    Copy the full SHA
    4a1ab6e View commit details
    Browse the repository at this point in the history