fix pvc race condition (#786) (#789)

This commit is contained in:
Enrico Candino
2026-04-16 11:27:49 +02:00
committed by GitHub
parent d784743360
commit bbe79b1fbd
4 changed files with 38 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/utils/ptr"
appsv1 "k8s.io/api/apps/v1"
@@ -39,16 +40,17 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
pvc *v1.PersistentVolumeClaim
namespace = "default"
labels = map[string]string{
"app": "k3k-deployment-test-app",
}
)
BeforeAll(func() {
BeforeEach(func() {
var err error
ctx := context.Background()
labels := map[string]string{
"app": "k3k-deployment-test-app-" + rand.String(5),
}
By("Creating the PVC")
pvc = &v1.PersistentVolumeClaim{
@@ -69,6 +71,11 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
pvc, err = virtualCluster.Client.CoreV1().PersistentVolumeClaims(namespace).Create(ctx, pvc, metav1.CreateOptions{})
Expect(err).To(Not(HaveOccurred()))
DeferCleanup(func() {
err := virtualCluster.Client.CoreV1().PersistentVolumeClaims(namespace).Delete(ctx, pvc.Name, metav1.DeleteOptions{})
Expect(err).To(Not(HaveOccurred()))
})
By("Creating the Deployment")
deployment = &appsv1.Deployment{
@@ -111,6 +118,11 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
deployment, err = virtualCluster.Client.AppsV1().Deployments(namespace).Create(ctx, deployment, metav1.CreateOptions{})
Expect(err).To(Not(HaveOccurred()))
DeferCleanup(func() {
err := virtualCluster.Client.AppsV1().Deployments(namespace).Delete(ctx, deployment.Name, metav1.DeleteOptions{})
Expect(err).To(Not(HaveOccurred()))
})
})
It("should bound the PVC in the virtual cluster", func() {
@@ -191,20 +203,19 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
statefulSet *appsv1.StatefulSet
namespace = "default"
labels = map[string]string{
"app": "k3k-sts-test-app",
}
)
BeforeAll(func() {
BeforeEach(func() {
var err error
ctx := context.Background()
namespace := "default"
By("Creating the StatefulSet")
labels := map[string]string{
"app": "k3k-sts-test-app-" + rand.String(5),
}
statefulSet = &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "k3k-sts-test-app-",
@@ -251,6 +262,11 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
statefulSet, err = virtualCluster.Client.AppsV1().StatefulSets(namespace).Create(ctx, statefulSet, metav1.CreateOptions{})
Expect(err).To(Not(HaveOccurred()))
DeferCleanup(func() {
err := virtualCluster.Client.AppsV1().StatefulSets(namespace).Delete(ctx, statefulSet.Name, metav1.DeleteOptions{})
Expect(err).To(Not(HaveOccurred()))
})
})
It("should bound the PVCs in the virtual cluster", func() {
@@ -279,7 +295,7 @@ var _ = Context("In a shared cluster", Label(e2eTestLabel), Ordered, func() {
labelSelector := metav1.FormatLabelSelector(statefulSet.Spec.Selector)
listOpts := metav1.ListOptions{LabelSelector: labelSelector}
pvcs, err := virtualCluster.Client.CoreV1().PersistentVolumeClaims(statefulSet.Namespace).List(ctx, listOpts)
pvcs, err := virtualCluster.Client.CoreV1().PersistentVolumeClaims(namespace).List(ctx, listOpts)
g.Expect(err).NotTo(HaveOccurred())
for _, pvc := range pvcs.Items {

View File

@@ -178,6 +178,9 @@ var _ = When("a cluster's status is tracked", Label(e2eTestLabel), Label(statusT
Expect(k8sClient.Delete(ctx, priorityClassVCP)).To(Succeed())
})
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(vcp), vcp)
Expect(err).NotTo(HaveOccurred())
vcp.Spec.DefaultPriorityClass = priorityClassVCP.Name
Expect(k8sClient.Update(ctx, vcp)).To(Succeed())

View File

@@ -361,9 +361,6 @@ var _ = Describe("VirtualClusterPolicy Controller", Label("controller"), Label("
})
bindPolicyToNamespace(namespace, policy)
err := k8sClient.Update(ctx, policy)
Expect(err).To(Not(HaveOccurred()))
cluster := &v1beta1.Cluster{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "cluster-",
@@ -376,7 +373,7 @@ var _ = Describe("VirtualClusterPolicy Controller", Label("controller"), Label("
},
}
err = k8sClient.Create(ctx, cluster)
err := k8sClient.Create(ctx, cluster)
Expect(err).To(Not(HaveOccurred()))
// wait a bit