Skip to content
Open
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
196 changes: 196 additions & 0 deletions frontend/e2e/mocks/storage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isNotFound } from '../clients/kubernetes-client';

export const testerDeployment = {
apiVersion: 'apps/v1',
kind: 'Deployment',
Expand Down Expand Up @@ -257,6 +259,105 @@ export const getVACFixtures = (suffix: string) => {
};
};

// --- VolumeGroupSnapshot fixtures ---

export const getVGSFixtures = (suffix: string, groupSnapshotStorageClassName: string) => {
const names = {
TEST_PVC_A: `vgs-testpvc-a-${suffix}`,
TEST_PVC_B: `vgs-testpvc-b-${suffix}`,
TEST_PVC_MIXED_A: `vgs-mixed-pvc-a-${suffix}`,
TEST_PVC_MIXED_B: `vgs-mixed-pvc-b-${suffix}`,
TEST_FAKE_STORAGECLASS_A: `vgs-fake-sc-a-${suffix}`,
TEST_FAKE_STORAGECLASS_B: `vgs-fake-sc-b-${suffix}`,
TEST_DEPLOYMENT: `vgs-tester-deployment-${suffix}`,
};

const makePVC = (name: string, storageClassName: string, labels: Record<string, string>) => ({
apiVersion: 'v1',
kind: 'PersistentVolumeClaim',
metadata: { name, labels },
spec: {
storageClassName,
accessModes: ['ReadWriteOnce'],
resources: { requests: { storage: '1Gi' } },
},
});

return {
...names,
// Two PVCs on the same StorageClass/provisioner, for the happy-path group snapshot.
// The caller discovers groupSnapshotStorageClassName from an existing
// VolumeGroupSnapshotClass on the cluster (see findGroupSnapshotCapableStorageClass),
// since not every StorageClass's CSI driver actually implements group snapshots.
PVC_SAME_PROVISIONER_A: makePVC(names.TEST_PVC_A, groupSnapshotStorageClassName, {
'vgs-test': 'true',
}),
PVC_SAME_PROVISIONER_B: makePVC(names.TEST_PVC_B, groupSnapshotStorageClassName, {
'vgs-test': 'true',
}),
// Two PVCs on two throwaway StorageClasses with distinct fake provisioners, so the
// create form's mixed-provisioner validation is exercised without depending on any
// real StorageClass existing on the cluster. Neither needs to be Bound: the
// validation only inspects the matched PVCs' declared StorageClass/provisioner.
PVC_MIXED_FAKE_PROVISIONER_A: makePVC(names.TEST_PVC_MIXED_A, names.TEST_FAKE_STORAGECLASS_A, {
'vgs-mixed-test': 'true',
}),
PVC_MIXED_FAKE_PROVISIONER_B: makePVC(names.TEST_PVC_MIXED_B, names.TEST_FAKE_STORAGECLASS_B, {
'vgs-mixed-test': 'true',
}),
FAKE_STORAGE_CLASS_A: {
apiVersion: 'storage.k8s.io/v1',
kind: 'StorageClass',
metadata: { name: names.TEST_FAKE_STORAGECLASS_A },
provisioner: 'csi.fake-a.example.com',
},
FAKE_STORAGE_CLASS_B: {
apiVersion: 'storage.k8s.io/v1',
kind: 'StorageClass',
metadata: { name: names.TEST_FAKE_STORAGECLASS_B },
provisioner: 'csi.fake-b.example.com',
},
getDeployment: (namespace: string, pvcNames: string[]) => ({
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: { name: names.TEST_DEPLOYMENT, namespace },
spec: {
replicas: 1,
selector: { matchLabels: { app: names.TEST_DEPLOYMENT } },
template: {
metadata: { labels: { app: names.TEST_DEPLOYMENT } },
spec: {
securityContext: {
runAsNonRoot: true,
seccompProfile: { type: 'RuntimeDefault' },
},
containers: [
{
name: 'busybox',
image: 'busybox',
imagePullPolicy: 'IfNotPresent',
securityContext: {
allowPrivilegeEscalation: false,
capabilities: { drop: ['ALL'] },
},
command: ['sh', '-c', 'echo Container is Running ; sleep 3600'],
volumeMounts: pvcNames.map((pvcName, i) => ({
name: `vol-${i}`,
mountPath: `/data-${i}`,
})),
},
],
volumes: pvcNames.map((pvcName, i) => ({
name: `vol-${i}`,
persistentVolumeClaim: { claimName: pvcName },
})),
},
},
},
}),
};
};

