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

Cleans up rocks and test #33

Merged
merged 2 commits into from
Sep 17, 2024
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
149 changes: 63 additions & 86 deletions tests/integration/test_longhorn_in_helm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,6 @@
INSTALL_NAME = "longhorn"
INSTALL_NS = "longhorn"

LONGHORN_AUX_IMAGES_VERSION_MAP = {
# https://github.com/longhorn/longhorn/releases/download/v1.6.2/longhorn-images.txt
"v1.6.2": {
"support-bundle-kit": "v0.0.37",
"csi-attacher": "v4.5.1",
"csi-node-driver-registrar": "v2.9.2",
"csi-resizer": "v1.10.1",
"csi-snapshotter": "v6.3.4",
"livenessprobe": "v2.12.0",
"openshift-origin-oauth-proxy": "4.14",
},
# https://github.com/longhorn/longhorn/releases/download/v1.7.0/longhorn-images.txt
"v1.7.0": {
"support-bundle-kit": "v0.0.41",
"csi-attacher": "v4.6.1",
"csi-node-driver-registrar": "v2.11.1",
"csi-resizer": "v1.11.1",
"csi-snapshotter": "v7.0.2",
"livenessprobe": "v2.13.1",
"openshift-origin-oauth-proxy": "4.15",
},
}

# This mapping indicates which fields of the upstream Longhorn Helm chart
# contain the 'image' fields which should be overridden with the ROCK
Expand All @@ -63,7 +41,6 @@
"longhorn-share-manager": "longhorn.shareManager",
"backing-image-manager": "longhorn.backingImageManager",
"support-bundle-kit": "longhorn.supportBundleKit",
"openshift-origin-oauth-proxy": "openshift.oauthProxy",
}

