CrictlPs - command crictl ps --quiet
This parser reads the output of crictl ps --quiet command and returns a list of
container records with their associated metadata. The parser handles various container
states and time formats in the “created” field.
The parser is designed to handle the complex structure of crictl output where the “created” field may contain spaces (e.g., “About a minute ago”, “2 hours ago”) and uses intelligent parsing to correctly separate fields.
- class insights.parsers.crictl_ps.CrictlPs(context, extra_bad_lines=None)[source]
Bases:
CommandParser,listParser for the output of
crictl ps --quietcommand.The parser is designed to handle the complex structure of crictl output where the “created” field may contain spaces (e.g., “About a minute ago”, “2 hours ago”) and uses intelligent parsing to correctly separate fields.
Sample input:
CONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID POD 93b10093a8263 bea2d277eb71530a376a68be9760260cedb59f2392bb6e7793b05d5350df8d4c About a minute ago Running oauth-apiserver 185 19d971fe5c478 apiserver-7cd97c59ff-dwckz e34ce05ade472 2c96c7c72cf99490b4bdbb7389020b7e4b5bb7dc43ea9cadc4d5af43cb300b3f 9 days ago Running guard 1 c48cc19e5b0b1 etcd-guard-nah-4jnq5-master-v8z5h-0 471d75b135b5b 90e50eece96ef2a252b729a76a2ee3360d3623295cceb7d3e623b55cb7aef30a 9 days ago Running etcd 39 d2dd84f8db754 etcd-nah-4jnq5-master-v8z5h-0
The parser returns a list of dictionaries, each containing one container record with the following fields: - container_id (str): The container ID (e.g., ‘93b10093a8263’) - image (str): The container image hash or reference (e.g., ‘bea2d277eb71530a…’) - created (str): When the container was created (e.g., ‘About a minute ago’, ‘9 days ago’) - state (str): Current container state (e.g., ‘Running’, ‘Exited’, ‘ContainerCreating’, ‘Unknown’) - name (str): Container name (e.g., ‘oauth-apiserver’) - attempt (str): Container restart attempt number (e.g., ‘185’) - pod_id (str): Associated pod ID (e.g., ‘19d971fe5c478’) - pod (str): Associated pod name (e.g., ‘apiserver-7cd97c59ff-dwckz’)
Supported Container States: - Running: Container is currently running - Exited: Container has exited - Created: Container has been created but not started - ContainerCreating: Container is in the process of being created - Unknown: Container state is unknown - Pending: Container is pending (waiting for resources)
Examples
Basic usage: >>> crictl_ps = CrictlPs(context) >>> len(crictl_ps) 3 >>> crictl_ps[0][‘container_id’] ‘93b10093a8263’ >>> crictl_ps[0][‘image’] ‘bea2d277eb71530a376a68be9760260cedb59f2392bb6e7793b05d5350df8d4c’ >>> crictl_ps[0][‘created’] ‘About a minute ago’ >>> crictl_ps[0][‘state’] ‘Running’ >>> crictl_ps[0][‘name’] ‘oauth-apiserver’ >>> crictl_ps[0][‘attempt’] ‘185’ >>> crictl_ps[0][‘pod_id’] ‘19d971fe5c478’ >>> crictl_ps[0][‘pod’] ‘apiserver-7cd97c59ff-dwckz’
- Raises:
ParseException -- If the input content is invalid or doesn’t contain the expected header line with “CONTAINER” keyword.
SkipComponent -- If no container records are found after parsing.
- parse_content(content)[source]
Parse the crictl ps output content.
- Parameters:
content (list) -- List of strings representing the crictl ps output lines.
- Raises:
ParseException -- If the content is invalid or doesn’t contain the expected header.
SkipComponent -- If no container records are found after parsing.