From 47d0d5012fb0dadb6197073c32f338777042233e Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 23 Sep 2024 13:38:06 +0000 Subject: [PATCH 1/2] core: Drop OS RHEL 7 based support --- .devcontainer/Dockerfile | 4 +- .github/workflows/build.yaml | 2 +- .github/workflows/nightly.yaml | 1 - .pre-commit-config.yaml | 16 +----- CHANGELOG.md | 5 ++ buildchain/buildchain/builder.py | 14 ----- buildchain/buildchain/packaging.py | 51 +----------------- buildchain/buildchain/versions.py | 16 +----- docs/installation/setup.rst | 44 +++------------ packages/common/metalk8s-sosreport/.pylintrc | 4 -- .../common/metalk8s-sosreport/metalk8s.py | 31 ++++------- .../metalk8s-sosreport/metalk8s_containerd.py | 23 +++----- packages/redhat/7/Dockerfile | 51 ------------------ packages/redhat/common/60-containerd.conf | 9 ---- packages/redhat/common/containerd.spec | 29 +++------- .../redhat/common/metalk8s-sosreport.spec | 26 --------- .../metalk8s/kubernetes/kubelet/installed.sls | 12 ----- salt/metalk8s/kubernetes/kubelet/running.sls | 2 - salt/metalk8s/map.jinja | 53 ------------------- salt/tests/unit/formulas/config.py | 2 +- salt/tests/unit/formulas/config.yaml | 16 +++--- .../tests/unit/formulas/data/base_grains.yaml | 19 ++++--- .../unit/formulas/data/kubernetes/base.yaml | 4 +- salt/tests/unit/formulas/fixtures/data.py | 2 +- .../test_metalk8s_package_manager_yum.yaml | 10 ++-- 25 files changed, 68 insertions(+), 378 deletions(-) delete mode 100644 packages/redhat/7/Dockerfile delete mode 100644 packages/redhat/common/60-containerd.conf diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index ae4453dbe1..a1fb0e05d7 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -65,8 +65,8 @@ RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \ export PATH="$HOME/.pyenv/bin:$PATH" && eval "$(pyenv init -)" # Install pythons -RUN ~/.pyenv/bin/pyenv install 3.10.12 3.6.15 2.7 && \ - ~/.pyenv/bin/pyenv global 3.10.12 3.6.15 2.7 +RUN ~/.pyenv/bin/pyenv install 3.10.12 3.6.15 && \ + ~/.pyenv/bin/pyenv global 3.10.12 3.6.15 # Install python libs RUN ~/.pyenv/bin/pyenv exec pip install "tox~=4.4.12" "pre-commit~=3.3.3" "virtualenv<20.22.0" "esbonio>=0.12.0" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0740c90322..7eb701097f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -208,7 +208,7 @@ jobs: run: | export DEBIAN_FRONTEND=noninteractive sudo apt-get update - sudo apt-get install --no-install-recommends -y shellcheck python2.7-minimal + sudo apt-get install --no-install-recommends -y shellcheck python3.10 -m pip install tox~=4.0.11 - name: Install Helm env: diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index cc03280480..e1e4d4ff28 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -179,7 +179,6 @@ jobs: fail-fast: false matrix: os: - - centos-7 - rhel-8 # NOTE: We add rocky-8 here even if it's already tested in pre-merge since # we also test solution install + upgrade there diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 696dd40c56..26f729ccf4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,21 +63,7 @@ repos: files: ^packages/common/metalk8s-sosreport/.*\.py$ additional_dependencies: - requests - args: - - --rcfile=packages/common/metalk8s-sosreport/.pylintrc - - # Python 2.7 specific - - repo: https://github.com/pre-commit/mirrors-pylint - # NOTE: Newer version does no longer support python2.7 - rev: v1.9.1 - hooks: - - id: pylint - name: Lint sos report plugin (python2.7) - language_version: python2.7 - # Linting for sos report plugin files only - files: ^packages/common/metalk8s-sosreport/.*\.py$ - additional_dependencies: - - requests + - git+https://github.com/sosreport/sos@4.7.2 args: - --rcfile=packages/common/metalk8s-sosreport/.pylintrc diff --git a/CHANGELOG.md b/CHANGELOG.md index e309d166ad..b9ac2252b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Release 129.0.0 (in development) +### Removals + +- Drop RHEL 7 based OS support + (PR[#4430](https://github.com/scality/metalk8s/pull/4430)) + ### Enhancements - Implement super-admin user and bind admin to built-in cluster-admins role diff --git a/buildchain/buildchain/builder.py b/buildchain/buildchain/builder.py index 3f4caf9b9b..a63e30d9b3 100644 --- a/buildchain/buildchain/builder.py +++ b/buildchain/buildchain/builder.py @@ -46,20 +46,6 @@ def _builder_image(name: str, dockerfile: Path, **kwargs: Any) -> LocalImage: REDHAT_REPOS_ROOT: Path = constants.ROOT / "packages/redhat/common/yum_repositories" RPM_BUILDER: Dict[str, LocalImage] = { - "7": _builder_image( - name="redhat-7-rpm", - dockerfile=constants.ROOT / "packages/redhat/7/Dockerfile", - build_context=constants.ROOT / "packages/redhat", - file_dep=[ - REDHAT_REPOS_ROOT / "kubernetes.repo", - REDHAT_REPOS_ROOT / "saltstack.repo", - ], - build_args={ - # Used to template the repository definition - "SALT_VERSION": versions.SALT_VERSION, - "K8S_SHORT_VERSION": versions.K8S_SHORT_VERSION, - }, - ), "8": _builder_image( name="redhat-8-rpm", dockerfile=constants.ROOT / "packages/redhat/8/Dockerfile", diff --git a/buildchain/buildchain/packaging.py b/buildchain/buildchain/packaging.py index dbdadc2236..e8acb09189 100644 --- a/buildchain/buildchain/packaging.py +++ b/buildchain/buildchain/packaging.py @@ -9,7 +9,7 @@ - building local packages from sources - building local repositories from local packages -Note that for now, it only works for CentOS/RedHat 7 and 8 x86_64. +Note that for now, it only works for CentOS/RedHat 8 x86_64. Overview; @@ -89,7 +89,6 @@ def task__build_packages() -> types.TaskDict: return { "actions": None, "task_dep": [ - "_build_redhat_7_packages", "_build_redhat_8_packages", ], } @@ -100,7 +99,6 @@ def task__download_packages() -> types.TaskDict: return { "actions": None, "task_dep": [ - "_download_redhat_7_packages", "_download_redhat_8_packages", ], } @@ -111,7 +109,6 @@ def task__build_repositories() -> types.TaskDict: return { "actions": None, "task_dep": [ - "_build_redhat_7_repositories", "_build_redhat_8_repositories", ], } @@ -138,11 +135,6 @@ def _package_mkdir_redhat_release_root(releasever: str) -> types.TaskDict: ).task -def task__package_mkdir_redhat_7_root() -> types.TaskDict: - """Create the RedHat 7 packages root directory.""" - return _package_mkdir_redhat_release_root("7") - - def task__package_mkdir_redhat_8_root() -> types.TaskDict: """Create the RedHat 8 packages root directory.""" return _package_mkdir_redhat_release_root("8") @@ -173,11 +165,6 @@ def _package_mkdir_redhat_release_iso_root(releasever: str) -> types.TaskDict: ).task -def task__package_mkdir_redhat_7_iso_root() -> types.TaskDict: - """Create the RedHat 7 packages root directory on the ISO.""" - return _package_mkdir_redhat_release_iso_root("7") - - def task__package_mkdir_redhat_8_iso_root() -> types.TaskDict: """Create the RedHat 8 packages root directory on the ISO.""" return _package_mkdir_redhat_release_iso_root("8") @@ -245,11 +232,6 @@ def _dl_packages_callable() -> None: } -def task__download_redhat_7_packages() -> types.TaskDict: - """Download RedHat 7 packages locally.""" - return _download_rpm_packages("7") - - def task__download_redhat_8_packages() -> types.TaskDict: """Download RedHat 8 packages locally.""" return _download_rpm_packages("8") @@ -262,11 +244,6 @@ def _build_rpm_packages(releasever: str) -> Iterator[types.TaskDict]: yield from package.execution_plan -def task__build_redhat_7_packages() -> Iterator[types.TaskDict]: - """Build RPM packages for RedHat 7.""" - return _build_rpm_packages("7") - - def task__build_redhat_8_packages() -> Iterator[types.TaskDict]: """Build RPM packages for RedHat 8.""" return _build_rpm_packages("8") @@ -278,11 +255,6 @@ def _build_redhat_repositories(releasever: str) -> Iterator[types.TaskDict]: yield from repository.execution_plan -def task__build_redhat_7_repositories() -> Iterator[types.TaskDict]: - """Build RedHat 7 repositories.""" - return _build_redhat_repositories("7") - - def task__build_redhat_8_repositories() -> Iterator[types.TaskDict]: """Build RedHat 8 repositories.""" return _build_redhat_repositories("8") @@ -341,11 +313,6 @@ def _rpm_repository( def _rpm_package_containerd(releasever: str) -> targets.RPMPackage: """Containerd RPM package.""" - extra_sources = [] - - if releasever == "7": - extra_sources.append(Path("60-containerd.conf")) - return _rpm_package( name="containerd", releasever=releasever, @@ -354,8 +321,7 @@ def _rpm_package_containerd(releasever: str) -> targets.RPMPackage: Path("containerd.service"), Path("containerd.toml"), Path(f"v{versions.CONTAINERD_VERSION}.tar.gz"), - ] - + extra_sources, + ], ) @@ -373,10 +339,6 @@ def _rpm_package_metalk8s_sosreport(releasever: str) -> targets.RPMPackage: RPM_TO_BUILD: Dict[str, Dict[str, Tuple[targets.RPMPackage, ...]]] = { "scality": { - "7": ( - _rpm_package_containerd("7"), - _rpm_package_metalk8s_sosreport("7"), - ), "8": ( _rpm_package_containerd("8"), _rpm_package_metalk8s_sosreport("8"), @@ -408,21 +370,12 @@ def _rpm_package_metalk8s_sosreport(releasever: str) -> targets.RPMPackage: ) -SCALITY_REDHAT_7_REPOSITORY: targets.RPMRepository = _rpm_repository( - name="scality", packages=RPM_TO_BUILD["scality"]["7"], releasever="7" -) SCALITY_REDHAT_8_REPOSITORY: targets.RPMRepository = _rpm_repository( name="scality", packages=RPM_TO_BUILD["scality"]["8"], releasever="8" ) REDHAT_REPOSITORIES: Dict[str, Tuple[targets.RPMRepository, ...]] = { - "7": ( - SCALITY_REDHAT_7_REPOSITORY, - _rpm_repository(name="epel", releasever="7"), - _rpm_repository(name="kubernetes", releasever="7"), - _rpm_repository(name="saltstack", releasever="7"), - ), "8": ( SCALITY_REDHAT_8_REPOSITORY, _rpm_repository(name="epel", releasever="8"), diff --git a/buildchain/buildchain/versions.py b/buildchain/buildchain/versions.py index d4ada4d3f4..b47c80bb66 100644 --- a/buildchain/buildchain/versions.py +++ b/buildchain/buildchain/versions.py @@ -29,7 +29,7 @@ SALT_VERSION: str = "3002.9" CONTAINERD_VERSION: str = "1.6.35" -CONTAINERD_RELEASE: str = "1" +CONTAINERD_RELEASE: str = "2" SOSREPORT_RELEASE: str = "2" @@ -380,20 +380,6 @@ def rpm_full_name(self) -> str: PackageVersion(name="xfsprogs"), ), "redhat": { - "7": ( - PackageVersion( - name="containerd", - version=CONTAINERD_VERSION, - release=f"{CONTAINERD_RELEASE}.el7", - ), - PackageVersion(name="container-selinux"), # TODO #1710 - PackageVersion( - name="metalk8s-sosreport", - version=NONSUFFIXED_VERSION, - release=f"{SOSREPORT_RELEASE}.el7", - ), - PackageVersion(name="yum-plugin-versionlock"), - ), "8": ( PackageVersion( name="containerd", diff --git a/docs/installation/setup.rst b/docs/installation/setup.rst index 9358c8e7f3..7543e09eaf 100644 --- a/docs/installation/setup.rst +++ b/docs/installation/setup.rst @@ -4,6 +4,7 @@ Prerequisites .. _MetalK8s: https://github.com/scality/metalk8s .. _CentOS: https://www.centos.org .. _RHEL: https://access.redhat.com/products/red-hat-enterprise-linux +.. _Rocky: https://rockylinux.org .. _RHSM register: https://access.redhat.com/solutions/253273 .. _Enable Optional repositories with RHSM: https://access.redhat.com/solutions/392003 .. _Configure repositories with YUM: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sec-configuring_yum_and_yum_repositories#sec-Managing_Yum_Repositories @@ -11,7 +12,7 @@ Prerequisites .. _SaltStack: https://www.saltstack.com .. _Puppet: https://puppet.com -MetalK8s_ clusters require machines running CentOS_\/RHEL_ 7.6 or higher as +MetalK8s_ clusters require machines running CentOS_\/RHEL_/Rocky_ 8 as their operating system. These machines may be virtual or physical, with no difference in setup procedure. The number of machines to set up depends on the architecture you chose in :ref:`installation-intro-architecture`. @@ -28,29 +29,6 @@ Proxies For nodes operating behind a proxy, see :ref:`Bootstrap Configuration`. -Linux Kernel Version --------------------- - -Linux kernels shipped with CentOS/RHEL 7 and earlier are affected by a -cgroups memory leak bug. - -This bug was fixed in kernel 3.10.0-1062.4.1. Use this kernel version or later. - -The version can be retrieved using: - - .. code-block:: shell - - $ uname -r - -If the installed version is lower than the one above, upgrade it with: - - .. code-block:: shell - - $ yum upgrade -y kernel-3.10.0-1062.4.1.el7 - $ reboot - -These commands may require sudo or root access. - Provisioning ------------ @@ -79,17 +57,11 @@ Repositories Each machine must have properly configured repositories with access to basic repository packages (depending on the operating system). -CentOS: +CentOS/Rocky: - - base + - appstream + - baseos - extras - - updates - -RHEL 7: - - - rhel-7-server-rpms - - rhel-7-server-extras-rpms - - rhel-7-server-optional-rpms RHEL 8: @@ -107,11 +79,11 @@ RHEL 8: To enable an existing repository: - CentOS: + CentOS/Rocky: .. code-block:: shell - yum-config-manager --enable + dnf config-manager --enable RHEL: @@ -123,7 +95,7 @@ To add a new repository: .. code-block:: shell - yum-config-manager --add-repo + dnf config-manager --add-repo .. note:: diff --git a/packages/common/metalk8s-sosreport/.pylintrc b/packages/common/metalk8s-sosreport/.pylintrc index b5bd86d1aa..d3233d6d11 100644 --- a/packages/common/metalk8s-sosreport/.pylintrc +++ b/packages/common/metalk8s-sosreport/.pylintrc @@ -5,7 +5,3 @@ disable=duplicate-code, bad-continuation, consider-using-f-string, unspecified-encoding - -[3RD-PARTY-IMPORTS] - -allowed-3rd-party-modules=sos diff --git a/packages/common/metalk8s-sosreport/metalk8s.py b/packages/common/metalk8s-sosreport/metalk8s.py index ad53d99a31..de55a5adc7 100644 --- a/packages/common/metalk8s-sosreport/metalk8s.py +++ b/packages/common/metalk8s-sosreport/metalk8s.py @@ -3,9 +3,8 @@ There is some flags to enable/disable some specific data collection like Kubernetes resources and Pod logs. -NOTE: This plugin is used on different OS including CentOs 7 and Rocky 8 -which mean it need to work with both sos 3.x and sos 4.x and also with -Python 2.7 and Python 3.6. +NOTE: This plugin is used only on RedHat 8 based OS which mean it need to work +with sos 4.x and also with Python 3.6. """ import contextlib @@ -14,22 +13,16 @@ import requests -HAS_PLUGIN_OPT = False +from sos.report.plugins import Plugin, RedHatPlugin -# sos plugin layout changed in sos 4.0 +# PluginOpt get added in sos 4.3 and must be used instead of +# simple tuple starting from there try: - from sos.report.plugins import Plugin, RedHatPlugin + from sos.report.plugins import PluginOpt - # PluginOpt get added in sos 4.3 and must be used instead of - # simple tuple starting from there - try: - from sos.report.plugins import PluginOpt - - HAS_PLUGIN_OPT = True - except ImportError: - pass + HAS_PLUGIN_OPT = True except ImportError: - from sos.plugins import Plugin, RedHatPlugin + HAS_PLUGIN_OPT = False class MetalK8s(Plugin, RedHatPlugin): @@ -115,9 +108,7 @@ def _custom_collection_file(self, fname, subdir=None): root_dir = self.get_cmd_output_path(make=False) dir_name = os.path.join(root_dir, subdir) - if not os.path.exists(dir_name): - # NOTE: We cannot use `exist_ok=True` since it's not available in Python 2.7 - os.makedirs(dir_name) + os.makedirs(dir_name, exist_ok=True) # We truncate the filename to 255 characters since it's the max full_path = os.path.join(dir_name, fname[:255]) @@ -157,9 +148,7 @@ def _add_symlink(relative_dest, src_path, dest_name): dest_dir = os.path.join(root_dir, relative_dest) dest = os.path.join(dest_dir, dest_name) - if not os.path.exists(dest_dir): - # NOTE: We cannot use `exist_ok=True` since it's not available in Python 2.7 - os.makedirs(dest_dir) + os.makedirs(dest_dir, exist_ok=True) if os.path.lexists(dest): # NOTE: If symlink already exists it means we have 2 objects with diff --git a/packages/common/metalk8s-sosreport/metalk8s_containerd.py b/packages/common/metalk8s-sosreport/metalk8s_containerd.py index 888feaa0e4..89223c01ea 100644 --- a/packages/common/metalk8s-sosreport/metalk8s_containerd.py +++ b/packages/common/metalk8s-sosreport/metalk8s_containerd.py @@ -3,27 +3,20 @@ There is some flags to enable/disable some specific data collection like Pod logs. -NOTE: This plugin is used on different OS including CentOs 7 and Rocky 8 -which mean it need to work with both sos 3.x and sos 4.x and also with -Python 2.7 and Python 3.6. +NOTE: This plugin is used only on RedHat 8 based OS which mean it need to work +with sos 4.x and also with Python 3.6. """ -HAS_PLUGIN_OPT = False +from sos.report.plugins import Plugin, RedHatPlugin -# sos plugin layout changed in sos 4.0 +# PluginOpt get added in sos 4.3 and must be used instead of +# simple tuple starting from there try: - from sos.report.plugins import Plugin, RedHatPlugin + from sos.report.plugins import PluginOpt - # PluginOpt get added in sos 4.3 and must be used instead of - # simple tuple starting from there - try: - from sos.report.plugins import PluginOpt - - HAS_PLUGIN_OPT = True - except ImportError: - pass + HAS_PLUGIN_OPT = True except ImportError: - from sos.plugins import Plugin, RedHatPlugin + HAS_PLUGIN_OPT = False class MetalK8sContainerd(Plugin, RedHatPlugin): diff --git a/packages/redhat/7/Dockerfile b/packages/redhat/7/Dockerfile deleted file mode 100644 index 01bfdaf718..0000000000 --- a/packages/redhat/7/Dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -# Equal to centos:7.6.1810 -# SHA256 digest of the base image -ARG BUILD_IMAGE_SHA256=5d4f4e6051c7cc10f2e712f9dc3f86a2bd67e457bced7ca52a71c243099c0121 -ARG BUILD_IMAGE=docker.io/centos -FROM ${BUILD_IMAGE}@sha256:${BUILD_IMAGE_SHA256} as build - -ARG SALT_VERSION -ARG K8S_SHORT_VERSION -ARG GO_VERSION=1.19.13 - -# CentOS 7 is EOL and mirrorlist does no longer exists -# as a temporary workaround (waiting for drop of CentOS 7 support) -# let's use another mirror -RUN sed -i 's/^mirrorlist=/#mirrorlist=/; s/^#baseurl=/baseurl=/; s/mirror\.centos\.org/vault\.centos\.org/' /etc/yum.repos.d/*.repo - -ADD common/yum_repositories/*.repo /etc/yum.repos.d/ -RUN sed -i s/@SALT_VERSION@/$SALT_VERSION/ /etc/yum.repos.d/saltstack.repo -RUN sed -i s/@K8S_SHORT_VERSION@/$K8S_SHORT_VERSION/ /etc/yum.repos.d/kubernetes.repo - -ENV GOROOT /usr/local/go - -RUN yum install -y --setopt=skip_missing_names_on_install=False \ - createrepo \ - epel-release \ - python36-rpm \ - rpm-build \ - rpmdevtools \ - rpmlint \ - yum-utils \ - gcc \ - && \ - yum clean all - -# To build containerd -RUN yum install -y --setopt=skip_missing_names_on_install=False \ - btrfs-progs-devel \ - go-md2man \ - libseccomp-devel \ - systemd \ - go-srpm-macros \ - && \ - yum clean all - -RUN curl -ORL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz \ - && tar xzvf go${GO_VERSION}.linux-amd64.tar.gz \ - && rm go${GO_VERSION}.linux-amd64.tar.gz \ - && mv go /usr/local \ - && ln -s $GOROOT/bin/go /usr/local/bin/go \ - && ln -s $GOROOT/bin/gofmt /usr/local/bin/gofmt - -RUN useradd -m build diff --git a/packages/redhat/common/60-containerd.conf b/packages/redhat/common/60-containerd.conf deleted file mode 100644 index d2e27d15ab..0000000000 --- a/packages/redhat/common/60-containerd.conf +++ /dev/null @@ -1,9 +0,0 @@ -# Starting with EL7.4, this knob should be set to '1' on hosts where container -# runtimes are being used. Docker seems to set this from inside the daemon, -# containerd doesn't. -# Some pointers: -# - https://github.com/scality/metalk8s/issues/3211 -# - https://access.redhat.com/solutions/5430091 -# - https://github.com/containerd/containerd/issues/3667#issuecomment-802373736 -# - https://github.com/cri-o/cri-o/pull/4210 -fs.may_detach_mounts = 1 diff --git a/packages/redhat/common/containerd.spec b/packages/redhat/common/containerd.spec index 6fbc5c3137..1e19fecab8 100644 --- a/packages/redhat/common/containerd.spec +++ b/packages/redhat/common/containerd.spec @@ -23,44 +23,33 @@ export GOPATH=$GO_BUILD_PATH:%{gopath} %define gobuild(o:) %{expand: %global _dwz_low_mem_die_limit 0 %ifnarch ppc64 -go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-seccomp %{!?el7:no_btrfs}}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; +go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-seccomp no_btrfs}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; %else -go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-seccomp %{!?el7:no_btrfs}}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; +go build -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-seccomp no_btrfs}" -ldflags "${LDFLAGS:-} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}'" -a -v -x %{?**}; %endif } %endif Name: containerd -Release: 1%{?dist} +Release: 2%{?dist} Summary: An industry-standard container runtime License: ASL 2.0 URL: https://containerd.io Source0: %{gosource} Source1: containerd.service Source2: containerd.toml -%if 0%{?el7} -Source3: 60-containerd.conf -%endif # Carve out code requiring github.com/Microsoft/hcsshim Patch0: 0001-Revert-commit-for-Windows-metrics.patch # NOTE: We do not require golang as we do not rely on the package to install it # BuildRequires: golang >= 1.10 -%if 0%{?el7} -BuildRequires: btrfs-progs-devel -BuildRequires: go-md2man -%endif BuildRequires: libseccomp-devel BuildRequires: systemd %{?systemd_requires} # NOTE: A bug in runc 1.1.3 seems to cause issues with "exec" in containers # See https://github.com/containerd/containerd/issues/7219 -%if 0%{?el7} -Requires: runc < 1.1.3 -%else Requires: (runc < 1:1.1.3 or runc > 1:1.1.3) -%endif # vendored libraries # From github.com/containerd/containerd repository, checkout the corresponding version and run: @@ -522,9 +511,6 @@ install -D -p -m 0644 _man/ctr.8 %{buildroot}%{_mandir}/man1/ctr.8 install -D -p -m 0644 _man/containerd-config.toml.5 %{buildroot}%{_mandir}/man5/containerd-config.toml.5 install -D -p -m 0644 %{S:1} %{buildroot}%{_unitdir}/containerd.service install -D -p -m 0644 %{S:2} %{buildroot}%{_sysconfdir}/containerd/config.toml -%if 0%{?el7} -install -D -p -m 0644 %{S:3} %{buildroot}%{_sysctldir}/60-containerd.conf -%endif %if %{with tests} %check @@ -534,9 +520,6 @@ install -D -p -m 0644 %{S:3} %{buildroot}%{_sysctldir}/60-containerd.conf %post %systemd_post containerd.service -%if 0%{?el7} -%sysctl_apply 60-containerd.conf -%endif %preun @@ -559,12 +542,12 @@ install -D -p -m 0644 %{S:3} %{buildroot}%{_sysctldir}/60-containerd.conf %{_unitdir}/containerd.service %dir %{_sysconfdir}/containerd %config(noreplace) %{_sysconfdir}/containerd/config.toml -%if 0%{?el7} -%{_sysctldir}/60-containerd.conf -%endif %changelog +* Mon Sep 23 2024 Teddy Andrieux - 1.6.35-2 +- Drop RHEL 7 based support + * Mon Aug 12 2024 Yoan Moscatelli - 1.6.35-1 - Latest upstream in branch 1.6.x diff --git a/packages/redhat/common/metalk8s-sosreport.spec b/packages/redhat/common/metalk8s-sosreport.spec index c2c086c32c..a63be321ae 100644 --- a/packages/redhat/common/metalk8s-sosreport.spec +++ b/packages/redhat/common/metalk8s-sosreport.spec @@ -5,20 +5,10 @@ Summary: Metalk8s SOS report custom plugins BuildRequires: /usr/bin/pathfix.py -# sos layout changed in version 4.0, in order to make things simpler -# let's consider we have sos >= 4.0 for RHEL 8+ and sos < 4.0 for RHEL 7 -%if 0%{rhel} >= 8 Requires: sos >= 4.0 Requires: python3 >= 3.6 Requires: python3-requests Requires: python3-boto3 >= 1.6 -%else -Requires: sos >= 3.1, sos < 4.0 -Requires: python >= 2.6, python < 2.8 -Requires: python-requests -# NameError on FileNotFoundError in sos 3.5 python2.7 -Conflicts: sos = 3.5 -%endif ExclusiveArch: x86_64 ExclusiveOS: Linux @@ -30,39 +20,23 @@ Source1: ../../common/metalk8s-sosreport/metalk8s_containerd.py %description %{Summary} -%if 0%{rhel} >= 8 %define python_lib %{python3_sitelib} %define report_plugins %{python_lib}/sos/report/plugins -%else -%define python_lib %{python_sitelib} -%define report_plugins %{python_lib}/sos/plugins -%endif %install install -m 755 -d %{buildroot}/%{report_plugins} install -p -m 755 %{_topdir}/SOURCES/metalk8s.py %{buildroot}/%{report_plugins}/metalk8s.py install -p -m 755 %{_topdir}/SOURCES/metalk8s_containerd.py %{buildroot}/%{report_plugins}/metalk8s_containerd.py -%if 0%{rhel} >= 8 pathfix.py -pni "%{__python3} %{py3_shbang_opts}" %{buildroot}%{python_lib} -%else -pathfix.py -pni "%{__python} %{py_shbang_opts}" %{buildroot}%{python_lib} -%endif %files %defattr(-,root,root) %{report_plugins}/metalk8s_containerd.py %{report_plugins}/metalk8s.py -%if 0%{rhel} >= 8 %{report_plugins}/__pycache__/metalk8s_containerd.cpython-%{python3_version_nodots}.pyc %{report_plugins}/__pycache__/metalk8s_containerd.cpython-%{python3_version_nodots}.opt-?.pyc %{report_plugins}/__pycache__/metalk8s.cpython-%{python3_version_nodots}.pyc %{report_plugins}/__pycache__/metalk8s.cpython-%{python3_version_nodots}.opt-?.pyc -%else -%{report_plugins}/metalk8s.pyc -%{report_plugins}/metalk8s_containerd.pyc -%{report_plugins}/metalk8s.pyo -%{report_plugins}/metalk8s_containerd.pyo -%endif %changelog * Tue Dec 08 2020 Alexandre Allard - 1.0.0-2 diff --git a/salt/metalk8s/kubernetes/kubelet/installed.sls b/salt/metalk8s/kubernetes/kubelet/installed.sls index 36f1057dd2..de092b82cd 100644 --- a/salt/metalk8s/kubernetes/kubelet/installed.sls +++ b/salt/metalk8s/kubernetes/kubelet/installed.sls @@ -9,15 +9,3 @@ Install kubelet: {{ pkg_installed('kubelet') }} - require: - test: Repositories configured - -# When upgrading kubelet on centos7 we have error when trying to restart or get -# status of the kubelet service -# $ systemctl status kubelet -# Failed to get properties: Access denied -# -# Workaround: Reload systemctl -Reload systemctl: - module.wait: - - service.systemctl_reload: [] - - watch: - - metalk8s_package_manager: Install kubelet diff --git a/salt/metalk8s/kubernetes/kubelet/running.sls b/salt/metalk8s/kubernetes/kubelet/running.sls index 7c57e958bb..5bd12f37ed 100644 --- a/salt/metalk8s/kubernetes/kubelet/running.sls +++ b/salt/metalk8s/kubernetes/kubelet/running.sls @@ -7,5 +7,3 @@ Ensure kubelet running: - enable: True - watch: - metalk8s_package_manager: Install kubelet - - require: - - module: Reload systemctl diff --git a/salt/metalk8s/map.jinja b/salt/metalk8s/map.jinja index a8a064d17c..dcebf22c38 100644 --- a/salt/metalk8s/map.jinja +++ b/salt/metalk8s/map.jinja @@ -5,13 +5,6 @@ {% set version_defaults = salt['grains.filter_by']( salt['grains.filter_by']({ 'CentOS': { - 7: { - 'kubernetes': versions.kubernetes, - 'repo': { - 'packages': versions.packages.centos['7'], - 'images': versions.images, - }, - }, 8: { 'kubernetes': versions.kubernetes, 'repo': { @@ -21,13 +14,6 @@ }, }, 'RedHat': { - 7: { - 'kubernetes': versions.kubernetes, - 'repo': { - 'packages': versions.packages.redhat['7'], - 'images': versions.images, - }, - }, 8: { 'kubernetes': versions.kubernetes, 'repo': { @@ -43,7 +29,6 @@ {% set packages = salt['grains.filter_by']( salt['grains.filter_by']({ 'RedHat': { - 7: {}, 8: { 'python36-psutil': 'python3-psutil', 'python36-pyOpenSSL': 'python3-pyOpenSSL', @@ -88,44 +73,6 @@ {% set repo = salt['grains.filter_by']( salt['grains.filter_by']({ 'RedHat': { - 7: { - 'repositories': { - 'metalk8s-epel': { - 'humanname': 'EPEL', - 'gpgcheck': 1, - 'gpgkeys': [ - 'RPM-GPG-KEY-metalk8s-epel-7_1', - ], - 'repo_gpg_check': 0, - 'enabled': 1, - }, - 'metalk8s-kubernetes': { - 'humanname': 'Kubernetes', - 'gpgcheck': 1, - 'gpgkeys': [ - 'RPM-GPG-KEY-metalk8s-kubernetes-7_1', - ], - 'repo_gpg_check': 0, - 'enabled': 1, - }, - 'metalk8s-saltstack': { - 'humanname': 'SaltStack', - 'gpgcheck': 1, - 'gpgkeys': [ - 'RPM-GPG-KEY-metalk8s-saltstack-7_1', - ], - 'repo_gpg_check': 0, - 'enabled': 1, - }, - 'metalk8s-scality': { - 'humanname': 'Scality', - 'gpgcheck': 0, - 'gpgkeys': [], - 'repo_gpg_check': 0, - 'enabled': 1, - }, - } - }, 8: { 'repositories': { 'metalk8s-epel': { diff --git a/salt/tests/unit/formulas/config.py b/salt/tests/unit/formulas/config.py index 0c1ccde790..d9c48fff0c 100644 --- a/salt/tests/unit/formulas/config.py +++ b/salt/tests/unit/formulas/config.py @@ -116,7 +116,7 @@ def update_context(self, context: Dict[str, Any]) -> None: class OS(EnumOption): """Simulate one of the OS distributions supported by MetalK8s.""" - ALLOWED_VALUES: FrozenSet[str] = frozenset(("CentOS/7", "RedHat/7", "RedHat/8")) + ALLOWED_VALUES: FrozenSet[str] = frozenset(("CentOS/8", "RedHat/8")) def update_context(self, context: Dict[str, Any]) -> None: os_name, release = self.value.split("/") diff --git a/salt/tests/unit/formulas/config.yaml b/salt/tests/unit/formulas/config.yaml index 58839a3cff..b89a6ff1ba 100644 --- a/salt/tests/unit/formulas/config.yaml +++ b/salt/tests/unit/formulas/config.yaml @@ -3,7 +3,7 @@ # Please be mindful of the number of cases generated, as these will apply to # many formulas. default_case: - os: CentOS/7 + os: CentOS/8 saltenv: metalk8s-2.8.0 minion_state: ready architecture: single-node @@ -16,10 +16,8 @@ metalk8s: map.jinja: _cases: - "CentOS 7": - os: CentOS/7 - "RHEL 7": - os: RedHat/7 + "CentOS 8": + os: CentOS/8 "RHEL 8": os: RedHat/8 @@ -905,10 +903,8 @@ metalk8s: redhat.sls: _cases: - "CentOS 7": - os: CentOS/7 - "RHEL 7": - os: RedHat/7 + "CentOS 8": + os: CentOS/8 "RHEL 8": os: RedHat/8 @@ -1023,7 +1019,7 @@ metalk8s: installed.sls: _cases: "RedHat family": - os: CentOS/7 + os: CentOS/8 volumes: unprepared.sls: diff --git a/salt/tests/unit/formulas/data/base_grains.yaml b/salt/tests/unit/formulas/data/base_grains.yaml index d51f99f72d..ee79e75ff6 100644 --- a/salt/tests/unit/formulas/data/base_grains.yaml +++ b/salt/tests/unit/formulas/data/base_grains.yaml @@ -198,7 +198,7 @@ ipv6: kernel: Linux kernelparams: - - BOOT_IMAGE - - /boot/vmlinuz-3.10.0-1160.15.2.el7.x86_64 + - /boot/vmlinuz-4.18.0-553.16.1.el8_10.x86_64 - - root - /dev/md2 - - ro @@ -229,7 +229,7 @@ kernelparams: - '0' - - biosdevname - '0' -kernelrelease: 3.10.0-1160.15.2.el7.x86_64 +kernelrelease: 4.18.0-553.16.1.el8_10.x86_64 kernelversion: '#1 SMP Wed Feb 3 15:06:38 UTC 2021' locale_info: defaultencoding: UTF-8 @@ -237,7 +237,7 @@ locale_info: detectedencoding: UTF-8 timezone: unknown localhost: ns631140750 -lsb_distrib_codename: CentOS Linux 7 (Core) +lsb_distrib_codename: CentOS Linux 8 (Core) lsb_distrib_id: CentOS Linux lvm: {} machine_id: afec8d2527c836686dd418bb601d4f4f @@ -255,15 +255,14 @@ num_gpus: 1 os: CentOS os_family: RedHat osarch: x86_64 -oscodename: CentOS Linux 7 (Core) -osfinger: CentOS Linux-7 +oscodename: CentOS Linux 8 (Core) +osfinger: CentOS Linux-8 osfullname: CentOS Linux -osmajorrelease: 7 -osrelease: 7.9.2009 +osmajorrelease: 8 +osrelease: 8.10 osrelease_info: - - 7 - - 9 - - 2009 + - 8 + - 10 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin pid: 6928 productname: X10DRH diff --git a/salt/tests/unit/formulas/data/kubernetes/base.yaml b/salt/tests/unit/formulas/data/kubernetes/base.yaml index b5a5b6155a..14781d5cdc 100644 --- a/salt/tests/unit/formulas/data/kubernetes/base.yaml +++ b/salt/tests/unit/formulas/data/kubernetes/base.yaml @@ -426,12 +426,12 @@ items: architecture: amd64 bootID: fdbc96df-027a-4877-bd23-5f5d33ce09a1 containerRuntimeVersion: containerd://1.4.3 - kernelVersion: 3.10.0-1160.15.2.el7.x86_64 + kernelVersion: 4.18.0-553.16.1.el8_10.x86_64 kubeProxyVersion: v1.19.7 kubeletVersion: v1.19.7 machineID: cc2c86fe566741e6a2ff6d399c5d5daa operatingSystem: linux - osImage: CentOS Linux 7 (Core) + osImage: CentOS Linux 8 (Core) systemUUID: EB0EB251-7413-4A0A-867E-0E129650C679 --- diff --git a/salt/tests/unit/formulas/fixtures/data.py b/salt/tests/unit/formulas/fixtures/data.py index bcff678a19..655fc99c58 100644 --- a/salt/tests/unit/formulas/fixtures/data.py +++ b/salt/tests/unit/formulas/fixtures/data.py @@ -17,7 +17,7 @@ def _load_yaml_data(path: Path) -> Any: @pytest.fixture(scope="session", name="base_grains") def fixture_base_grains() -> Any: - """Example set of grains found on a CentOS 7 minion running MetalK8s 2.7.""" + """Example set of grains found on a CentOS 8 minion running MetalK8s 2.7.""" return _load_yaml_data(paths.DATA_DIR / "base_grains.yaml") diff --git a/salt/tests/unit/modules/files/test_metalk8s_package_manager_yum.yaml b/salt/tests/unit/modules/files/test_metalk8s_package_manager_yum.yaml index 3a2f627eaa..4544f1fc55 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_package_manager_yum.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_package_manager_yum.yaml @@ -101,9 +101,9 @@ list_pkg_dependents: package_not_yet_installed: "2.14.15" rpm_qa_outputs: my_package: | - my_package-3.11.10.el7 + my_package-3.11.10.el8 my_second_package: | - my_second_package-1.11.12.el7 + my_second_package-1.11.12.el8 package_not_yet_installed: "" result: my_package: "3.11.12" @@ -120,9 +120,9 @@ list_pkg_dependents: version: "3000.3" rpm_qa_outputs: salt-minion: | - salt-minion-2018.3.4-1.el7.noarch + salt-minion-2018.3.4-1.el8.noarch salt: | - salt-2018.3.4-1.el7.noarch + salt-2018.3.4-1.el8.noarch result: salt-minion: "3000.3" salt: "3000.3" @@ -146,7 +146,7 @@ check_pkg_availability: my_second_package: version: null my_third_package: - version: "3.10.5-0.el7" + version: "3.10.5-0.el8" exclude: "my-excluded-package,my-second-excluded-package-1.2.3" # check 1 package not available - error when retrieving it From f79925f99f3c1766a4fe9a4f78d7d6ae3c30cfc4 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 23 Sep 2024 14:08:57 +0000 Subject: [PATCH 2/2] packages/common/metalk8s-sosreport: Move to more python3 friendly Since we droped RHEL 7 based system we can also consider our sos report plugin to always run with python3 --- packages/common/metalk8s-sosreport/.pylintrc | 6 +- .../common/metalk8s-sosreport/metalk8s.py | 161 ++++++------------ .../metalk8s-sosreport/metalk8s_containerd.py | 12 +- 3 files changed, 63 insertions(+), 116 deletions(-) diff --git a/packages/common/metalk8s-sosreport/.pylintrc b/packages/common/metalk8s-sosreport/.pylintrc index d3233d6d11..a07c93b07f 100644 --- a/packages/common/metalk8s-sosreport/.pylintrc +++ b/packages/common/metalk8s-sosreport/.pylintrc @@ -1,7 +1,3 @@ [MESSAGES CONTROL] -disable=duplicate-code, - too-few-public-methods, - bad-continuation, - consider-using-f-string, - unspecified-encoding +disable=duplicate-code diff --git a/packages/common/metalk8s-sosreport/metalk8s.py b/packages/common/metalk8s-sosreport/metalk8s.py index de55a5adc7..31c6778eea 100644 --- a/packages/common/metalk8s-sosreport/metalk8s.py +++ b/packages/common/metalk8s-sosreport/metalk8s.py @@ -113,7 +113,7 @@ def _custom_collection_file(self, fname, subdir=None): # We truncate the filename to 255 characters since it's the max full_path = os.path.join(dir_name, fname[:255]) - with open(full_path, "a") as _file: + with open(full_path, "a", encoding="utf-8") as _file: yield _file def _setup_common(self): @@ -181,11 +181,9 @@ def _handle_symlinks(src_name, dest_name, kind, namespace=None): def _handle_global(): for kind, namespaces in ns_kind.items(): for namespace in namespaces: - filename = "{}_ns_{}_list.txt".format(kind, namespace) + filename = f"{kind}_ns_{namespace}_list.txt" self.add_cmd_output( - "{} get --namespace={} {}".format( - self.kube_cmd, namespace, kind - ), + f"{self.kube_cmd} get --namespace={namespace} {kind}", subdir=flat_dir, suggest_filename=filename, ) @@ -198,11 +196,9 @@ def _handle_global(): ) if kind == "pod": - filename = "{}_ns_{}_top.txt".format(kind, namespace) + filename = f"{kind}_ns_{namespace}_top.txt" self.add_cmd_output( - "{} top --namespace={} {}".format( - self.kube_cmd, namespace, kind - ), + f"{self.kube_cmd} top --namespace={namespace} {kind}", subdir=flat_dir, suggest_filename=filename, ) @@ -215,9 +211,9 @@ def _handle_global(): ) for kind in no_ns_kind: - filename = "{}_list.txt".format(kind) + filename = f"{kind}_list.txt" self.add_cmd_output( - "{} get {}".format(self.kube_cmd, kind), + f"{self.kube_cmd} get {kind}", subdir=flat_dir, suggest_filename=filename, ) @@ -225,9 +221,9 @@ def _handle_global(): _handle_symlinks(src_name=filename, dest_name="list.txt", kind=kind) if kind == "node": - filename = "{}_top.txt".format(kind) + filename = f"{kind}_top.txt" self.add_cmd_output( - "{} top {}".format(self.kube_cmd, kind), + f"{self.kube_cmd} top {kind}", subdir=flat_dir, suggest_filename=filename, ) @@ -235,39 +231,34 @@ def _handle_global(): _handle_symlinks(src_name=filename, dest_name="top.txt", kind=kind) def _handle_describe(prefix, obj): - cmd = "{} describe {} {}".format( - self.kube_cmd, - obj["kind"], - obj["metadata"]["name"], - ) + cmd = f"{self.kube_cmd} describe {obj['kind']} {obj['metadata']['name']}" if obj["metadata"].get("namespace"): cmd += " --namespace=" + obj["metadata"]["namespace"] self.add_cmd_output( cmd, subdir=flat_dir, - suggest_filename="{}_describe.txt".format(prefix), + suggest_filename=f"{prefix}_describe.txt", ) _handle_symlinks( - src_name="{}_describe.txt".format(prefix), - dest_name="{}_describe.txt".format(obj["metadata"]["name"]), + src_name=f"{prefix}_describe.txt", + dest_name=f"{obj['metadata']['name']}_describe.txt", kind=obj["kind"].lower(), namespace=obj["metadata"].get("namespace"), ) def _handle_pod_logs(prefix, obj): - cmd = "{} logs --all-containers --timestamps --since={} --namespace={} {}".format( - self.kube_cmd, - self.get_option("last"), - obj["metadata"]["namespace"], - obj["metadata"]["name"], + cmd = ( + f"{self.kube_cmd} logs --all-containers --timestamps " + f"--since={self.get_option('last')} " + f"--namespace={obj['metadata']['namespace']} {obj['metadata']['name']}" ) self.add_cmd_output( - cmd, subdir=flat_dir, suggest_filename="{}_logs.txt".format(prefix) + cmd, subdir=flat_dir, suggest_filename=f"{prefix}_logs.txt" ) _handle_symlinks( - src_name="{}_logs.txt".format(prefix), - dest_name="{}_logs.txt".format(obj["metadata"]["name"]), + src_name=f"{prefix}_logs.txt", + dest_name=f"{obj['metadata']['name']}_logs.txt", kind=obj["kind"].lower(), namespace=obj["metadata"]["namespace"], ) @@ -278,13 +269,11 @@ def _handle_pod_logs(prefix, obj): self.add_cmd_output( cmd + " --previous", subdir=flat_dir, - suggest_filename="{}_logs_previous.txt".format(prefix), + suggest_filename=f"{prefix}_logs_previous.txt", ) _handle_symlinks( - src_name="{}_logs_previous.txt".format(prefix), - dest_name="{}_logs_previous.txt".format( - obj["metadata"]["name"] - ), + src_name=f"{prefix}_logs_previous.txt", + dest_name=f"{obj['metadata']['name']}_logs_previous.txt", kind=obj["kind"].lower(), namespace=obj["metadata"]["namespace"], ) @@ -309,20 +298,18 @@ def _handle_obj(obj): obj_namespace = obj["involvedObject"].get("namespace") suffix = "event" - prefix = "{}_{}{}".format( - obj_kind, - "ns_{}_".format(obj_namespace) if obj_namespace else "", - obj_name, + prefix = ( + f"{obj_kind}_{f'ns_{obj_namespace}' if obj_namespace else ''}{obj_name}" ) with self._custom_collection_file( - "{}_{}.json".format(prefix, suffix), subdir=flat_dir + f"{prefix}_{suffix}.json", subdir=flat_dir ) as obj_file: obj_file.write(json.dumps(obj, indent=4)) _handle_symlinks( - src_name="{}_{}.json".format(prefix, suffix), - dest_name="{}_{}.json".format(obj_name, suffix), + src_name=f"{prefix}_{suffix}.json", + dest_name=f"{obj_name}_{suffix}.json", kind=obj_kind, namespace=obj_namespace, ) @@ -336,16 +323,12 @@ def _handle_obj(obj): # Retrieve Kubernetes resources types ns_resources = set( self.exec_cmd( - "{} api-resources --verbs=list --namespaced=true -o name".format( - self.kube_cmd - ) + f"{self.kube_cmd} api-resources --verbs=list --namespaced=true -o name" )["output"].splitlines() ) no_ns_resources = set( self.exec_cmd( - "{} api-resources --verbs=list --namespaced=false -o name".format( - self.kube_cmd - ) + f"{self.kube_cmd} api-resources --verbs=list --namespaced=false -o name" )["output"].splitlines() ) @@ -363,17 +346,13 @@ def _handle_obj(obj): # one by one is not efficient (too many calls to the APIServer) all_ns_obj = json.loads( self.exec_cmd( - "{} get --all-namespaces {} --output=json".format( - self.kube_cmd, ",".join(ns_resources) - ), + f"{self.kube_cmd} get --all-namespaces {','.join(ns_resources)} --output=json", stderr=False, )["output"] )["items"] all_no_ns_obj = json.loads( self.exec_cmd( - "{} get {} --output=json".format( - self.kube_cmd, ",".join(no_ns_resources) - ), + f"{self.kube_cmd} get {','.join(no_ns_resources)} --output=json", stderr=False, )["output"] )["items"] @@ -389,21 +368,14 @@ def _handle_obj(obj): def _setup_metrics(self): prom_svc = json.loads( self.exec_cmd( - "{} get svc -n metalk8s-monitoring thanos-query-http -o json".format( - self.kube_cmd - ) + f"{self.kube_cmd} get svc -n metalk8s-monitoring thanos-query-http -o json" )["output"] ) - prom_endpoint = "http://{}:{}".format( - prom_svc["spec"]["clusterIP"], - prom_svc["spec"]["ports"][0]["port"], - ) + prom_endpoint = f"http://{prom_svc['spec']['clusterIP']}:{prom_svc['spec']['ports'][0]['port']}" # pylint: disable=line-too-long # Retrieve 1 point every time for the last time - query_range = "{}:{}".format( - self.get_option("last"), self.get_option("resolution") - ) + query_range = f"{self.get_option('last')}:{self.get_option('resolution')}" # Retrieve all metrics # NOTE: Retrieving all metrics at once is not efficient since it @@ -411,42 +383,34 @@ def _setup_metrics(self): # and can cause the API to be unavailable. # We retrieve metrics one by one to avoid this issue. try: - metrics_res = requests.get( - "{}/api/v1/label/__name__/values".format(prom_endpoint) - ) + metrics_res = requests.get(f"{prom_endpoint}/api/v1/label/__name__/values") except requests.exceptions.ConnectionError as exc: - self._log_error("Unable to connect to Prometheus API: {}".format(exc)) + self._log_error(f"Unable to connect to Prometheus API: {exc}") return try: metrics_res.raise_for_status() except requests.exceptions.HTTPError as exc: - self._log_error( - "An error occurred while querying Prometheus API: {}".format(exc) - ) + self._log_error(f"An error occurred while querying Prometheus API: {exc}") return try: metrics = metrics_res.json()["data"] except ValueError as exc: self._log_error( - "Invalid JSON returned by Prometheus API: {} {}".format( - exc, metrics_res.text - ) + f"Invalid JSON returned by Prometheus API: {exc} {metrics_res.text}" ) return for metric in metrics: try: res = requests.get( - "{}/api/v1/query".format(prom_endpoint), - params={"query": "{}[{}]".format(metric, query_range)}, + f"{prom_endpoint}/api/v1/query", + params={"query": f"{metric}[{query_range}]"}, ) except requests.exceptions.ConnectionError as exc: self._log_error( - "Unable to connect to Prometheus API for metric {}: {}".format( - metric, exc - ) + f"Unable to connect to Prometheus API for metric {metric}: {exc}" ) continue @@ -454,9 +418,7 @@ def _setup_metrics(self): res.raise_for_status() except requests.exceptions.HTTPError as exc: self._log_error( - "An error occurred while retrieving the metric {}: {}".format( - metric, exc - ) + f"An error occurred while retrieving the metric {metric}: {exc}" ) continue @@ -464,14 +426,12 @@ def _setup_metrics(self): res_json = res.json() except ValueError as exc: self._log_error( - "Invalid JSON returned for metric {}: {} {}".format( - metric, exc, res.text - ) + f"Invalid JSON returned for metric {metric}: {exc} {res.text}" ) continue with self._custom_collection_file( - "{}.json".format(metric), subdir="metrics" + f"{metric}.json", subdir="metrics" ) as metric_file: metric_file.write(json.dumps(res_json, indent=4)) @@ -484,11 +444,11 @@ def _prometheus_snapshot(self): # Retrieve Prometheus endpoint prom_endpoint_cmd = ( - "{0} get endpoints " + f"{kube_cmd} get endpoints " "prometheus-operator-prometheus --output " "jsonpath='{{ .subsets[0].addresses[0].targetRef.name }} " "{{ .subsets[0].addresses[0].ip }}:" - "{{ .subsets[0].ports[0].port }}'".format(kube_cmd) + "{{ .subsets[0].ports[0].port }}'" ) prom_endpoint_res = self.exec_cmd(prom_endpoint_cmd) prom_instance, prom_endpoint = prom_endpoint_res["output"].split() @@ -498,23 +458,19 @@ def _prometheus_snapshot(self): # {"status":"success","data":{"name":"20210322T164646Z-7d0b9ca8be8e9981"}} # or in case of error: # {"status":"error","errorType":"unavailable","error":"admin APIs disabled"} - prom_snapshot_url = "http://{0}/api/v1/admin/tsdb/snapshot".format( - prom_endpoint - ) + prom_snapshot_url = f"http://{prom_endpoint}/api/v1/admin/tsdb/snapshot" res = requests.post(prom_snapshot_url) try: res.raise_for_status() except requests.exceptions.HTTPError as exc: - self._log_error( - "An error occurred while querying Prometheus API: {0}".format(str(exc)) - ) + self._log_error(f"An error occurred while querying Prometheus API: {exc}") return try: res_json = res.json() except ValueError as exc: self._log_error( - "Invalid JSON returned by Prometheus API: {} {}".format(exc, res.text) + f"Invalid JSON returned by Prometheus API: {exc} {res.text}" ) return @@ -522,28 +478,23 @@ def _prometheus_snapshot(self): snapshot_name = res_json["data"]["name"] except KeyError: self._log_error( - "Unable to generate Prometheus snapshot: {0}".format(res_json["error"]) + f"Unable to generate Prometheus snapshot: {res_json['error']}" ) return # Copy snapshot locally - snapshot_archive_dir = "{0}/prometheus-snapshot".format( - self.archive.get_archive_path() - ) + snapshot_archive_dir = f"{self.archive.get_archive_path()}/prometheus-snapshot" copy_snapshot_cmd = ( - "{0} cp -c prometheus {1}:/prometheus/snapshots/{2} {3}".format( - kube_cmd, prom_instance, snapshot_name, snapshot_archive_dir - ) + f"{kube_cmd} cp -c prometheus {prom_instance}:/prometheus/snapshots/{snapshot_name}" + f" {snapshot_archive_dir}" ) self.exec_cmd(copy_snapshot_cmd) # Remove snapshot from Prometheus pod delete_snapshot_cmd = ( - "{0} exec -c prometheus {1} -- " - "rm -rf /prometheus/snapshots/{2}".format( - kube_cmd, prom_instance, snapshot_name - ) + f"{kube_cmd} exec -c prometheus {prom_instance} -- " + f"rm -rf /prometheus/snapshots/{snapshot_name}" ) self.exec_cmd(delete_snapshot_cmd) diff --git a/packages/common/metalk8s-sosreport/metalk8s_containerd.py b/packages/common/metalk8s-sosreport/metalk8s_containerd.py index 89223c01ea..163c5e5e3a 100644 --- a/packages/common/metalk8s-sosreport/metalk8s_containerd.py +++ b/packages/common/metalk8s-sosreport/metalk8s_containerd.py @@ -64,12 +64,12 @@ def setup(self): ] self.add_journal(units="containerd") - self.add_cmd_output(["crictl {}".format(s) for s in subcmds]) + self.add_cmd_output([f"crictl {s}" for s in subcmds]) self.add_cmd_output("ls -alhR /etc/cni") ps_cmd = "crictl ps --quiet" if self.get_option("all"): - ps_cmd = "{} -a".format(ps_cmd) + ps_cmd = f"{ps_cmd} -a" img_cmd = "crictl images --quiet" pod_cmd = "crictl pods --quiet" @@ -79,15 +79,15 @@ def setup(self): pods = self._get_crio_list(pod_cmd) for container in containers: - self.add_cmd_output("crictl inspect {}".format(container)) + self.add_cmd_output(f"crictl inspect {container}") if self.get_option("logs"): - self.add_cmd_output("crictl logs -t {}".format(container)) + self.add_cmd_output(f"crictl logs -t {container}") for image in images: - self.add_cmd_output("crictl inspecti {}".format(image)) + self.add_cmd_output(f"crictl inspecti {image}") for pod in pods: - self.add_cmd_output("crictl inspectp {}".format(pod)) + self.add_cmd_output(f"crictl inspectp {pod}") def _get_crio_list(self, cmd): ret = []