diff --git a/k3k-kubelet/controller/syncer/persistentvolumeclaims.go b/k3k-kubelet/controller/syncer/persistentvolumeclaims.go index 6dac500..205eb34 100644 --- a/k3k-kubelet/controller/syncer/persistentvolumeclaims.go +++ b/k3k-kubelet/controller/syncer/persistentvolumeclaims.go @@ -191,6 +191,13 @@ func (r *PVCReconciler) createVirtualPersistentVolume(ctx context.Context, pvc v pvcPatch.Annotations[volume.AnnBoundByController] = "yes" pvcPatch.Annotations[volume.AnnBindCompleted] = "yes" + pvcPatch.Spec.VolumeName = pv.Name + + // Update spec to set the volumeName binding + if err := r.VirtualClient.Update(ctx, pvcPatch); err != nil { + return err + } + pvcPatch.Status.Phase = v1.ClaimBound pvcPatch.Status.AccessModes = pvcPatch.Spec.AccessModes diff --git a/tests/e2e/cluster_app_test.go b/tests/e2e/cluster_app_test.go index 615a527..dd0a7a5 100644 --- a/tests/e2e/cluster_app_test.go +++ b/tests/e2e/cluster_app_test.go @@ -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 { diff --git a/tests/e2e/cluster_status_test.go b/tests/e2e/cluster_status_test.go index 4aa6884..6a12b0d 100644 --- a/tests/e2e/cluster_status_test.go +++ b/tests/e2e/cluster_status_test.go @@ -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()) diff --git a/tests/integration/policy/policy_test.go b/tests/integration/policy/policy_test.go index 44b907e..19a7efb 100644 --- a/tests/integration/policy/policy_test.go +++ b/tests/integration/policy/policy_test.go @@ -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