fix: preserve bound PVC storage classes
This commit is contained in:
@@ -836,12 +836,12 @@ type ManagementClientsType = NonNullable<
|
||||
const managementClients = (
|
||||
deployments: Array<Record<string, unknown>>,
|
||||
replicaSets: Array<Record<string, unknown>>,
|
||||
objects = {} as KubernetesObjectApi,
|
||||
): ManagementClientsType => {
|
||||
const apps = new FakeApps(deployments, replicaSets);
|
||||
const objects = {} as KubernetesObjectApi;
|
||||
return {
|
||||
apps: apps as unknown as ManagementClientsType["apps"],
|
||||
objects: {} as KubernetesObjectApi,
|
||||
objects,
|
||||
config: {} as ManagementClientsType["config"],
|
||||
batch: {} as ManagementClientsType["batch"],
|
||||
core: {} as ManagementClientsType["core"],
|
||||
@@ -849,6 +849,107 @@ const managementClients = (
|
||||
};
|
||||
};
|
||||
|
||||
type PersistentVolumeClaim = KubernetesObject & {
|
||||
spec: { storageClassName?: string };
|
||||
status?: { phase?: string };
|
||||
};
|
||||
|
||||
function persistentVolumeClaim(
|
||||
storageClassName = "kuber-longhorn-test",
|
||||
): PersistentVolumeClaim {
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: "PersistentVolumeClaim",
|
||||
metadata: { name: "kimaki-kimaki-data", namespace: "kimaki" },
|
||||
spec: { storageClassName },
|
||||
};
|
||||
}
|
||||
|
||||
function managementObjects(existing?: KubernetesObject) {
|
||||
const applied: PersistentVolumeClaim[] = [];
|
||||
return {
|
||||
applied,
|
||||
objects: {
|
||||
async read() {
|
||||
if (!existing) throw { code: 404 };
|
||||
return structuredClone(existing);
|
||||
},
|
||||
async patch(resource: KubernetesObject) {
|
||||
applied.push(structuredClone(resource) as PersistentVolumeClaim);
|
||||
return resource;
|
||||
},
|
||||
} as unknown as KubernetesObjectApi,
|
||||
};
|
||||
}
|
||||
|
||||
describe("management PVC storage classes", () => {
|
||||
test("sends the existing storage class for a Bound claim with a different class", async () => {
|
||||
const existing = {
|
||||
...persistentVolumeClaim("longhorn"),
|
||||
status: { phase: "Bound" },
|
||||
};
|
||||
const fake = managementObjects(existing);
|
||||
const dependencies = createKubernetesManagementDependencies(
|
||||
managementClients([], [], fake.objects),
|
||||
);
|
||||
const desired = persistentVolumeClaim();
|
||||
|
||||
await dependencies.applyResource(desired);
|
||||
|
||||
expect(fake.applied).toEqual([
|
||||
{
|
||||
...persistentVolumeClaim(),
|
||||
spec: { storageClassName: "longhorn" },
|
||||
},
|
||||
]);
|
||||
expect(desired).toEqual(persistentVolumeClaim());
|
||||
});
|
||||
|
||||
test("retains a matching storage class for a Bound claim", async () => {
|
||||
const existing = {
|
||||
...persistentVolumeClaim(),
|
||||
status: { phase: "Bound" },
|
||||
};
|
||||
const fake = managementObjects(existing);
|
||||
const dependencies = createKubernetesManagementDependencies(
|
||||
managementClients([], [], fake.objects),
|
||||
);
|
||||
const desired = persistentVolumeClaim();
|
||||
|
||||
await dependencies.applyResource(desired);
|
||||
|
||||
expect(fake.applied).toEqual([desired]);
|
||||
});
|
||||
|
||||
test("retains the desired storage class for an absent claim", async () => {
|
||||
const fake = managementObjects();
|
||||
const dependencies = createKubernetesManagementDependencies(
|
||||
managementClients([], [], fake.objects),
|
||||
);
|
||||
const desired = persistentVolumeClaim();
|
||||
|
||||
await dependencies.applyResource(desired);
|
||||
|
||||
expect(fake.applied).toEqual([desired]);
|
||||
});
|
||||
|
||||
test("retains a different storage class for a Pending claim", async () => {
|
||||
const existing = {
|
||||
...persistentVolumeClaim("longhorn"),
|
||||
status: { phase: "Pending" },
|
||||
};
|
||||
const fake = managementObjects(existing);
|
||||
const dependencies = createKubernetesManagementDependencies(
|
||||
managementClients([], [], fake.objects),
|
||||
);
|
||||
const desired = persistentVolumeClaim();
|
||||
|
||||
await dependencies.applyResource(desired);
|
||||
|
||||
expect(fake.applied).toEqual([desired]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("rollback ReplicaSet discovery", () => {
|
||||
test("discovers owned revisions without the managed-by selector", async () => {
|
||||
const depUid = "deployment-uid";
|
||||
|
||||
Reference in New Issue
Block a user