Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPREQ-10003] - deprecated kuber version #690

Merged
merged 9 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
- name: Install software
run: pip3 install yq
- name: Parse kubernetes versions
Expand Down Expand Up @@ -48,10 +48,10 @@ jobs:
ssh-keyscan -H 172.17.0.1 >> ~/.ssh/known_hosts
- name: Test ssh connection
run: ssh -i ~/.ssh/id_rsa 172.17.0.1 echo "Test"
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
- name: Install Kubemarine with dependencies
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -110,10 +110,10 @@ jobs:
run: sudo ifconfig docker0:0 172.17.1.1 up
- name: Test ssh connection
run: ssh -i ~/.ssh/id_rsa 172.17.0.1 echo "Test"
- name: Set up Python 3.9
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
- name: Install Kubemarine with dependencies
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
- name: Install dependencies
run: pip install . && pip uninstall -y kubemarine
- name: Run scripts/thirdparties/sync.py
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
# Install coverage and kubemarine with all dependencies except ansible.
# Then uninstall only kubemarine to avoid ambiguity and to surely run coverage on sources.
- run: pip install coverage . && pip uninstall -y kubemarine
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
# Install pylint and kubemarine with all dependencies except ansible.
# Then uninstall only kubemarine to avoid ambiguity and to surely run pylint on sources.
- run: pip install .[pylint] && pip install -r requirements-pyinstaller.txt && pip uninstall -y kubemarine
Expand All @@ -56,7 +56,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.12"
- run: pip install radon xenon
# Use `radon cc {paths} -a` locally for full report per function
# xenon checks, if radon absolute result is A
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

# Build ipip_check binary
FROM golang:1.22 AS go-build
FROM golang:1.22.5 AS go-build

WORKDIR /opt

Expand All @@ -11,7 +11,7 @@ RUN go mod download && \
GOOS=linux CGO_ENABLED=1 go build -ldflags="-linkmode external -extldflags='-static'" -o ipip_check -buildvcs=false && \
gzip ipip_check

FROM python:3.12-slim-bullseye AS python-build
FROM python:3.12.4-slim-bullseye AS python-build
koryaga marked this conversation as resolved.
Show resolved Hide resolved

ARG BUILD_TYPE

Expand Down
6 changes: 4 additions & 2 deletions kubemarine/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,13 @@ def verify_allowed_version(version: str) -> str:
return version


def verify_supported_version(target_version: str, logger: log.EnhancedLogger) -> None:
def verify_supported_version(target_version: str, logger: log.EnhancedLogger) -> bool:
minor_version = utils.minor_version(target_version)
supported_versions = static.KUBERNETES_VERSIONS['kubernetes_versions']
if not supported_versions.get(minor_version, {}).get("supported", False):
logger.warning(f"Specified target Kubernetes version {target_version!r} - is not supported!")
logger.warning(f"Specified target Kubernetes version {target_version!r} - is deprecated!")
return False
return True


