ocp.krkn_openshift module
- class ocp.krkn_openshift.KrknOpenshift(kubeconfig_path: str | None = None)
Bases:
KrknKubernetes
- __init__(kubeconfig_path: str | None = None)
KrknKubernetes Constructor. Can be invoked with kubeconfig_path or, optionally, with a kubeconfig in string format using the keyword argument
- Parameters:
kubeconfig_path – kubeconfig path
- Param:
request_chunk_size: int of chunk size to limit requests to
Initialization with kubeconfig path:
>>> KrknKubernetes(log_writer, "/home/test/.kube/config")
- collect_filter_archive_ocp_logs(src_dir: str, dst_dir: str, kubeconfig_path: str, start_timestamp: int | None, end_timestamp: int | None, log_filter_patterns: list[str], threads: int, safe_logger: SafeLogger, namespace: str | None = None, oc_path: str | None = None) str
Collects, filters and finally creates a tar.gz archive containing the filtered logs matching the criteria passed as parameters. The logs are used leveraging the oc CLI with must-gather option (oc adm must-gather)
- Parameters:
src_dir – the folder containing the files to be filtered
dst_dir – the folder where the filtered logs will be written
kubeconfig_path – path of the kubeconfig file used by the oc CLI to gather the log files from the cluster
start_timestamp – timestamp of the first relevant entry, if None will start from the beginning
end_timestamp – timestamp of the last relevant entry, if None will be collected until the latest
threads – the number of threads that will do the job
log_filter_patterns – a list of regex that will match and extract the time info that will be parsed by dateutil.parser (it supports several formats by default but not every date format)
safe_logger – thread safe logger used to log the output on a file stream
namespace – if set the logs will refer only to the provided namespace
oc_path – the path of the oc CLI, if None will be searched in the PATH
- Returns:
the path of the archive containing the filtered logs
- filter_must_gather_ocp_log_folder(src_dir: str, dst_dir: str, start_timestamp: int | None, end_timestamp: int | None, log_files_extension: str, threads: int, log_filter_patterns: list[str])
Filters a folder containing logs collected by the oc adm must-gather command (usually logs) with a given extension. The time info is extracted matching each line against the patterns passed as parameters and within the time range between start_timestamp and end_timestamp. if start and end timestamp are None the bottom and top time limit will be removed respectively. The filtering is multithreaded. The timezone of the client and the cluster will be applied to the filter and the records. If a file does not contain relevant rows in the time range won’t be written in the dst_dir The output of the filter will be the original file name with all the folder structure (base folder not included) added as a prefix and separated by a dot, eg. src_dir: /tmp/folder dst_dir: /tmp/filtered log_file: /tmp/folder/namespaces/openshift-monitoring/pods/prometheus-k8s-0/logs/current.log # NOQA output: /tmp/filtered/namespaces.openshift-monitoring.pods.prometheus-k8s-0.logs.current.log # NOQA
- Parameters:
src_dir – the folder containing the files to be filtered
dst_dir – the folder where the filtered logs will be written
start_timestamp – timestamp of the first relevant entry, if None will start from the beginning
end_timestamp – timestamp of the last relevant entry, if None will be collected until the latest
log_files_extension – the extension of the files that will be filtered using wildcards (* will consider all the files, log_file_name.log will consider only this file)
threads – the number of threads that will do the job
log_filter_patterns – a list of regex that will match and extract the time info that will be parsed by dateutil.parser (it supports several formats by default but not every date format). Each pattern must contain only 1 group that represent the time string that must be extracted and parsed
- get_cloud_infrastructure() str
Get the cluster Cloud infrastructure name when available
- Returns:
the cluster infrastructure name or Unknown when unavailable
- get_cluster_network_plugins() list[str]
Get the cluster Cloud network plugins list
- Returns:
the cluster infrastructure name or Unknown when unavailable
- get_cluster_type() str
Get the cluster Cloud infrastructure type when available status:
- platformStatus:
aws: region: us-west-2 resourceTags: - key: prowci
value: ci-rosa-**
- key: red-hat-clustertype
value: rosa
- key: red-hat-managed
value: “true”
type: AWS
- Returns:
the cluster type (ex. rosa) or self-managed when unavailable
- get_clusterversion_string() str
Return clusterversion status text on OpenShift, empty string on other distributions
- Returns:
clusterversion status
- get_prometheus_api_connection_data(namespace: str = 'openshift-monitoring') PrometheusConnectionData | None
- is_openshift() bool
Checks if is an openshift cluster :return: true if it’s openshift, false if not