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

Use background cascading deletion of DynamicPVC #1474

Merged
merged 2 commits into from
Nov 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ default PersistentVolumeClaim createPVC(KubernetesClient client, ObjectMeta podM
OwnerReference ownerReference = new OwnerReferenceBuilder().
withApiVersion("v1").
withKind("Pod").
withBlockOwnerDeletion(true).
withController(true).
withName(podMetaData.getName()).
withUid(podMetaData.getUid()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.csanchez.jenkins.plugins.kubernetes.pipeline;

import static org.awaitility.Awaitility.await;
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.CONTAINER_ENV_VAR_FROM_SECRET_VALUE;
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.POD_ENV_VAR_FROM_SECRET_VALUE;
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.WINDOWS_1809_BUILD;
Expand All @@ -44,6 +45,7 @@

import io.fabric8.kubernetes.api.model.StatusDetails;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,6 +74,7 @@
import org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
Expand Down Expand Up @@ -688,24 +691,27 @@ public void secretMaskingWindows() throws Exception {

@Test
public void dynamicPVCWorkspaceVolume() throws Exception {
try {
cloud.connect().persistentVolumeClaims().list();
} catch (KubernetesClientException x) {
// Error from server (Forbidden): persistentvolumeclaims is forbidden: User "system:serviceaccount:kubernetes-plugin-test:default" cannot list resource "persistentvolumeclaims" in API group "" in the namespace "kubernetes-plugin-test"
assumeNoException("was not permitted to list pvcs, so presumably cannot run test either", x);
}
assumePvcAccess();
var size = cloud.connect().persistentVolumeClaims().list().getItems().size();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
await().until(() -> cloud.connect().persistentVolumeClaims().list().getItems(), hasSize(size));
}

@Test
public void dynamicPVCVolume() throws Exception {
assumePvcAccess();
var size = cloud.connect().persistentVolumeClaims().list().getItems().size();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
await().until(() -> cloud.connect().persistentVolumeClaims().list().getItems(), hasSize(size));
}

private void assumePvcAccess() throws KubernetesAuthException, IOException {
try {
cloud.connect().persistentVolumeClaims().list();
} catch (KubernetesClientException x) {
// Error from server (Forbidden): persistentvolumeclaims is forbidden: User "system:serviceaccount:kubernetes-plugin-test:default" cannot list resource "persistentvolumeclaims" in API group "" in the namespace "kubernetes-plugin-test"
assumeNoException("was not permitted to list pvcs, so presumably cannot run test either", x);
}
r.assertBuildStatusSuccess(r.waitForCompletion(b));
}

@Test
Expand Down