Current File : //usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/microshift.cpython-312.pyc |
�
-�_g� � �8 � d dl Z d dlmZmZmZ G d� dee� Zy)� N)�Plugin�RedHatPlugin� PluginOptc � � e Zd ZdZd ZdZdZdZefZefZ dZ
ede
ed�� ed d
ed�� edd
ed
�� gZ
d� Zd� Zd� Zd� Zd� Zy)�
Microshifta: This is the plugin for MicroShift 4.X. Even though it shares some of
the OpenShift components, its IoT/Edge target makes the product nimble and
light, thus requiring different a approach when operating it.
When enabled, this plugin will collect cluster information (such as
systemd service logs, configuration, versions, etc.)and also inspect API
resources in certain namespaces. The namespaces to scan are kube.* and
openshift.*. Other namespaces may be collected by making use of the
``only-namespaces`` or ``add-namespaces`` options.
�
microshifti� )r zmicroshift-selinuxzmicroshift-networkingz2/var/lib/microshift/resources/kubeadmin/kubeconfig�
kubeconfigz+Path to a locally available kubeconfig file)�default�val_type�desc�only-namespaces� z2colon-delimited list of namespaces to collect from�add-namespaceszHcolon-delimited list of namespaces to add to the default collection listc � � | j d� r)t | j d� j d� � S ddg}| j d� r:| j d� j d� D ] }|j d|� d�� � |S )z�Combine a set of regexes for collection with any namespaces passed
to sos via the -k openshift.add-namespaces option. Note that this does
allow for end users to specify namespace regexes of their own.
r
�:z^openshift\-.+$z
^kube\-.+$r �^�$)�
get_option�list�split�append)�self�collect_regexes�nsps �?/usr/lib/python3/dist-packages/sos/report/plugins/microshift.py�_setup_namespace_regexesz#Microshift._setup_namespace_regexes, s� � �
�?�?�,�-�����(9�:�@�@��E�F�F�
��
��
�?�?�+�,����'7�8�>�>�s�C�
4���&�&�!�C�5��{�3�
4� �� c �h ��� d� �| j � �t t ��fd�|D � � � S )a Reduce the namespace listing returned to just the ones we want to
collect from. By default, as requested by OCP support personnel, this
must include all 'openshift' prefixed namespaces
:param nsps list: Namespace names from oc output
c �B � |D ] }t j || � s� y y)z�Match a particular namespace for inclusion (or not) in the
collection phases
:param namespace str: The name of a namespace
TF)�re�match)� namespace�regexes�regexs r �_match_namespacez;Microshift._reduce_namespace_list.<locals>._match_namespaceG s) � � !�
���8�8�E�9�-��
� r c 3 �6 �K � | ] } �|�� s�
|�� � y �w)N� )�.0�nr% r# s ��r � <genexpr>z4Microshift._reduce_namespace_list.<locals>.<genexpr>U s �� �� �H�a�+;�A�w�+G��H�s ��)r r �set)r �nspsr% r# s @@r �_reduce_namespace_listz!Microshift._reduce_namespace_list? s. �� �
� �/�/�1���C�H�4�H�H�I�Ir c � � | j d| j d� � �� }|d dk( r#| j |d j d� � S g S )NzRoc get namespaces -o custom-columns=NAME:.metadata.name --no-headers --kubeconfig=r �statusr �output�
)�exec_cmdr r- r )r �ress r �_get_namespaceszMicroshift._get_namespacesW s^ � ��m�m�
� "�_�_�\�:�;�
=�>��
�x�=�A���.�.�s�8�}�/B�/B�4�/H�I�I�� r c � � g d�}g }|D ]R }| j d| j d� � d|� �t j �� }|d dk( s�B|j |� �T |S )z@Get cluster-level (non-namespaced) resources to collect
)�apiservices�certificatesigningrequests�clusterrolebindings�clusterroles�componentstatuses�
csidrivers�csinodes�customresourcedefinitions�flowschemas�ingressclasses�logicalvolumes�mutatingwebhookconfigurations�nodes�persistentvolumes�priorityclasses�prioritylevelconfigurations�rangeallocations�runtimeclasses�securitycontextconstraints�selfsubjectaccessreviews�selfsubjectrulesreviews�storageclasses�subjectaccessreviews�tokenreviews�validatingwebhookconfigurations�volumeattachmentszoc get --kubeconfig r � )�timeoutr/ r )r2 r r �plugin_timeoutr )r �global_resources�_filtered_resources�resourcer3 s r �_get_cluster_resourcesz!Microshift._get_cluster_resourcesa s~ � �
��: !��(� 5�H��-�-�&�t���|�'D�&E�Q��*��"�1�1� � 3�C� �8�}��!�#�*�*�8�4�
5� #�"r c � � | j d� | j d� | j d� r| j ddg� | j dg� | j ddg� d j | j � � }d
j | j
� D �cg c] }d|� ��� c}� }| j t j � rz| j d�
� }| j d� }| j d|� d|� d
|� �dt j �� | j d|� d|� d
|� �dt j �� yyc c}w )a� The setup() phase of this plugin will first gather system
information and then iterate through all default namespaces, and/or
those specified via the `add-namespaces` and `only-namespaces` plugin
options. Both of these options accept shell-style regexes.
Output format for this function is based on `oc adm inspect` command,
which is used to retrieve all API resources from the cluster.
zmicroshift-etcd.scopez/etc/microshiftz/var/lib/microshift-backupsz%/var/lib/microshift-backups/*/versionz"/var/lib/microshift-backups/*.jsonz/var/log/kube-apiserver/*.logzmicroshift versionz#microshift show-config -m effective�,rP zns/F)�maker zoc adm inspect --kubeconfig z --dest-dir zinspect_cluster_resources.log)�suggest_filenamerQ zinspect_namespaces.logN)
�add_journal�
add_copy_spec�path_exists�add_cmd_output�joinrV r4 �is_service_runningr �plugin_name�get_cmd_output_pathr rR )r �_cluster_resources_to_collectr) �_namespaces_to_collect�_subdir�_kubeconfigs r �setupzMicroshift.setup� sw � �
���0�1����,�-����9�:���� G� D� F�
G����;�<�=���� �1�
� �
),����'�'�)�)+�%�!$��� $� 4� 4� 6�7�1�s�1�#�Y�7�"9�� �"�"�:�#9�#9�:��.�.�E�.�:�G��/�/�,�7�K����.�{�m�<��)�1�:�;�=�!@�"�1�1�
�
3�
���.�{�m�<��)�1�3�4�6�!9�"�1�1�
�
3� ;��
8s �(EN)�__name__�
__module__�__qualname__�__doc__�
short_descra rR �packages�services�profiles�localhost_kubeconfigr �str�option_listr r- r4 rV rg r'