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 cpu/memory limits and reservations being reset on service update #1079

Merged
merged 2 commits into from
May 24, 2018

Commits on May 23, 2018

  1. Fix cpu/memory limits and reservations being reset on service update

    Before this change:
    ----------------------------------------------------
    
    Create a service with reservations and limits for memory and cpu:
    
        docker service create --name test \
          --limit-memory=100M --limit-cpu=1 \
          --reserve-memory=100M --reserve-cpu=1 \
          nginx:alpine
    
    Verify the configuration
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "NanoCPUs": 1000000000,
            "MemoryBytes": 104857600
          },
          "Reservations": {
            "NanoCPUs": 1000000000,
            "MemoryBytes": 104857600
          }
        }
    
    Update just CPU limit and reservation:
    
        docker service update --limit-cpu=2 --reserve-cpu=2 test
    
    Notice that the memory limit and reservation is not preserved:
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "NanoCPUs": 2000000000
          },
          "Reservations": {
            "NanoCPUs": 2000000000
          }
        }
    
    Update just Memory limit and reservation:
    
        docker service update --limit-memory=200M --reserve-memory=200M test
    
    Notice that the CPU limit and reservation is not preserved:
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "MemoryBytes": 209715200
          },
          "Reservations": {
            "MemoryBytes": 209715200
          }
        }
    
    After this change:
    ----------------------------------------------------
    
    Create a service with reservations and limits for memory and cpu:
    
        docker service create --name test \
          --limit-memory=100M --limit-cpu=1 \
          --reserve-memory=100M --reserve-cpu=1 \
          nginx:alpine
    
    Verify the configuration
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "NanoCPUs": 1000000000,
            "MemoryBytes": 104857600
          },
          "Reservations": {
            "NanoCPUs": 1000000000,
            "MemoryBytes": 104857600
          }
        }
    
    Update just CPU limit and reservation:
    
        docker service update --limit-cpu=2 --reserve-cpu=2 test
    
    Confirm that the CPU limits/reservations are updated, but memory limit and reservation are preserved:
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "NanoCPUs": 2000000000,
            "MemoryBytes": 104857600
          },
          "Reservations": {
            "NanoCPUs": 2000000000,
            "MemoryBytes": 104857600
          }
        }
    
    Update just Memory limit and reservation:
    
        docker service update --limit-memory=200M --reserve-memory=200M test
    
    Confirm that the Mempry limits/reservations are updated, but CPU limit and reservation are preserved:
    
        docker service inspect --format '{{json .Spec.TaskTemplate.Resources}}' test
        {
          "Limits": {
            "NanoCPUs": 2000000000,
            "MemoryBytes": 209715200
          },
          "Reservations": {
            "NanoCPUs": 2000000000,
            "MemoryBytes": 209715200
          }
        }
    
    Signed-off-by: Sebastiaan van Stijn <[email protected]>
    
    Signed-off-by: Sebastiaan van Stijn <[email protected]>
    thaJeztah committed May 23, 2018
    Configuration menu
    Copy the full SHA
    df43eb9 View commit details
    Browse the repository at this point in the history
  2. Minor refactor: use anyChanged() to detect changed flags

    Signed-off-by: Sebastiaan van Stijn <[email protected]>
    thaJeztah committed May 23, 2018
    Configuration menu
    Copy the full SHA
    df9a0c7 View commit details
    Browse the repository at this point in the history