Skip to content

Commit

Permalink
Automatically round container instance memory to the first decimal pl…
Browse files Browse the repository at this point in the history
…ace (#1004)
  • Loading branch information
ninjarobot authored Jan 28, 2023
1 parent 4702b7d commit e63388c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Release Notes
=============
## vNext
* Identity: Update the list of all RBAC roles to latest.
* Container Groups: Automatically round container instance memory to the first decimal place.

## 1.7.13
* KeyVault: Added support for disabling public network access.
Expand Down
5 changes: 4 additions & 1 deletion src/Farmer/Builders/Builders.ContainerGroups.fs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,10 @@ type ContainerInstanceBuilder() =

/// Sets the maximum gigabytes of memory the container instance may use
[<CustomOperationAttribute "memory">]
member _.Memory(state: ContainerInstanceConfig, memory) = { state with Memory = memory }
member _.Memory(state: ContainerInstanceConfig, memory: float<Gb>) =
{ state with
Memory = System.Math.Round(memory / 1.<Gb>, 1) * 1.<Gb>
}

/// Enables container instances with gpus
[<CustomOperationAttribute "gpu">]
Expand Down
38 changes: 38 additions & 0 deletions src/Tests/ContainerGroup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ let tests =
Expect.equal ports [ 80; 443; 9090 ] "Incorrect ports on container"
}

test "Container group memory increment truncation" {
let container4_5Gb =
containerInstance {
name "myapp"
image "myapp:latest"
memory 4.5678<Gb>
}

Expect.equal 4.6<Gb> container4_5Gb.Memory "Memory rounded incorrectly for 4.5 GB"

let container8Gb =
containerInstance {
name "myapp"
image "myapp:latest"
memory 8.<Gb>
}

Expect.equal 8.0<Gb> container8Gb.Memory "Memory rounded incorrectly for 8 GB"

let container8_2Gb =
containerInstance {
name "myapp"
image "myapp:latest"
memory 8.2<Gb>
}

Expect.equal 8.2<Gb> container8_2Gb.Memory "Memory rounded incorrectly for 8.2 GB"

let container0_2Gb =
containerInstance {
name "myapp"
image "myapp:latest"
memory 0.22<Gb>
}

Expect.equal 0.2<Gb> container0_2Gb.Memory "Memory rounded incorrectly for 0.2 GB"
}

test "Container group with init containers" {
let group =
let emptyDir1 = "emptyDir1"
Expand Down

0 comments on commit e63388c

Please sign in to comment.