@@ -1433,3 +1433,170 @@ func WithWindowsDevice(idType, id string) SpecOpts {
14331433 return nil
14341434 }
14351435}
1436+
1437+ // WithMemorySwap sets the container's swap in bytes
1438+ func WithMemorySwap (swap int64 ) SpecOpts {
1439+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1440+ setResources (s )
1441+ if s .Linux .Resources .Memory == nil {
1442+ s .Linux .Resources .Memory = & specs.LinuxMemory {}
1443+ }
1444+ s .Linux .Resources .Memory .Swap = & swap
1445+ return nil
1446+ }
1447+ }
1448+
1449+ // WithPidsLimit sets the container's pid limit or maximum
1450+ func WithPidsLimit (limit int64 ) SpecOpts {
1451+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1452+ setResources (s )
1453+ if s .Linux .Resources .Pids == nil {
1454+ s .Linux .Resources .Pids = & specs.LinuxPids {}
1455+ }
1456+ s .Linux .Resources .Pids .Limit = limit
1457+ return nil
1458+ }
1459+ }
1460+
1461+ // WithBlockIO sets the container's blkio parameters
1462+ func WithBlockIO (blockio * specs.LinuxBlockIO ) SpecOpts {
1463+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1464+ setResources (s )
1465+ s .Linux .Resources .BlockIO = blockio
1466+ return nil
1467+ }
1468+ }
1469+
1470+ // WithCPUShares sets the container's cpu shares
1471+ func WithCPUShares (shares uint64 ) SpecOpts {
1472+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1473+ setCPU (s )
1474+ s .Linux .Resources .CPU .Shares = & shares
1475+ return nil
1476+ }
1477+ }
1478+
1479+ // WithCPUs sets the container's cpus/cores for use by the container
1480+ func WithCPUs (cpus string ) SpecOpts {
1481+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1482+ setCPU (s )
1483+ s .Linux .Resources .CPU .Cpus = cpus
1484+ return nil
1485+ }
1486+ }
1487+
1488+ // WithCPUsMems sets the container's cpu mems for use by the container
1489+ func WithCPUsMems (mems string ) SpecOpts {
1490+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1491+ setCPU (s )
1492+ s .Linux .Resources .CPU .Mems = mems
1493+ return nil
1494+ }
1495+ }
1496+
1497+ // WithCPUCFS sets the container's Completely fair scheduling (CFS) quota and period
1498+ func WithCPUCFS (quota int64 , period uint64 ) SpecOpts {
1499+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1500+ setCPU (s )
1501+ s .Linux .Resources .CPU .Quota = & quota
1502+ s .Linux .Resources .CPU .Period = & period
1503+ return nil
1504+ }
1505+ }
1506+
1507+ // WithCPURT sets the container's realtime scheduling (RT) runtime and period.
1508+ func WithCPURT (runtime int64 , period uint64 ) SpecOpts {
1509+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1510+ setCPU (s )
1511+ s .Linux .Resources .CPU .RealtimeRuntime = & runtime
1512+ s .Linux .Resources .CPU .RealtimePeriod = & period
1513+ return nil
1514+ }
1515+ }
1516+
1517+ // WithoutRunMount removes the `/run` inside the spec
1518+ func WithoutRunMount (ctx context.Context , client Client , c * containers.Container , s * Spec ) error {
1519+ return WithoutMounts ("/run" )(ctx , client , c , s )
1520+ }
1521+
1522+ // WithRdt sets the container's RDT parameters
1523+ func WithRdt (closID , l3CacheSchema , memBwSchema string ) SpecOpts {
1524+ return func (ctx context.Context , _ Client , c * containers.Container , s * Spec ) error {
1525+ s .Linux .IntelRdt = & specs.LinuxIntelRdt {
1526+ ClosID : closID ,
1527+ L3CacheSchema : l3CacheSchema ,
1528+ MemBwSchema : memBwSchema ,
1529+ }
1530+ return nil
1531+ }
1532+ }
1533+
1534+ // WithWindowsCPUCount sets the `Windows.Resources.CPU.Count` section to the
1535+ // `count` specified.
1536+ func WithWindowsCPUCount (count uint64 ) SpecOpts {
1537+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1538+ setCPUWindows (s )
1539+ s .Windows .Resources .CPU .Count = & count
1540+ return nil
1541+ }
1542+ }
1543+
1544+ // WithWindowsCPUShares sets the `Windows.Resources.CPU.Shares` section to the
1545+ // `shares` specified.
1546+ func WithWindowsCPUShares (shares uint16 ) SpecOpts {
1547+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1548+ setCPUWindows (s )
1549+ s .Windows .Resources .CPU .Shares = & shares
1550+ return nil
1551+ }
1552+ }
1553+
1554+ // WithWindowsCPUMaximum sets the `Windows.Resources.CPU.Maximum` section to the
1555+ // `max` specified.
1556+ func WithWindowsCPUMaximum (max uint16 ) SpecOpts {
1557+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1558+ setCPUWindows (s )
1559+ s .Windows .Resources .CPU .Maximum = & max
1560+ return nil
1561+ }
1562+ }
1563+
1564+ // WithWindowsIgnoreFlushesDuringBoot sets `Windows.IgnoreFlushesDuringBoot`.
1565+ func WithWindowsIgnoreFlushesDuringBoot () SpecOpts {
1566+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1567+ if s .Windows == nil {
1568+ s .Windows = & specs.Windows {}
1569+ }
1570+ s .Windows .IgnoreFlushesDuringBoot = true
1571+ return nil
1572+ }
1573+ }
1574+
1575+ // WithWindowNetworksAllowUnqualifiedDNSQuery sets `Windows.Network.AllowUnqualifiedDNSQuery`.
1576+ func WithWindowNetworksAllowUnqualifiedDNSQuery () SpecOpts {
1577+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1578+ if s .Windows == nil {
1579+ s .Windows = & specs.Windows {}
1580+ }
1581+ if s .Windows .Network == nil {
1582+ s .Windows .Network = & specs.WindowsNetwork {}
1583+ }
1584+
1585+ s .Windows .Network .AllowUnqualifiedDNSQuery = true
1586+ return nil
1587+ }
1588+ }
1589+
1590+ // WithWindowsNetworkNamespace sets the network namespace for a Windows container.
1591+ func WithWindowsNetworkNamespace (ns string ) SpecOpts {
1592+ return func (_ context.Context , _ Client , _ * containers.Container , s * Spec ) error {
1593+ if s .Windows == nil {
1594+ s .Windows = & specs.Windows {}
1595+ }
1596+ if s .Windows .Network == nil {
1597+ s .Windows .Network = & specs.WindowsNetwork {}
1598+ }
1599+ s .Windows .Network .NetworkNamespace = ns
1600+ return nil
1601+ }
1602+ }
0 commit comments