| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "github.com/carlosframework/platform/internal/cgroup" |
| 5 | "github.com/carlosframework/platform/internal/registry" |
| 6 | "github.com/carlosframework/platform/internal/release" |
| 7 | ) |
| 8 | |
| 9 | // memTier builds the exec backend's Tier seam from a manifest reader — |
| 10 | // on a box, stagedManifestOfLiveVersion, the same reader the caps pass |
| 11 | // uses, so "what does this app declare" has one answer on the box. |
| 12 | // |
| 13 | // One bit decides it: capabilities.children → the 1G tier a forking family |
| 14 | // gets on the unit path (caps/render.go); anything else → 512M, the |
| 15 | // carlos-app@ template's number. A missing or unreadable sibling is the |
| 16 | // default tier, not an error: the smaller cap is the safe direction, and |
| 17 | // the caps pass already reports the unreadable sibling in its own advice. |
| 18 | func memTier(load func(registry.Route) (*release.Manifest, error)) func(registry.Route) cgroup.Limit { |
| 19 | return func(rt registry.Route) cgroup.Limit { |
| 20 | m, err := load(rt) |
| 21 | if err != nil || m == nil || m.Capabilities == nil || !m.Capabilities.Children { |
| 22 | return cgroup.TierDefault |
| 23 | } |
| 24 | return cgroup.TierChildren |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // memTierOf is memTier for one named version: that version's staged |
| 29 | // manifest, never the live link's (zero-downtime spec §7.3: a generation's |
| 30 | // limits are its own artifact's). A staged copy is immutable once anything |
| 31 | // refers to it (plan 4), so the answer for a version does not move. |
| 32 | func memTierOf(load func(rt registry.Route, version string) (*release.Manifest, error)) func(registry.Route, string) cgroup.Limit { |
| 33 | return func(rt registry.Route, version string) cgroup.Limit { |
| 34 | return memTier(func(rt registry.Route) (*release.Manifest, error) { return load(rt, version) })(rt) |
| 35 | } |
| 36 | } |
| 37 | |