o id@s2ddlmZmZmZddlZGdddeeZdS))Plugin RedHatPlugin PluginOptNc@seZdZdZdZdZdZdZedddfZefZ dZ e d e e d d e d d e dd e dd e dd gZ ddZddZddZddZddZdS) 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)rzmicroshift-selinuxzmicroshift-networkingzmicroshift-greenbootzgreenboot-healthcheckzgreenboot-task-runnerzredboot-task-runnerz2/var/lib/microshift/resources/kubeadmin/kubeconfig kubeconfigz+Path to a locally available kubeconfig file)defaultval_typedesconly-namespacesz2colon-delimited list of namespaces to collect fromadd-namespaceszHcolon-delimited list of namespaces to add to the default collection listcCs^|drdd|ddDSddg}|dr-|ddD] }|d|q#|S) zCombine 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 cSsg|]}|qSr.0nrr?/usr/lib/python3/dist-packages/sos/report/plugins/microshift.py 4sz7Microshift._setup_namespace_regexes..:z^openshift\-.+$z ^kube\-.+$r z^%s$) get_optionsplitappend)selfcollect_regexesnsprrr_setup_namespace_regexes.s  z#Microshift._setup_namespace_regexescs0fdd_ttfdd|DS)aReduce 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 cs"jD] }t||rdSqdS)zMatch a particular namespace for inclusion (or not) in the collection phases :param namespace str: The name of a namespace TF)rrematch) namespaceregex)rrr_match_namespaceIs  z;Microshift._reduce_namespace_list.._match_namespacecsg|]}|r|qSrrr)r rrrWsz5Microshift._reduce_namespace_list..)rrlistset)rnspsr)r rr_reduce_namespace_listAs  z!Microshift._reduce_namespace_listcCs8|d|d}|ddkr||ddSgS)NzToc get namespaces -o custom-columns=NAME:.metadata.name --no-headers --kubeconfig=%srstatusroutput )exec_cmdrr$r)rresrrr_get_namespacesYs zMicroshift._get_namespacescCsNgd}g}|D]}|jd|d|ftjd}|ddkr$||q|S)z@Get cluster-level (non-namespaced) resources to collect ) apiservicescertificatesigningrequestsclusterrolebindings clusterrolescomponentstatuses csidriverscsinodescustomresourcedefinitions flowschemasingressclasseslogicalvolumesmutatingwebhookconfigurationsnodespersistentvolumespriorityclassesprioritylevelconfigurationsrangeallocationsruntimeclassessecuritycontextconstraintsselfsubjectaccessreviewsselfsubjectrulesreviewsstorageclassessubjectaccessreviews tokenreviewsvalidatingwebhookconfigurationsvolumeattachmentszoc get --kubeconfig %s %sr)timeoutr%r)r(rrplugin_timeoutr)rglobal_resources_filtered_resourcesresourcer)rrr_get_cluster_resourcescs   z!Microshift._get_cluster_resourcescCs|dr |ddg|ddgd|}ddd |D}|tjrU|j d d }| d }|jd |||fdtj d|jd |||fdtj ddSdS)aThe 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. z/var/lib/microshift-backupsz%/var/lib/microshift-backups/*/versionz"/var/lib/microshift-backups/*.jsonzmicroshift versionz#microshift show-config -m effective, cSsg|]}d|qS)zns/%srrrrrrsz$Microshift.setup..F)makerz/oc adm inspect --kubeconfig %s --dest-dir %s %szinspect_cluster_resources.log)suggest_filenamerEzinspect_namespaces.logN) path_exists add_copy_specadd_cmd_outputjoinrJr*is_service_runningr plugin_nameget_cmd_output_pathrrF)r_cluster_resources_to_collect_namespaces_to_collect_subdir _kubeconfigrrrsetups@     zMicroshift.setupN)__name__ __module__ __qualname____doc__ short_descrTrFpackagesservicesprofileslocalhost_kubeconfigrstr option_listrr$r*rJrZrrrrrs4   +r)sos.report.pluginsrrrrrrrrrs