|
383 | 383 | # the 5m pod-Succeeded budget when containerd's CreateContainer stalls. |
384 | 384 | kubectl wait hr -n tenant-test "kubernetes-${test_name}-csi" --timeout=10m --for=condition=ready |
385 | 385 |
|
| 386 | + # ---------------------------------------------------------------------- |
| 387 | + # StorageClass propagation (issue #2094). Remote-accessible LINSTOR infra |
| 388 | + # classes propagate to the tenant under the same name; node-local classes |
| 389 | + # ("local", allowRemoteVolumeAccess=false) are filtered out; the legacy |
| 390 | + # "kubevirt" alias is retained for backward compatibility. The e2e infra |
| 391 | + # cluster ships both "replicated" (remote) and "local" (node-local). |
| 392 | + # ---------------------------------------------------------------------- |
| 393 | + echo "Verifying StorageClass propagation to tenant..." |
| 394 | + timeout 2m bash -c ' |
| 395 | + until kubectl --kubeconfig tenantkubeconfig-'"${test_name}"' get sc replicated >/dev/null 2>&1; do |
| 396 | + sleep 5 |
| 397 | + done |
| 398 | + ' |
| 399 | + |
| 400 | + rep_prov=$(kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc replicated -o jsonpath='{.provisioner}') |
| 401 | + rep_infra=$(kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc replicated -o jsonpath='{.parameters.infraStorageClassName}') |
| 402 | + if [ "$rep_prov" != "csi.kubevirt.io" ] || [ "$rep_infra" != "replicated" ]; then |
| 403 | + echo "replicated SC misconfigured: provisioner=$rep_prov infraStorageClassName=$rep_infra" >&2 |
| 404 | + kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc >&2 |
| 405 | + exit 1 |
| 406 | + fi |
| 407 | + |
| 408 | + # Legacy kubevirt alias must still exist (existing PVCs depend on it). |
| 409 | + if ! kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc kubevirt >/dev/null 2>&1; then |
| 410 | + echo "legacy kubevirt StorageClass alias is missing" >&2 |
| 411 | + exit 1 |
| 412 | + fi |
| 413 | + |
| 414 | + # Node-local "local" class must NOT be propagated (allowRemoteVolumeAccess=false). |
| 415 | + if kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc local >/dev/null 2>&1; then |
| 416 | + echo "node-local StorageClass 'local' should not be propagated to the tenant" >&2 |
| 417 | + exit 1 |
| 418 | + fi |
| 419 | + |
| 420 | + # Exactly one default StorageClass, and it must be "replicated". |
| 421 | + default_scs=$(kubectl --kubeconfig "tenantkubeconfig-${test_name}" get sc \ |
| 422 | + -o jsonpath='{range .items[?(@.metadata.annotations.storageclass\.kubernetes\.io/is-default-class=="true")]}{.metadata.name}{"\n"}{end}') |
| 423 | + default_count=$(printf '%s' "$default_scs" | grep -c .) |
| 424 | + if [ "$default_count" -ne 1 ] || [ "$default_scs" != "replicated" ]; then |
| 425 | + echo "expected exactly one default StorageClass 'replicated', got: ${default_scs:-<none>} (count=$default_count)" >&2 |
| 426 | + exit 1 |
| 427 | + fi |
| 428 | + echo "StorageClass propagation OK (replicated default, kubevirt alias present, local filtered)" |
| 429 | + |
386 | 430 | # Clean up NFS test resources from any previous failed attempt |
387 | 431 | kubectl --kubeconfig "tenantkubeconfig-${test_name}" delete pod nfs-test-pod \ |
388 | 432 | -n tenant-test --ignore-not-found --timeout=60s || true |
@@ -621,3 +665,129 @@ EOF |
621 | 665 | kubectl -n tenant-test delete kuberneteses.apps.cozystack.io "${test_name}" --ignore-not-found --wait=false 2>/dev/null || true |
622 | 666 |
|
623 | 667 | } |
| 668 | + |
| 669 | +# B1 regression coverage (PR #2872 review). The tenant's default StorageClass |
| 670 | +# must be chosen among the *propagated* classes and must never be the legacy |
| 671 | +# "kubevirt" alias -- even when the management cluster exposes only remote |
| 672 | +# LINSTOR classes whose names sort alphabetically after "kubevirt" and none is |
| 673 | +# named the configured storageClass (default "replicated"). That is the |
| 674 | +# feature's own multi-tier target configuration. A regressed `sortAlpha | first` |
| 675 | +# over a candidate set that still contained the inserted "kubevirt" alias would |
| 676 | +# pick it, pointing the tenant default at an infra class absent on the |
| 677 | +# management cluster -> default PVCs stay Pending with no error surfaced. |
| 678 | +# |
| 679 | +# helm-unittest cannot reach this branch: with no live cluster Helm `lookup` |
| 680 | +# returns empty, so the storageClasses map always collapses to the "replicated" |
| 681 | +# fallback (see packages/apps/kubernetes/tests/csi_test.yaml). It is therefore |
| 682 | +# exercised here against the live management cluster with a single server-side |
| 683 | +# dry-run render (helm v4 executes `lookup` against the API): add two remote |
| 684 | +# LINSTOR classes that sort after "kubevirt", remove "replicated" for the one |
| 685 | +# render, restore it immediately, then assert on the rendered -csi HelmRelease's |
| 686 | +# storageClasses map. |
| 687 | +verify_storageclass_fallback_default() { |
| 688 | + echo "Verifying tenant default StorageClass selection with no 'replicated' class (PR #2872 B1 regression)..." |
| 689 | + |
| 690 | + # Pre-cleanup: drop probe classes leaked by a previous failed run. |
| 691 | + kubectl delete sc nvme ssd --ignore-not-found |
| 692 | + |
| 693 | + # Two remote-accessible LINSTOR classes whose names sort AFTER "kubevirt". |
| 694 | + kubectl apply -f - <<'EOF' |
| 695 | +apiVersion: storage.k8s.io/v1 |
| 696 | +kind: StorageClass |
| 697 | +metadata: |
| 698 | + name: nvme |
| 699 | +provisioner: linstor.csi.linbit.com |
| 700 | +parameters: |
| 701 | + linstor.csi.linbit.com/storagePool: "data" |
| 702 | + linstor.csi.linbit.com/allowRemoteVolumeAccess: "true" |
| 703 | +volumeBindingMode: Immediate |
| 704 | +allowVolumeExpansion: true |
| 705 | +--- |
| 706 | +apiVersion: storage.k8s.io/v1 |
| 707 | +kind: StorageClass |
| 708 | +metadata: |
| 709 | + name: ssd |
| 710 | +provisioner: linstor.csi.linbit.com |
| 711 | +parameters: |
| 712 | + linstor.csi.linbit.com/storagePool: "data" |
| 713 | + linstor.csi.linbit.com/allowRemoteVolumeAccess: "true" |
| 714 | +volumeBindingMode: Immediate |
| 715 | +allowVolumeExpansion: true |
| 716 | +EOF |
| 717 | + |
| 718 | + # Remove "replicated" only for the duration of the render below, so that |
| 719 | + # neither the configured storageClass (default "replicated") nor "replicated" |
| 720 | + # is in the propagated set -- forcing the `sortAlpha | first` selection branch. |
| 721 | + kubectl delete sc replicated --ignore-not-found |
| 722 | + |
| 723 | + # Server-side dry-run executes Helm `lookup` against the live cluster and |
| 724 | + # renders the real storageClasses map. rc is captured separately (no pipe) so |
| 725 | + # the management-cluster state is always restored before any assertion exits. |
| 726 | + # The release namespace must be a valid tenant identifier (the chart's |
| 727 | + # dashboard-resourcemap template enforces this), so render under tenant-test. |
| 728 | + local raw rc |
| 729 | + raw=$(timeout 120 helm install scprobe packages/apps/kubernetes \ |
| 730 | + --dry-run=server -n tenant-test \ |
| 731 | + -f packages/apps/kubernetes/tests/values/common.yaml -o json 2>/tmp/sc-fallback-render.err) |
| 732 | + rc=$? |
| 733 | + |
| 734 | + # Restore management-cluster StorageClasses (inline, unconditional). This MUST |
| 735 | + # run before any assertion `exit 1` below, so no EXIT/RETURN trap is used |
| 736 | + # (per docs/agents/e2e-testing.md). The "replicated" manifest mirrors |
| 737 | + # hack/e2e-post-install-prep.sh. |
| 738 | + kubectl apply -f - <<'EOF' |
| 739 | +apiVersion: storage.k8s.io/v1 |
| 740 | +kind: StorageClass |
| 741 | +metadata: |
| 742 | + name: replicated |
| 743 | +provisioner: linstor.csi.linbit.com |
| 744 | +parameters: |
| 745 | + linstor.csi.linbit.com/storagePool: "data" |
| 746 | + linstor.csi.linbit.com/autoPlace: "3" |
| 747 | + linstor.csi.linbit.com/layerList: "drbd storage" |
| 748 | + linstor.csi.linbit.com/allowRemoteVolumeAccess: "true" |
| 749 | + property.linstor.csi.linbit.com/DrbdOptions/auto-quorum: suspend-io |
| 750 | + property.linstor.csi.linbit.com/DrbdOptions/Resource/on-no-data-accessible: suspend-io |
| 751 | + property.linstor.csi.linbit.com/DrbdOptions/Resource/on-suspended-primary-outdated: force-secondary |
| 752 | + property.linstor.csi.linbit.com/DrbdOptions/Net/rr-conflict: retry-connect |
| 753 | +volumeBindingMode: Immediate |
| 754 | +allowVolumeExpansion: true |
| 755 | +EOF |
| 756 | + kubectl delete sc nvme ssd --ignore-not-found |
| 757 | + |
| 758 | + if [ "$rc" -ne 0 ] || [ -z "$raw" ]; then |
| 759 | + echo "server-side dry-run render of the kubernetes chart failed (rc=$rc)" >&2 |
| 760 | + cat /tmp/sc-fallback-render.err >&2 || true |
| 761 | + exit 1 |
| 762 | + fi |
| 763 | + |
| 764 | + # Isolate the rendered -csi HelmRelease's storageClasses map. |
| 765 | + local sc |
| 766 | + sc=$(printf '%s' "$raw" | yq -p=json '.manifest' \ |
| 767 | + | yq 'select(.kind == "HelmRelease" and .metadata.name == "scprobe-csi") | .spec.values.storageClasses') |
| 768 | + if [ -z "$sc" ] || [ "$sc" = "null" ]; then |
| 769 | + echo "rendered scprobe-csi HelmRelease carries no storageClasses map" >&2 |
| 770 | + printf '%s' "$raw" | yq -p=json '.manifest' >&2 |
| 771 | + exit 1 |
| 772 | + fi |
| 773 | + |
| 774 | + local default_count default_key kubevirt_present kubevirt_default |
| 775 | + default_count=$(printf '%s' "$sc" | yq '[to_entries | .[] | select(.value.default == true)] | length') |
| 776 | + default_key=$(printf '%s' "$sc" | yq 'to_entries | map(select(.value.default == true)) | .[0].key') |
| 777 | + kubevirt_present=$(printf '%s' "$sc" | yq 'has("kubevirt")') |
| 778 | + kubevirt_default=$(printf '%s' "$sc" | yq '.kubevirt.default') |
| 779 | + |
| 780 | + # 1. Exactly one default. 2. The default is a propagated class (nvme/ssd), |
| 781 | + # never the kubevirt alias. 3. The kubevirt alias still exists, non-default. |
| 782 | + if [ "$default_count" != "1" ] \ |
| 783 | + || { [ "$default_key" != "nvme" ] && [ "$default_key" != "ssd" ]; } \ |
| 784 | + || [ "$kubevirt_present" != "true" ] \ |
| 785 | + || [ "$kubevirt_default" != "false" ]; then |
| 786 | + echo "tenant default StorageClass selection regressed (PR #2872 B1):" >&2 |
| 787 | + echo " default_count=$default_count default_key=$default_key kubevirt_present=$kubevirt_present kubevirt_default=$kubevirt_default" >&2 |
| 788 | + echo " expected exactly one default among {nvme,ssd}; kubevirt present and non-default" >&2 |
| 789 | + printf 'rendered storageClasses:\n%s\n' "$sc" >&2 |
| 790 | + exit 1 |
| 791 | + fi |
| 792 | + echo "StorageClass fallback-default OK (default='$default_key' among propagated classes; kubevirt alias non-default)" |
| 793 | +} |
0 commit comments