def expect_kubernetes_version(cluster: KubernetesCluster, version: str,
Expand Down
13 changes: 13 additions & 0 deletions kubemarine/procedures/check_paas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,18 @@ def kubernetes_admission_status(cluster: KubernetesCluster) -> None:
cluster.log.debug(kube_admission_status)
tc.success(results='enabled')

def verify_kubernetes_version(cluster: KubernetesCluster) -> None:
koryaga marked this conversation as resolved.
Show resolved Hide resolved
"""
The method checks if used kubernetes version is deprecated in kubemarine
"""
with TestCase(cluster, '225', "Kubernetes", "Version") as tc:
target_version = cluster.inventory['services']['kubeadm']['kubernetesVersion']
if not kubernetes.verify_supported_version(target_version, cluster.log):
raise TestWarn(f"Kubernetes version {target_version} is deprecated",
hint=f"Used kubernetes version is deprecated and will be excluded from support "
f"in future kubemarine releases. Please, plan upgrade to newer version")

tc.success(results='Kubernetes version is OK')

def geo_check(cluster: KubernetesCluster) -> None:
"""
Expand Down Expand Up @@ -1789,6 +1801,7 @@ def verify_apparmor_config(cluster: KubernetesCluster) -> None:
'policy': kubernetes_audit_policy_configuration,
},
'admission': kubernetes_admission_status,
'version': verify_kubernetes_version,
},
'etcd': {
"health_status": etcd_health_status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This section can be changed manually, but it is also synchronized automatically with the 'compatibility_map' section below.
kubernetes_versions:
v1.26:
supported: true
supported: false
v1.27:
supported: true
v1.28:
Expand Down
14 changes: 14 additions & 0 deletions scripts/thirdparties/src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from kubemarine.core import static
from .compatibility import KubernetesVersions
from .software import InternalCompatibility, UpgradeConfig, CompatibilityMap, SoftwareType
from .software.defaults import KubemarineDefaults
from .software.kubernetes_images import KubernetesImagesResolver, KubernetesImages
from .software.packages import Packages
from .software.plugins import ManifestResolver, Plugins, ManifestsEnrichment
Expand All @@ -27,6 +28,7 @@

class Synchronization:
def __init__(self,
defaults: KubemarineDefaults,
compatibility: InternalCompatibility,
kubernetes_versions: KubernetesVersions,
images_resolver: KubernetesImagesResolver,
Expand All @@ -35,6 +37,7 @@ def __init__(self,
manifests_enrichment: ManifestsEnrichment,
upgrade_config: UpgradeConfig,
):
self.defaults = defaults
self.compatibility = compatibility
self.kubernetes_versions = kubernetes_versions
self.images_resolver = images_resolver
Expand All @@ -44,6 +47,8 @@ def __init__(self,
self.upgrade_config = upgrade_config

def run(self) -> SummaryTracker:
self.validate()

tracker = SummaryTracker(self.kubernetes_versions.compatibility_map)

software: List[SoftwareType] = [
Expand Down Expand Up @@ -75,3 +80,12 @@ def run(self) -> SummaryTracker:

tracker.print()
return tracker

def validate(self) -> None:
# Validate version
default_version = self.defaults.default_version()
if default_version not in self.kubernetes_versions.compatibility_map:
raise Exception(f"Kubemarine default version {default_version} "
f"does not exist in compatibility map. "
f"Default version should be updated before excluding it from support."
)
29 changes: 29 additions & 0 deletions scripts/thirdparties/src/software/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2021-2023 NetCracker Technology Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from kubemarine.core import utils

# pylint: disable=bad-builtin

YAML = utils.yaml_structure_preserver()
RESOURCE_PATH = utils.get_internal_resource_path("resources/configurations/defaults.yaml")


class KubemarineDefaults:
def __init__(self) -> None:
with utils.open_internal(RESOURCE_PATH) as stream:
self._defaults = YAML.load(stream)

def default_version(self) -> str:
return str(self._defaults['services']['kubeadm']['kubernetesVersion'])
3 changes: 2 additions & 1 deletion scripts/thirdparties/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from src.software.kubernetes_images import KubernetesImagesResolver
from src.software.plugins import ManifestResolver, ManifestsEnrichment
from src.software.thirdparties import ThirdpartyResolver

from src.software.defaults import KubemarineDefaults

if __name__ == '__main__':
if platform.system() != 'Linux':
Expand All @@ -46,6 +46,7 @@

args = parser.parse_args()
Synchronization(
KubemarineDefaults(),
InternalCompatibility(),
KubernetesVersions(),
KubernetesImagesResolver(),
Expand Down
4 changes: 4 additions & 0 deletions test/unit/tools/thirdparties/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from scripts.thirdparties.src.software.kubernetes_images import KubernetesImagesResolver
from scripts.thirdparties.src.software.plugins import ManifestResolver, ManifestsEnrichment
from scripts.thirdparties.src.software.thirdparties import ThirdpartyResolver
from scripts.thirdparties.src.software.defaults import KubemarineDefaults

from scripts.thirdparties.src.tracker import SummaryTracker


Expand Down Expand Up @@ -163,6 +165,7 @@ def store(self):

class FakeSynchronization(Synchronization):
def __init__(self,
defaults: KubemarineDefaults,
compatibility: FakeInternalCompatibility,
kubernetes_versions: FakeKubernetesVersions,
images_resolver: FakeKubernetesImagesResolver,
Expand All @@ -171,6 +174,7 @@ def __init__(self,
upgrade_config=FakeUpgradeConfig(),
):
super().__init__(
defaults,
compatibility,
kubernetes_versions,
images_resolver,
Expand Down
4 changes: 4 additions & 0 deletions test/unit/tools/thirdparties/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from copy import deepcopy
from typing import List, Dict, ContextManager
from unittest import mock

from test.unit import utils as test_utils
from test.unit.tools.thirdparties.stub import (
FakeSynchronization, FakeInternalCompatibility, FakeKubernetesVersions,
Expand All @@ -30,6 +31,7 @@
from kubemarine.plugins import builtin
from kubemarine.plugins.manifest import Manifest, Processor, Identity
from scripts.thirdparties.src.software import thirdparties, plugins, kubernetes_images
from scripts.thirdparties.src.software.defaults import KubemarineDefaults
from scripts.thirdparties.src.software.plugins import (
ManifestResolver, ManifestsEnrichment,
ERROR_UNEXPECTED_IMAGE, ERROR_SUSPICIOUS_ABA_VERSIONS
Expand All @@ -47,6 +49,7 @@

class SynchronizationTest(unittest.TestCase):
def setUp(self) -> None:
self.defaults = KubemarineDefaults()
self.compatibility = FakeInternalCompatibility()
self.kubernetes_versions = FakeKubernetesVersions()
self.images_resolver = FakeKubernetesImagesResolver()
Expand Down Expand Up @@ -580,6 +583,7 @@ def load_compatibility_map_mocked(filename: str) -> dict:

def run_sync(self) -> SummaryTracker:
return FakeSynchronization(
self.defaults,
self.compatibility,
self.kubernetes_versions,
self.images_resolver,
Expand Down
Loading