Skip to content

Commit 7114b01

Browse files
authored
Merge pull request #1339 from kernelkit/container-operational
cli: use operational data in `show container [name]`
2 parents 97f4638 + 1030bae commit 7114b01

File tree

11 files changed

+817
-264
lines changed

11 files changed

+817
-264
lines changed

board/common/rootfs/etc/fstab

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
# Virtual filesystems
2-
devtmpfs /dev devtmpfs defaults 0 0
3-
mkdir#-p /dev/pts helper none 0 0
4-
devpts /dev/pts devpts mode=620,ptmxmode=0666 0 0
5-
mkdir#-p /dev/shm helper none 0 0
6-
tmpfs /dev/shm tmpfs mode=0777 0 0
7-
proc /proc proc defaults 0 0
8-
tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0
9-
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
10-
tmpfs /media tmpfs mode=1755,nosuid,nodev 0 0
11-
sysfs /sys sysfs defaults 0 0
12-
debugfs /sys/kernel/debug debugfs nofail 0 0
13-
cfgfs /config configfs nofail,noauto 0 0
2+
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
3+
tmpfs /media tmpfs mode=1755,nosuid,nodev 0 0
4+
debugfs /sys/kernel/debug debugfs nofail 0 0
5+
cfgfs /config configfs nofail,noauto 0 0
146

157
# The chosen backing storage for the overlays placed on /cfg, /etc,
168
# /home, /root, and /var, are determined dynamically by /usr/libexec/infix/mnt

doc/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ All notable changes to the project are documented in this file.
1717
can now be enabled per category (bfd, packet, ism, nsm, default-information,
1818
nssa). All debug options are disabled by default to prevent log flooding in
1919
production environments. See the documentation for usage examples
20+
- Add support for configurable container resource limits, memory and CPU.
21+
Resource usage is available through the operational datastore, where the
22+
currently active resource limits in the container runtime are also available
2023
- Add support for "routing interfaces", issue #647. Lists interfaces with IP
2124
forwarding. Inspect from CLI using `show interface`, look for `` flag
2225
- Add operational data journal to statd with hierarchical time-based retention
2326
policy, keeping snapshots from every 5 minutes (recent) to yearly (historical)
27+
- Add support data collection script, useful when troubleshooting issues on
28+
deployed systems. Gathers system information, logs, and more. Issue #1287
2429

2530
### Fixes
2631

doc/container.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,46 @@ time and analysis of your container application to figure out which
488488
capabilities you need.
489489

490490

491+
Resource Limits
492+
---------------
493+
494+
Containers can be configured with resource limits to control their memory
495+
and CPU usage. This helps prevent containers from consuming excessive system
496+
resources and ensures fair resource allocation across multiple containers.
497+
498+
### Configuring Resource Limits
499+
500+
Resource limits are set per container and include:
501+
502+
- **Memory:** Maximum memory usage in kibibytes (KiB)
503+
- **CPU:** Maximum CPU usage in millicores (1000 millicores = 1 CPU core)
504+
505+
Example configuration limiting a container to 512 MiB of memory and 1.5 CPU cores:
506+
507+
admin@example:/> configure
508+
admin@example:/config/> edit container web
509+
admin@example:/config/container/web/> edit resource-limit
510+
admin@example:/config/container/web/resource-limit/> set memory 524288
511+
admin@example:/config/container/web/resource-limit/> set cpu 1500
512+
admin@example:/config/container/web/resource-limit/> leave
513+
514+
Common CPU limit examples:
515+
516+
- `500` = 0.5 cores (50% of one core)
517+
- `1000` = 1.0 cores (one full core)
518+
- `2000` = 2.0 cores (two full cores)
519+
520+
### Monitoring Resource Usage
521+
522+
Runtime resource usage statistics are available in the operational datastore:
523+
524+
admin@example:/> show container web
525+
...
526+
527+
Use `show container usage` to see resource consumption across all containers,
528+
including memory, CPU, block I/O, network I/O, and process counts.
529+
530+
491531
Networking and Containers
492532
-------------------------
493533

package/finit/finit.hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# From https://github.com/troglobit/finit/releases/
2-
sha256 7ccbcead4e3e6734c81a8c5445f4a27738f19a4ab367d702513a201db9b618c7 finit-4.15-rc1.tar.gz
2+
sha256 0e4774ccb8933ed92287e6c18d27cb463222dcc1f50a3607e27bbe5fd150ece0 finit-4.15.tar.gz
33

44
# Locally calculated
55
sha256 868cb6c5414933a48db11186042cfe65c87480d326734bc6cf0e4b19b4a2e52a LICENSE

package/finit/finit.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
################################################################################
66

7-
FINIT_VERSION = 4.15-rc1
7+
FINIT_VERSION = 4.15
88
FINIT_SITE = https://github.com/troglobit/finit/releases/download/$(FINIT_VERSION)
99
FINIT_LICENSE = MIT
1010
FINIT_LICENSE_FILES = LICENSE

src/klish-plugin-infix/xml/containers.xml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,11 @@
186186
</COMMAND>
187187

188188
<COMMAND name="show" help="Show system status and configuration files" mode="switch">
189-
<COMMAND name="container" help="Show container status">
190-
<ACTION sym="script" in="tty" out="tty" interrupt="true">
191-
doas container show |pager
192-
</ACTION>
193189

