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

fix: add unit tests for image loader + missing images #268

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 14 additions & 0 deletions magnum_cluster_api/cmd/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,37 @@ def _get_cloud_provider_images():
"registry.k8s.io/provider-os/cinder-csi-plugin:v1.26.3",
"registry.k8s.io/provider-os/manila-csi-plugin:v1.26.3",
"registry.k8s.io/provider-os/openstack-cloud-controller-manager:v1.26.3",
# v1.27.2
"registry.k8s.io/provider-os/cinder-csi-plugin:v1.27.2",
"registry.k8s.io/provider-os/manila-csi-plugin:v1.27.2",
"registry.k8s.io/provider-os/openstack-cloud-controller-manager:v1.27.2",
# v1.28.0
"registry.k8s.io/provider-os/cinder-csi-plugin:v1.28.0",
"registry.k8s.io/provider-os/manila-csi-plugin:v1.28.0",
"registry.k8s.io/provider-os/openstack-cloud-controller-manager:v1.28.0",
]


def _get_infra_images():
return [
"registry.k8s.io/sig-storage/csi-attacher:v3.4.0",
"registry.k8s.io/sig-storage/csi-attacher:v4.2.0",
"registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.4.0",
"registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.5.1",
"registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.6.2",
"registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.6.3",
"registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.9.0",
"registry.k8s.io/sig-storage/csi-provisioner:v3.0.0",
"registry.k8s.io/sig-storage/csi-provisioner:v3.1.0",
"registry.k8s.io/sig-storage/csi-provisioner:v3.3.0",
"registry.k8s.io/sig-storage/csi-provisioner:v3.4.1",
"registry.k8s.io/sig-storage/csi-resizer:v1.4.0",
"registry.k8s.io/sig-storage/csi-resizer:v1.8.0",
"registry.k8s.io/sig-storage/csi-snapshotter:v5.0.1",
"registry.k8s.io/sig-storage/csi-snapshotter:v6.0.1",
"registry.k8s.io/sig-storage/csi-snapshotter:v6.2.1",
"registry.k8s.io/sig-storage/livenessprobe:v2.7.0",
"registry.k8s.io/sig-storage/livenessprobe:v2.8.0",
"registry.k8s.io/sig-storage/livenessprobe:v2.9.0",
"registry.k8s.io/sig-storage/nfsplugin:v4.2.0",
]
77 changes: 77 additions & 0 deletions magnum_cluster_api/tests/unit/cmd/test_image_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2023 VEXXHOST, Inc.
#
# 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.

import itertools
import os

import pkg_resources
import yaml

from magnum_cluster_api.cmd import image_loader


def _get_images_from_manifests(file: str):
with open(file) as fd:
data = fd.read()

images = []
for doc in yaml.safe_load_all(data):
if doc["kind"] in ("DaemonSet", "Deployment", "StatefulSet"):
for container in itertools.chain(
doc["spec"]["template"]["spec"].get("initContainers", []),
doc["spec"]["template"]["spec"]["containers"],
):
images.append(container["image"])

return set(images)


def test__get_calico_images():
manifests_path = pkg_resources.resource_filename("magnum_cluster_api", "manifests")

calico_path = os.path.join(manifests_path, "calico")
for file in os.listdir(calico_path):
assert _get_images_from_manifests(os.path.join(calico_path, file)) == set(
image_loader._get_calico_images()
)


def test__get_cloud_provider_images():
manifests_path = pkg_resources.resource_filename("magnum_cluster_api", "manifests")
ccm_path = os.path.join(
manifests_path, "ccm/openstack-cloud-controller-manager-ds.yaml"
)

assert _get_images_from_manifests(ccm_path).issubset(
image_loader._get_cloud_provider_images()
)


def test__get_infra_images():
manifests_path = pkg_resources.resource_filename("magnum_cluster_api", "manifests")

for csi in ["cinder", "manila", "nfs"]:
folder = os.path.join(manifests_path, f"{csi}-csi")

for file in os.listdir(folder):
path = os.path.join(folder, file)

for image in _get_images_from_manifests(path):
if image in ("registry.k8s.io/provider-os/manila-csi-plugin:latest",):
continue

assert (
image in image_loader._get_infra_images()
or image in image_loader._get_cloud_provider_images()
)
Loading