on master help sign in
Makes Memory constriants more explicit
389eadaDeni Bertovic
docker.cabal+1
@@ -31,6 +31,7 @@ library
31 , network >= 2.6.0
31 , network >= 2.6.0
32 , text >= 1.0.0 && < 2.0.0
32 , text >= 1.0.0 && < 2.0.0
33 , time >= 1.5.0 && < 1.7.0
33 , time >= 1.5.0 && < 1.7.0
34+ , scientific >= 0.3.0 && < 0.4.0
34 , tls >= 1.3.7 && < 1.4.0
35 , tls >= 1.3.7 && < 1.4.0
35 , unordered-containers >= 0.2.0 && < 0.3.0
36 , unordered-containers >= 0.2.0 && < 0.3.0
36 , x509 >= 1.6.0 && < 1.7.0
37 , x509 >= 1.6.0 && < 1.7.0
src/Docker/Client/Types.hs+20−4
@@ -93,6 +93,7 @@ import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
93import Data.Char (isAlphaNum, toUpper)
93import Data.Char (isAlphaNum, toUpper)
94import qualified Data.HashMap.Strict as HM
94import qualified Data.HashMap.Strict as HM
95import Data.Monoid ((<>))
95import Data.Monoid ((<>))
96+import Data.Scientific (floatingOrInteger)
96import Data.Text (Text)
97import Data.Text (Text)
97import qualified Data.Text as T
98import qualified Data.Text as T
98import Data.Time.Clock (UTCTime)
99import Data.Time.Clock (UTCTime)
@@ -1229,6 +1230,21 @@ instance ToJSON DeviceRate where
1229 , "Rate" .= r
1230 , "Rate" .= r
1230 ]
1231 ]
1231
1232
1233+data MemoryConstraintSize = B | M | GB deriving (Eq, Show)
1234+
1235+data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
1236+
1237+instance ToJSON MemoryConstraint where
1238+ toJSON (MemoryConstraint x B) = toJSON x
1239+ toJSON (MemoryConstraint x M) = toJSON $ x * 1024
1240+ toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024
1241+
1242+instance FromJSON MemoryConstraint where
1243+ parseJSON (JSON.Number x) = case (floatingOrInteger x) of
1244+ Left _ -> fail "Failed to parse MemoryConstraint"
1245+ Right i -> return $ MemoryConstraint i B -- | The docker daemon will always return the number as bytes (integer), regardless of how we set them (using M or GB)
1246+ parseJSON _ = fail "Failed to parse MemoryConstraint"
1247+
1232data ContainerResources = ContainerResources {
1248data ContainerResources = ContainerResources {
1233 cpuShares :: Maybe Integer
1249 cpuShares :: Maybe Integer
1234 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
1250 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
@@ -1244,10 +1260,10 @@ data ContainerResources = ContainerResources {
1244 , cpusetMems :: Maybe Text
1260 , cpusetMems :: Maybe Text
1245 , devices :: [Device]
1261 , devices :: [Device]
1246 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1262 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1247− , kernelMemory :: Maybe Integer
1263+ , kernelMemory :: Maybe MemoryConstraint
1248− , memory :: Maybe Integer
1264+ , memory :: Maybe MemoryConstraint
1249− , memoryReservation :: Maybe Integer
1265+ , memoryReservation :: Maybe MemoryConstraint
1250− , memorySwap :: Maybe Integer
1266+ , memorySwap :: Maybe MemoryConstraint
1251 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1267 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1252 , oomKillDisable :: Bool
1268 , oomKillDisable :: Bool
1253 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1269 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.