194-
<SWITCH name="optional" min="0">
190+
<COMMAND name="container" help="Show container status">
191+
<SWITCH name="subcommands" min="0">
195192
<COMMAND name="all" help="Show all containers (default only running)">
196-
<ACTION sym="script">doas container -a show</ACTION>
193+
<ACTION sym="script">show container</ACTION>
197194
</COMMAND>
198195
<COMMAND name="log" help="Show container log (jumps to end), alias to 'show log container'">
199196
<ACTION sym="script" in="tty" out="tty" interrupt="true">
@@ -231,7 +228,15 @@
231228
</ACTION>
232229
</COMMAND>
233230
</SWITCH>
231+
232+
<SWITCH name="optional" min="0" max="1">
233+
<PARAM name="name" ptype="/CONTAINERS" help="Container name for detailed view" />
234+
</SWITCH>
235+
<ACTION sym="script" in="tty" out="tty" interrupt="true">
236+
show container $KLISH_PARAM_name |pager
237+
</ACTION>
234238
</COMMAND>
239+
235240
</COMMAND>
236241

237242
</VIEW>

src/klish-plugin-infix/xml/infix.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,18 @@
638638
<COMMAND name="firewall" help="Show firewall status and configuration">
639639
<SWITCH name="optional" min="0" max="1">
640640
<COMMAND name="log" help="Show firewall log (jumps to end), alias to 'show log firewall.log'">
641+
<SWITCH name="optional" min="0">
642+
<PARAM name="limit" ptype="/UINT" help="Last N lines, default: all"/>
643+
</SWITCH>
641644
<ACTION sym="script" in="tty" out="tty" interrupt="true">
642-
doas -u $USER cat /log/firewall.log |pager +G
645+
sysrepocfg -X -d operational -x /infix-firewall:firewall -f json -t 60 | /usr/libexec/statd/cli-pretty show-firewall-log $KLISH_PARAM_limit |pager +G
643646
</ACTION>
644647
</COMMAND>
648+
<COMMAND name="matrix" help="Show firewall zone matrix">
649+
<ACTION sym="script" in="tty" out="tty" interrupt="true">
650+
sysrepocfg -X -d operational -x /infix-firewall:firewall -f json -t 60 | /usr/libexec/statd/cli-pretty show-firewall-matrix
651+
</ACTION>
652+
</COMMAND>
645653
<COMMAND name="zone" help="Show firewall zones">
646654
<SWITCH name="optional" min="0">
647655
<PARAM name="name" ptype="/FIREWALL_ZONES" help="Zone name"/>

src/show/show.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,64 @@ def services(args: List[str]) -> None:
173173

174174
cli_pretty(data, f"show-services")
175175

176+
def container(args: List[str]) -> None:
177+
"""Handle show container [name]
178+
179+
Arguments:
180+
(none) - Show all containers in table format
181+
name - Show detailed view of specific container
182+
"""
183+
data = run_sysrepocfg("/infix-containers:containers")
184+
if not data:
185+
print("No container data retrieved.")
186+
return
187+
188+
# Fetch interface data for bridge resolution (both table and detailed views)
189+
# Fetch operational interface data
190+
iface_oper = run_sysrepocfg("/ietf-interfaces:interfaces")
191+
192+
# Also fetch config data for veth peer information (not in operational)
193+
try:
194+
result = subprocess.run([
195+
"sysrepocfg", "-f", "json", "-X", "-d", "running", "-x", "/ietf-interfaces:interfaces"
196+
], capture_output=True, text=True, check=True)
197+
iface_config = json.loads(result.stdout)
198+
199+
# Merge config veth peer info into operational data
200+
if iface_oper and iface_config:
201+
oper_ifaces = iface_oper.get('ietf-interfaces:interfaces', {}).get('interface', [])
202+
config_ifaces = iface_config.get('ietf-interfaces:interfaces', {}).get('interface', [])
203+
204+
# Create a map of config interfaces
205+
config_map = {iface['name']: iface for iface in config_ifaces}
206+
207+
# Merge veth peer info from config into operational
208+
for oper_iface in oper_ifaces:
209+
name = oper_iface.get('name')
210+
if name in config_map:
211+
config_iface = config_map[name]
212+
# Add veth peer if it exists in config but not in operational
213+
if 'infix-interfaces:veth' in config_iface and 'infix-interfaces:veth' not in oper_iface:
214+
oper_iface['infix-interfaces:veth'] = config_iface['infix-interfaces:veth']
215+
216+
data.update(iface_oper)
217+
except (subprocess.CalledProcessError, json.JSONDecodeError):
218+
# If config fetch fails, just use operational data
219+
if iface_oper:
220+
data.update(iface_oper)
221+
222+
if RAW_OUTPUT:
223+
print(json.dumps(data, indent=2))
224+
return
225+
226+
if len(args) == 0 or not args[0]:
227+
cli_pretty(data, "show-container")
228+
elif len(args) == 1:
229+
name = args[0]
230+
cli_pretty(data, "show-container-detail", name)
231+
else:
232+
print("Too many arguments provided. Expected: show container [name]")
233+
176234
def bfd(args: List[str]) -> None:
177235
"""Handle show bfd [subcommand] [peer] [brief]
178236
@@ -486,6 +544,7 @@ def execute_command(command: str, args: List[str]):
486544
command_mapping = {
487545
'bfd': bfd,
488546
'boot-order': boot_order,
547+
'container': container,
489548
'dhcp': dhcp,
490549
'hardware': hardware,
491550
'interface': interface,

0 commit comments

Comments
 (0)