export async function isAwsPlatform(
k8sClient: import('../clients/kubernetes-client').default,
): Promise<boolean> {
Expand All @@ -268,3 +369,98 @@ export async function isAwsPlatform(
)) as any;
return infra?.status?.platformStatus?.type === 'AWS';
}

/**
* Whether the groupsnapshot.storage.k8s.io v1 CRDs are installed. Unlike
* findGroupSnapshotCapableStorageClass, this doesn't require a working CSI
* driver/snapshot-controller - just that the API itself is served, which is
* all UI-only tests (e.g. form validation) that never create a real
* VolumeGroupSnapshot need.
*/
export async function isGroupSnapshotApiAvailable(
k8sClient: import('../clients/kubernetes-client').default,
): Promise<boolean> {
let crd: { spec?: { versions?: { name: string; served: boolean }[] } } | null;
try {
crd = (await k8sClient.getClusterCustomResource(
'apiextensions.k8s.io',
'v1',
'customresourcedefinitions',
'volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io',
)) as { spec?: { versions?: { name: string; served: boolean }[] } };
} catch (err) {
// Only a genuine 404 means the CRD isn't installed. Any other failure (permissions,
// 503, etc.) shouldn't be silently treated as "unsupported cluster" - that masks a
// real problem behind a skipped test instead of a failure.
if (isNotFound(err)) {
return false;
}
throw err;
}
return !!crd?.spec?.versions?.some((version) => version.name === 'v1' && version.served);
}

/**
* Like k8sClient.listClusterCustomResources, but propagates failures instead of treating
* every error (permissions, 503, etc.) as "no items". A genuine 404 (the resource type
* itself doesn't exist) still returns an empty list, since that's a real "not installed"
* signal.
*/
async function listClusterCustomResourcesStrict(
k8sClient: import('../clients/kubernetes-client').default,
group: string,
version: string,
plural: string,
): Promise<unknown[]> {
try {
const response = await k8sClient.customObjectsApi.listClusterCustomObject({
group,
plural,
version,
});
return (response as any)?.items || [];
} catch (err) {
if (isNotFound(err)) {
return [];
}
throw err;
}
}

/**
* Finds a StorageClass whose provisioner matches the driver of an existing
* VolumeGroupSnapshotClass. Group-snapshot support depends on the CSI driver/
* snapshot-controller sidecar having the CSIVolumeGroupSnapshot feature gate
* enabled, which isn't implied by the CRDs being installed or by any particular
* platform, so this discovers a combination the cluster has actually been
* configured with rather than assuming one.
*/
export async function findGroupSnapshotCapableStorageClass(
k8sClient: import('../clients/kubernetes-client').default,
): Promise<{ storageClassName: string; vgsClassName: string } | null> {
const vgsClasses = (await listClusterCustomResourcesStrict(
k8sClient,
'groupsnapshot.storage.k8s.io',
'v1',
'volumegroupsnapshotclasses',
)) as { metadata: { name: string }; driver: string; deletionPolicy: string }[];
if (vgsClasses.length === 0) {
return null;
}
const storageClasses = (await listClusterCustomResourcesStrict(
k8sClient,
'storage.k8s.io',
'v1',
'storageclasses',
)) as { metadata: { name: string }; provisioner: string }[];
// Require Delete so the member VolumeSnapshots/content this test creates don't outlive
// namespace deletion (Retain would leak cluster-scoped VolumeGroupSnapshotContent and
// backend snapshot storage across test runs).
for (const vgsClass of vgsClasses.filter((c) => c.deletionPolicy === 'Delete')) {
const storageClass = storageClasses.find((sc) => sc.provisioner === vgsClass.driver);
Comment thread
dfajmon marked this conversation as resolved.
Resolved
if (storageClass) {
return { storageClassName: storageClass.metadata.name, vgsClassName: vgsClass.metadata.name };
}
}
return null;
}
172 changes: 172 additions & 0 deletions frontend/e2e/tests/console/storage/volume-group-snapshot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { test, expect } from '../../../fixtures';
import { ListPage } from '../../../pages/list-page';
import { ModalPage } from '../../../pages/modal-page';
import {
findGroupSnapshotCapableStorageClass,
getVGSFixtures,
isGroupSnapshotApiAvailable,
} from '../../../mocks/storage';

