Skip to content

Commit

Permalink
fix: remove the MustGatherContext and InsightsOperatorContext (#4330)
Browse files Browse the repository at this point in the history
These two contexts are actually used by CCX rules and redefined
in CCX Core too. They are not used in case of non-CCX scenario.
Leaving them here would cause archive context identification
error, see RHINENG-15103

And deprecate all relevant example scripts, e.g. insighst.ocp and
insights.ocpshell. From now on, the CCX Core will be the only
entry to analyze must gather and insights operator archives.

Signed-off-by: Xiangce Liu <[email protected]>
(cherry picked from commit 9e933da)
  • Loading branch information
xiangce committed Feb 6, 2025
1 parent 0e517d6 commit 1915704
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 60 deletions.
12 changes: 0 additions & 12 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ These features allow these archives to be processed quickly and more
securely in the Insights production environment. On the other hand, the
reduced data set narrows the scope of uses to be Insights-specific.

OCP 4 Archives
--------------

OCP 4 can generate diagnostic archives with a component called the
``insights-operator``. They are automatically uploaded to Red Hat for analysis.

The openshift-must-gather CLI tool produces more comprehensive archives than
the operator. ``insights-core`` recognizes them as well.

.. _openshift-must-gather: https://github.com/openshift/must-gather


Execution Model
===============

Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Contents:
combiners_index
components_index
custom_datasources_index
ocp
shell
docs_guidelines
components
Expand Down
22 changes: 0 additions & 22 deletions docs/ocp.rst

This file was deleted.

42 changes: 20 additions & 22 deletions insights/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def __init__(self, version=DEFAULT_VERSION, release=None):
self.release = release

def __bool__(self):
return all([(self.version != DEFAULT_VERSION),
bool(self.release)])
return all([(self.version != DEFAULT_VERSION), bool(self.release)])

__nonzero__ = __bool__

Expand All @@ -102,9 +101,18 @@ def __init__(self, **kwargs):
self.loaded = True
self.cmd = None
optional_attrs = [
"content", "path", "hostname", "release",
"machine_id", "target", "last_client_run", "relative_path",
"args", "engine", "image", "container_id"
"content",
"path",
"hostname",
"release",
"machine_id",
"target",
"last_client_run",
"relative_path",
"args",
"engine",
"image",
"container_id",
]
for k in optional_attrs:
setattr(self, k, kwargs.pop(k, None))
Expand Down Expand Up @@ -168,7 +176,7 @@ def handles(cls, files):
if m in f:
i = f.find(m)
if f.endswith(m) or f[i + len(m)] == sep:
root = os.path.dirname(f[:i + 1])
root = os.path.dirname(f[: i + 1])
marker_root.add(root)
if len(marker_root) == 1:
return (marker_root.pop(), cls)
Expand All @@ -182,11 +190,13 @@ def handles(cls, files):
return (None, None)

def check_output(self, cmd, timeout=None, keep_rc=False, env=None, signum=None):
""" Subclasses can override to provide special
environment setup, command prefixes, etc.
"""
return subproc.call(cmd, timeout=timeout or self.timeout, signum=signum,
keep_rc=keep_rc, env=env)
Subclasses can override to provide special
environment setup, command prefixes, etc.
"""
return subproc.call(
cmd, timeout=timeout or self.timeout, signum=signum, keep_rc=keep_rc, env=env
)

def shell_out(self, cmd, split=True, timeout=None, keep_rc=False, env=None, signum=None):
env = env or os.environ
Expand Down Expand Up @@ -265,18 +275,6 @@ def locate_path(self, path):
return super(JDRContext, self).locate_path(p)


@fs_root
class InsightsOperatorContext(ExecutionContext):
"""Recognizes insights-operator archives"""
marker = "config/featuregate"


@fs_root
class MustGatherContext(ExecutionContext):
"""Recognizes must-gather archives"""
marker = "cluster-scoped-resources"


class OpenStackContext(ExecutionContext):
def __init__(self, hostname):
super(OpenStackContext, self).__init__()
Expand Down
26 changes: 23 additions & 3 deletions insights/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
import logging
import os
import yaml
import warnings

from fnmatch import fnmatch
from insights.core.plugins import component, datasource
from insights.core.context import InsightsOperatorContext, MustGatherContext
from insights.core.context import ExecutionContext, fs_root

from insights.core.archives import extract
from insights.parsr.query import from_dict, Result
from insights.util import content_type


log = logging.getLogger(__name__)
contexts = [InsightsOperatorContext, MustGatherContext]

try:
# requires pyyaml installed after libyaml
Expand All @@ -28,6 +27,21 @@
Loader = yaml.SafeLoader


@fs_root
class InsightsOperatorContext(ExecutionContext):
"""Recognizes insights-operator archives"""
marker = "config/featuregate"


@fs_root
class MustGatherContext(ExecutionContext):
"""Recognizes must-gather archives"""
marker = "cluster-scoped-resources"


contexts = [InsightsOperatorContext, MustGatherContext]


def _get_files(path):
for root, dirs, names in os.walk(path):
for name in names:
Expand All @@ -53,6 +67,11 @@ def _process(path, excludes=None):


def analyze(paths, excludes=None):
warnings.warn(
"This '{0}' is deprecated and will be removed in {1}.".format('ocp.analyze', '3.6.0'),
DeprecationWarning,
stacklevel=2,
)
if not isinstance(paths, list):
paths = [paths]

Expand Down Expand Up @@ -85,5 +104,6 @@ def conf(root):
`tutorial`_ for details.
.. _tutorial: https://insights-core.readthedocs.io/en/latest/notebooks/Parsr%20Query%20Tutorial.html
"""
return analyze(root, excludes=["*.log"])
6 changes: 6 additions & 0 deletions insights/ocpshell.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import argparse
import logging
import warnings

from insights.ocp import analyze

Expand Down Expand Up @@ -48,6 +49,11 @@ def parse_exclude(exc):


def main():
warnings.warn(
"This '{0}' is deprecated and will be removed in {1}.".format('insights.ocpshell', '3.6.0'),
DeprecationWarning,
stacklevel=2,
)
args = parse_args()
archives = args.archives
if args.debug:
Expand Down

0 comments on commit 1915704

Please sign in to comment.