LONGHORN_CSI_IMAGES_VERSION_MAP = {
Expand Down Expand Up @@ -111,66 +88,7 @@ def _wait_for_node_annotation(instance, annotation, value):
assert annotated, f"Expected node to have annotation '{annotation}={value}'."


@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_longhorn_helm_chart_deployment(
function_instance: harness.Instance, image_version: str
):

# Install prerequisites.
base_url = f"https://raw.githubusercontent.com/longhorn/longhorn/{image_version}/deploy/prerequisite"
for yaml_file in [
"longhorn-iscsi-installation.yaml",
"longhorn-nfs-installation.yaml",
]:
url = f"{base_url}/{yaml_file}"
process = function_instance.exec(
["k8s", "kubectl", "apply", "-f", url], check=True
)

architecture = platform_util.get_current_rockcraft_platform_architecture()

# Compose the Helm command line args for overriding the
# image fields for each component:
all_chart_value_overrides_args = []
found_env_rocks_metadata = []
all_rocks_meta_info = env_util.get_rocks_meta_info_from_env()

# NOTE(aznashwan): GitHub actions UI sometimes truncates env values:
LOG.info(
f"All built rocks metadata from env was: "
f"{json.dumps([rmi.__dict__ for rmi in all_rocks_meta_info])}"
)

for rmi in all_rocks_meta_info:
if rmi.name in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP and (
rmi.version == image_version and rmi.arch == architecture
):
chart_section = IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP[rmi.name]
repo, tag = rmi.image.split(":")
all_chart_value_overrides_args.extend(
[
"--set",
f"image.{chart_section}.repository={repo}",
"--set",
f"image.{chart_section}.tag={tag}",
]
)
found_env_rocks_metadata.append(rmi.name)

images = [
k8s_util.HelmImage(image, subitem=subsection)
for subsection, image in LONGHORN_CSI_IMAGES_VERSION_MAP[image_version].items()
]

# include the version in the url, but without the leading 'v'.
chart_url = CHART_RELEASE_URL % {"version": image_version[1:]}
helm_command = k8s_util.get_helm_install_command(
INSTALL_NAME, chart_url, INSTALL_NS, images=images
)
helm_command.extend(all_chart_value_overrides_args)

function_instance.exec(helm_command)

def _wait_for_longhorn(instance: harness.Instance):
# HACK(aznashwan): all the Longhorn deployment resources in the chart
# take a while to be properly set up, so we provide a generous wait:
retry_kwargs = {"retry_times": 30, "retry_delay_s": 10}
Expand All @@ -181,7 +99,7 @@ def test_longhorn_helm_chart_deployment(
]
for daemonset in daemonsets:
k8s_util.wait_for_daemonset(
function_instance,
instance,
daemonset,
INSTALL_NS,
**retry_kwargs,
Expand All @@ -197,7 +115,7 @@ def test_longhorn_helm_chart_deployment(
]
for deployment in deployments:
k8s_util.wait_for_deployment(
function_instance,
instance,
deployment,
INSTALL_NS,
condition=constants.K8S_CONDITION_AVAILABLE,
Expand All @@ -207,9 +125,68 @@ def test_longhorn_helm_chart_deployment(
# Wait until the node gets annotated with driver.longhorn.io, meaning that the Longhorn CSI
# plugin was successfully registered.
_wait_for_node_annotation(
function_instance, CSI_VOLUME_ANNOTATION, LONGHORN_CSI_ANNOTATION_VALUE
instance, CSI_VOLUME_ANNOTATION, LONGHORN_CSI_ANNOTATION_VALUE
)


def _get_helm_command(image_version: str):
architecture = platform_util.get_current_rockcraft_platform_architecture()

# Compose the Helm command line args for overriding the
# image fields for each component:
all_rocks_meta_info = env_util.get_rocks_meta_info_from_env()

# NOTE(aznashwan): GitHub actions UI sometimes truncates env values:
LOG.info(
f"All built rocks metadata from env was: "
f"{json.dumps([rmi.__dict__ for rmi in all_rocks_meta_info])}"
)

images = []
for rmi in all_rocks_meta_info:
if rmi.name in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP and (
rmi.version == image_version and rmi.arch == architecture
):
chart_section = IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP[rmi.name]
images.append(k8s_util.HelmImage(rmi.image, subitem=chart_section))

images += [
k8s_util.HelmImage(image, subitem=subsection)
for subsection, image in LONGHORN_CSI_IMAGES_VERSION_MAP[image_version].items()
]

# include the version in the url, but without the leading 'v'.
chart_url = CHART_RELEASE_URL % {"version": image_version[1:]}
helm_command = k8s_util.get_helm_install_command(
INSTALL_NAME, chart_url, INSTALL_NS, images=images
)

return helm_command


@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_longhorn_helm_chart_deployment(
function_instance: harness.Instance, image_version: str
):

# Install prerequisites.
base_url = f"https://raw.githubusercontent.com/longhorn/longhorn/{image_version}/deploy/prerequisite"
for yaml_file in [
"longhorn-iscsi-installation.yaml",
"longhorn-nfs-installation.yaml",
]:
url = f"{base_url}/{yaml_file}"
process = function_instance.exec(
["k8s", "kubectl", "apply", "-f", url], check=True
)

# Deploy Longhorn through a helm chart.
helm_command = _get_helm_command(image_version)
function_instance.exec(helm_command)

# Wait for Longhorn to become active,
_wait_for_longhorn(function_instance)

# Deploy an nginx Pod with a PVC, which should be satisfied by Longhorn.
function_instance.exec(
["k8s", "kubectl", "apply", "-f", "-"],
Expand Down
6 changes: 3 additions & 3 deletions v1.6.2/longhorn-share-manager/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ parts:
ln -sf /proc/self/mounts $CRAFT_PART_INSTALL/etc/mtab

# create and add the ganesha-extra files.
# https://github.com/longhorn/longhorn-share-manager/blob/v1.7.0/package/Dockerfile#L40
# https://github.com/longhorn/longhorn-share-manager/blob/v1.6.2/package/Dockerfile#L38
mkdir -p $CRAFT_PART_INSTALL/etc/dbus-1/system.d
cp src/scripts/ganeshactl/org.ganesha.nfsd.conf $CRAFT_PART_INSTALL/etc/dbus-1/system.d/

# add libs from /usr/local/lib64
# https://github.com/longhorn/longhorn-share-manager/blob/v1.7.0/package/Dockerfile#L62
# https://github.com/longhorn/longhorn-share-manager/blob/v1.6.2/package/Dockerfile#L53
echo /usr/local/lib64 > $CRAFT_PART_INSTALL/etc/ld.so.conf.d/local_libs.conf

# create other files.
mkdir -p $CRAFT_PART_INSTALL/var/run/dbus $CRAFT_PART_INSTALL/export

# do not ask systemd for user IDs or groups (slows down dbus-daemon start),
# do not ask systemd for user IDs or groups (slows down dbus-daemon start).
cp /etc/nsswitch.conf $CRAFT_PART_INSTALL/etc/
sed -i s/systemd// $CRAFT_PART_INSTALL/etc/nsswitch.conf
5 changes: 5 additions & 0 deletions v1.6.2/longhorn-ui/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
on-failure: shutdown

parts:
# https://github.com/longhorn/longhorn-ui/blob/v1.6.2/Dockerfile#L32
nginx-user:
plugin: nil
overlay-script: |
Expand All @@ -67,6 +68,7 @@ parts:
after: [nginx-user]
plugin: nil
stage-packages:
# https://github.com/longhorn/longhorn-ui/blob/v1.6.2/Dockerfile#L16
- curl
- libxml2
- gettext
Expand All @@ -91,17 +93,20 @@ parts:
build-packages:
- gettext-base
build-snaps:
# https://github.com/longhorn/longhorn-ui/blob/v1.6.2/Dockerfile#L1
- node/16/stable
build-environment:
- VERSION: $CRAFT_PROJECT_VERSION
override-build: |
npm ci
# Inject the version before building.
# https://github.com/longhorn/longhorn-ui/blob/v1.6.2/Dockerfile#L10
sed -i -e "s/\${VERSION}/${VERSION}/" src/utils/config.js
npm run build

mkdir -p "${CRAFT_PART_INSTALL}/etc/nginx" "${CRAFT_PART_INSTALL}/web"
cp nginx.conf.template "${CRAFT_PART_INSTALL}/etc/nginx/"

# nginx.conf.template has /web/dist location set in it.
# https://github.com/longhorn/longhorn-ui/blob/v1.6.2/Dockerfile#L22
cp -r dist "${CRAFT_PART_INSTALL}/web/"
6 changes: 6 additions & 0 deletions v1.6.2/support-bundle-kit/v0.0.37/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ services:
summary: "support-bundle-kit service"
override: replace
startup: enabled
# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/package/Dockerfile#L35
command: "entrypoint.sh"
on-success: shutdown
on-failure: shutdown

parts:
# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/package/Dockerfile#L10
# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/package/Dockerfile#L20-L21
add-packages:
plugin: nil
stage-packages:
Expand All @@ -52,6 +55,7 @@ parts:
source-tag: $CRAFT_PROJECT_VERSION
source-depth: 1
build-snaps:
# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/Dockerfile.dapper#L1
- go/1.20/stable
build-environment:
- GOOS: linux
Expand All @@ -63,9 +67,11 @@ parts:
override-build: |
mkdir -p "${CRAFT_PART_INSTALL}/usr/bin/" "${CRAFT_PART_INSTALL}/tmp"

# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/scripts/build#L14
LINKFLAGS="-extldflags -static -s -X github.com/rancher/support-bundle-kit/cmd.AppVersion=$VERSION"
go build -o $CRAFT_PART_INSTALL/usr/bin/ -ldflags "$LINKFLAGS"

# https://github.com/rancher/support-bundle-kit/blob/v0.0.37/package/Dockerfile#L23-L33
cp package/entrypoint.sh "${CRAFT_PART_INSTALL}/usr/bin/"
cp hack/support-bundle-collector.sh hack/collector-* "${CRAFT_PART_INSTALL}/usr/bin/"

Expand Down
4 changes: 1 addition & 3 deletions v1.7.0/backing-image-manager/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC

bash ./scripts/build

# https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L23
mkdir -p $CRAFT_PART_INSTALL/usr/local/bin
cp $CRAFT_PART_SRC/bin/backing-image-manager-${CRAFT_ARCH_BUILD_FOR} $CRAFT_PART_INSTALL/usr/local/bin/backing-image-manager
cp bin/backing-image-manager-${CRAFT_ARCH_BUILD_FOR} $CRAFT_PART_INSTALL/usr/local/bin/backing-image-manager

# Pulls a pre-built binary release of the `tini` init system.
# https://github.com/longhorn/backing-image-manager/blob/v1.7.0/package/Dockerfile#L28-L30
Expand Down
15 changes: 2 additions & 13 deletions v1.7.0/longhorn-instance-manager/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version: "v1.7.0"
# NOTE(aznashwan): the base for the Instance Manager image is the Suse Linux Enterprise
# Base Container Image (SLE BCE) Service Pack 6 which ships with Linux 6.4,
# and is thus most comparable to 24.04:
# https://github.com/longhorn/longhorn-instance-manager/blob/v1.7.0/package/Dockerfile#L44
# https://github.com/longhorn/longhorn-instance-manager/blob/v1.7.0/package/Dockerfile#L34
base: ubuntu@24.04
build-base: ubuntu@24.04
platforms:
Expand Down Expand Up @@ -115,13 +115,11 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC

bash ./scripts/build

# https://github.com/longhorn/longhorn-instance-manager/blob/v1.7.0/package/Dockerfile#L165-L166
mkdir -p $CRAFT_PART_INSTALL/usr/local/bin
cp $CRAFT_PART_SRC/bin/longhorn-instance-manager $CRAFT_PART_INSTALL/usr/local/bin
cp bin/longhorn-instance-manager $CRAFT_PART_INSTALL/usr/local/bin

# NOTE(aznashwan): the original script is lacking any error
# handling/debugging so we add it ourselves:
Expand All @@ -147,7 +145,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC
go build

mkdir -p $CRAFT_PART_INSTALL/usr/local/bin
Expand Down Expand Up @@ -186,7 +183,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC
make
make install

Expand All @@ -203,7 +199,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC
make
make install

Expand All @@ -223,8 +218,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC

git submodule update --init

sed -i.bak "s/pip3 install/pip3 install --break-system-packages/g" ./scripts/pkgdep/ubuntu.sh
Expand Down Expand Up @@ -264,8 +257,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC

mkdir -p .build
cd .build

Expand Down Expand Up @@ -295,8 +286,6 @@ parts:
override-build: |
set -eux -o pipefail

cd $CRAFT_PART_SRC

meson setup --force-fallback-for=libnvme .build
meson compile -C .build
meson install -C .build
Expand Down
2 changes: 1 addition & 1 deletion v1.7.0/longhorn-manager/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version: "v1.7.0"
# NOTE(aznashwan): the base for the manager image is the Suse Linux Enterprise
# Base Container Image (SLE BCE) Service Pack 6 which ships with Linux 6.4,
# and is thus most comparable to 24.04:
# https://github.com/longhorn/longhorn-manager/blob/v1.7.0/package/Dockerfile#L44
# https://github.com/longhorn/longhorn-manager/blob/v1.7.0/package/Dockerfile#L3
base: ubuntu@24.04
build-base: ubuntu@24.04
platforms:
Expand Down
Loading
Loading