const VALIDATION_ERROR =
'Selected PVCs have different storage provisioners. All PVCs must have StorageClasses with the same provisioner.';

test.describe('VolumeGroupSnapshot Tests', { tag: ['@admin', '@storage'] }, () => {
test('creates, lists, and deletes a VolumeGroupSnapshot from a label selector', async ({
page,
k8sClient,
cleanup,
}) => {
// Group-snapshot support depends on a CSI driver/snapshot-controller with the
// CSIVolumeGroupSnapshot feature gate enabled, which isn't implied by the CRDs being
// installed or by any particular platform. Discover a StorageClass/VolumeGroupSnapshotClass
// pairing the cluster has actually been configured with, and skip otherwise.
const capable = await findGroupSnapshotCapableStorageClass(k8sClient);
test.skip(
!capable,
'No StorageClass with a provisioner matching an existing VolumeGroupSnapshotClass was found',
);
const { storageClassName, vgsClassName } = capable!;

const ns = `test-vgs-${Date.now()}`;
const fixtures = getVGSFixtures(`${Date.now()}`, storageClassName);
const {
TEST_PVC_A,
TEST_PVC_B,
PVC_SAME_PROVISIONER_A,
PVC_SAME_PROVISIONER_B,
getDeployment,
} = fixtures;
const vgsName = 'vgs-group-snapshot';
const listPage = new ListPage(page);
const modal = new ModalPage(page);

await test.step('Set up namespace and PVCs', async () => {
await k8sClient.createNamespace(ns);
cleanup.trackNamespace(ns);
await k8sClient.createPVC(ns, {
...PVC_SAME_PROVISIONER_A,
metadata: { ...PVC_SAME_PROVISIONER_A.metadata, namespace: ns },
} as any);
await k8sClient.createPVC(ns, {
...PVC_SAME_PROVISIONER_B,
metadata: { ...PVC_SAME_PROVISIONER_B.metadata, namespace: ns },
} as any);
await k8sClient.createDeployment(ns, getDeployment(ns, [TEST_PVC_A, TEST_PVC_B]) as any);
});

await test.step('Wait for both PVCs to be Bound', async () => {
for (const pvcName of [TEST_PVC_A, TEST_PVC_B]) {
await page.goto(`/k8s/ns/${ns}/persistentvolumeclaims`);
await listPage.waitForRows();
await listPage.filterByName(pvcName);
const pvcRow = listPage.getCell(pvcName).locator('xpath=ancestor::tr');
await expect(pvcRow.locator('[data-test="status-text"]')).toContainText('Bound', {
timeout: 120_000,
});
}
});

await test.step('Create VolumeGroupSnapshot from a label selector', async () => {
await page.goto(`/k8s/ns/${ns}/groupsnapshot.storage.k8s.io~v1~VolumeGroupSnapshot`);
await listPage.clickCreateButton();
await page.getByTestId('snapshot-name').fill(vgsName);
await page.getByTestId('tags-input').fill('vgs-test=true');
await page.getByTestId('tags-input').press('Enter');
await page.getByTestId('snapshot-class-dropdown').click();
await page.getByRole('option', { name: vgsClassName }).click();
await page.locator('#save-changes').click();
});

await test.step('Verify VolumeGroupSnapshot details show the source PVCs', async () => {
await expect(page).toHaveURL(
new RegExp(
`groupsnapshot\\.storage\\.k8s\\.io~v1~VolumeGroupSnapshot/${vgsName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`,
),
);
await expect(page.getByTestId('page-heading')).toContainText(vgsName);
await expect(
page.getByTestId('resource-summary').locator('[data-test="status-text"]'),
).toContainText('Ready', { timeout: 120_000 });
await expect(page.getByTestId(TEST_PVC_A)).toBeVisible();
await expect(page.getByTestId(TEST_PVC_B)).toBeVisible();
});

await test.step('Verify VolumeGroupSnapshot in list', async () => {
await page.goto(`/k8s/ns/${ns}/groupsnapshot.storage.k8s.io~v1~VolumeGroupSnapshot`);
await listPage.waitForRows();
await expect(listPage.getCell(vgsName)).toBeVisible({ timeout: 30_000 });
});

await test.step('Delete VolumeGroupSnapshot', async () => {
await listPage.clickKebabAction(vgsName, 'Delete VolumeGroupSnapshot');
await modal.waitForOpen();
await expect(modal.getSubmitButton()).toBeEnabled({ timeout: 10_000 });
await modal.submit();
await modal.waitForClosed();
await expect(listPage.getCell(vgsName)).not.toBeAttached({ timeout: 90_000 });
});
});

test('blocks VolumeGroupSnapshot creation when matched PVCs have different provisioners', async ({
page,
k8sClient,
cleanup,
}) => {
// The create form watches VolumeGroupSnapshotClass; if the CRDs aren't installed that
// watch errors and the error takes priority over the mismatch message this test checks
// for. This test otherwise doesn't need a working snapshot-capable driver - just the API.
test.skip(
!(await isGroupSnapshotApiAvailable(k8sClient)),
'groupsnapshot.storage.k8s.io v1 CRDs are not installed on this cluster',
);

const ns = `test-vgs-mixed-${Date.now()}`;
// This test only needs PVCs that declare different provisioners; it never creates a
// VolumeGroupSnapshot, so it doesn't depend on any real StorageClass/platform - both
// PVCs use throwaway StorageClasses with distinct fake provisioners.
const fixtures = getVGSFixtures(`${Date.now()}`, 'unused');
const {
PVC_MIXED_FAKE_PROVISIONER_A,
PVC_MIXED_FAKE_PROVISIONER_B,
FAKE_STORAGE_CLASS_A,
FAKE_STORAGE_CLASS_B,
} = fixtures;

await test.step('Set up namespace and mismatched-provisioner PVCs', async () => {
await k8sClient.createNamespace(ns);
cleanup.trackNamespace(ns);
for (const fakeStorageClass of [FAKE_STORAGE_CLASS_A, FAKE_STORAGE_CLASS_B]) {
await k8sClient.createClusterCustomResource(
'storage.k8s.io',
'v1',
'storageclasses',
fakeStorageClass as any,
);
cleanup.trackClusterCustomResource(
fakeStorageClass.metadata.name,
'storage.k8s.io',
'v1',
'storageclasses',
);
}
await k8sClient.createPVC(ns, {
...PVC_MIXED_FAKE_PROVISIONER_A,
metadata: { ...PVC_MIXED_FAKE_PROVISIONER_A.metadata, namespace: ns },
} as any);
await k8sClient.createPVC(ns, {
...PVC_MIXED_FAKE_PROVISIONER_B,
metadata: { ...PVC_MIXED_FAKE_PROVISIONER_B.metadata, namespace: ns },
} as any);
});

await test.step('Select both PVCs via a label selector and verify validation blocks submit', async () => {
await page.goto(`/k8s/ns/${ns}/volumegroupsnapshots/~new/form`);
Comment thread
dfajmon marked this conversation as resolved.
Resolved
await page.getByTestId('snapshot-name').fill('vgs-mixed-provisioner-test');
await page.getByTestId('tags-input').fill('vgs-mixed-test=true');
await page.getByTestId('tags-input').press('Enter');

await expect(page.getByText(VALIDATION_ERROR)).toBeVisible({ timeout: 30_000 });
await expect(page.locator('#save-changes')).toBeDisabled();
});
});
});
Loading