Skip to content

Commit

Permalink
Fix assigning of policies to WCP namespace in case of policy driven v…
Browse files Browse the repository at this point in the history
…olume provisioing testcases
  • Loading branch information
Aishwarya-Hebbar committed Jan 30, 2025
1 parent 98404f4 commit 370dcff
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 26 deletions.
96 changes: 73 additions & 23 deletions tests/e2e/policy_driven_vol_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var spareSpace int64 = 200
var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation tests", func() {
f := framework.NewDefaultFramework("e2e-spbm-policy")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged

var (
client clientset.Interface
namespace string
Expand All @@ -77,11 +78,9 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
defer cancel()
client = f.ClientSet
namespace = getNamespaceToRunTests(f)

bootstrap()
if guestCluster {
svcClient, svNamespace := getSvcClientAndNamespace()
setResourceQuota(svcClient, svNamespace, rqLimitScaleTest)
}

nodeList, err := fnodes.GetReadySchedulableNodes(ctx, f.ClientSet)
framework.ExpectNoError(err, "Unable to find ready and schedulable Node")
if !(len(nodeList.Items) > 0) {
Expand Down Expand Up @@ -123,6 +122,7 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
setVpxdTaskTimeout(ctx, 0) // reset vpxd timeout to default
time.Sleep(3 * time.Minute)
if supervisorCluster {
dumpSvcNsEventsOnTestFailure(client, namespace)
}
Expand Down Expand Up @@ -267,9 +267,15 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}
} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
Expand All @@ -287,8 +293,7 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
pvclaims2d = append(pvclaims2d, []*v1.PersistentVolumeClaim{pvclaim})
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)

if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand All @@ -305,7 +310,7 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
}
} else {
ginkgo.By("CNS_TEST: Running for GC setup")
createResourceQuota(client, namespace, rqLimit, policyName)

storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
pvclaim, err = createPVC(ctx, client, namespace, nil, "", storageclass, "")
Expand Down Expand Up @@ -512,9 +517,15 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}
} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
Expand All @@ -532,8 +543,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
pvclaims2d = append(pvclaims2d, []*v1.PersistentVolumeClaim{pvclaim})
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand All @@ -550,7 +559,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
}
} else {
ginkgo.By("CNS_TEST: Running for GC setup")
createResourceQuota(client, namespace, rqLimit, policyName)
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
pvclaim, err = createPVC(ctx, client, namespace, nil, largeSize, storageclass, "")
Expand Down Expand Up @@ -737,9 +745,17 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)

} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)

}

setVpxdTaskTimeout(ctx, vpxdReducedTaskTimeoutSecsInt)
Expand All @@ -757,8 +773,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand All @@ -773,7 +787,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
}
} else {
ginkgo.By("CNS_TEST: Running for GC setup")
createResourceQuota(client, namespace, rqLimit, policyName)
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
pvclaim, err = createPVC(ctx, client, namespace, nil, largeSize, storageclass, "")
Expand Down Expand Up @@ -941,13 +954,21 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)

} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)

}

framework.Logf("namespace: %s", f.Namespace.Name)

setVpxdTaskTimeout(ctx, vpxdReducedTaskTimeoutSecsInt)
defer func() {
setVpxdTaskTimeout(ctx, 0)
Expand All @@ -964,7 +985,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down Expand Up @@ -1230,9 +1250,15 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}
} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
Expand All @@ -1250,8 +1276,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
pvclaims2d = append(pvclaims2d, []*v1.PersistentVolumeClaim{pvclaim})
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down Expand Up @@ -1556,11 +1580,19 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}
} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
}
}

if vanillaCluster {
Expand All @@ -1571,7 +1603,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
createResourceQuota(client, namespace, rqLimit, policyName)
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else {
Expand Down Expand Up @@ -1837,12 +1868,18 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation

if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)

} else if guestCluster {
_, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(client, ctx, svNamespace, []string{policyName}, resourceQuotaLimit)
time.Sleep(5 * time.Minute)

restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
time.Sleep(3 * time.Minute)

}

ginkgo.By("Create SC using policy created in step 1")
Expand All @@ -1856,8 +1893,6 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
gomega.Expect(err).NotTo(gomega.HaveOccurred())
} else if supervisorCluster {
ginkgo.By("CNS_TEST: Running for WCP setup")
// create resource quota
createResourceQuota(client, namespace, rqLimit, policyName)
if wcpVsanDirectCluster {
storageclass, err = client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down Expand Up @@ -2416,15 +2451,25 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
}
} else if supervisorCluster {
assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)

for _, policyName := range policyNames {
createResourceQuota(client, namespace, rqLimit, policyName)
storageclass, err := client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
scs = append(scs, storageclass)
}
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}
} else if guestCluster {
svcClient, svNamespace := getSvcClientAndNamespace()
assignPolicyToWcpNamespace(svcClient, ctx, svNamespace, policyNames, resourceQuotaLimit)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
}
for _, policyName := range policyNames {
restClientConfig := getRestConfigClient()
setStoragePolicyQuota(ctx, restClientConfig, policyName, svNamespace, resourceQuotaLimit)
Expand Down Expand Up @@ -2635,7 +2680,12 @@ var _ = ginkgo.Describe("[vol-allocation] Policy driven volume space allocation
policyNames = append(policyNames, policyName)

assignPolicyToWcpNamespace(client, ctx, namespace, policyNames, resourceQuotaLimit)
createResourceQuota(client, namespace, rqLimit, policyName)
time.Sleep(5 * time.Minute)
restClientConfig := getRestConfigClient()
for _, policyName := range policyNames {
setStoragePolicyQuota(ctx, restClientConfig, policyName, namespace, resourceQuotaLimit)
}

storageclass, err := client.StorageV1().StorageClasses().Get(ctx, policyName, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = createVsanDPvcAndPod(sshWcpConfig, svcMasterIp, svcNamespace,
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6266,9 +6266,7 @@ func assignPolicyToWcpNamespace(client clientset.Interface, ctx context.Context,
curlCmd := fmt.Sprintf(`curl -s -o /dev/null -w "%s" -k -X PATCH`+
` 'https://%s/api/vcenter/namespaces/instances/%s' -H `+
`'vmware-api-session-id: %s' -H 'Content-type: application/json' -d `+
`'{ "access_list": [ { "domain": "", "role": "OWNER", "subject": "", "subject_type": "USER" } ], `+
`"description": "", "resource_spec": { }, "storage_specs": [ %s ], `+
`"vm_service_spec": { } }'`, httpCodeStr, vcIp, namespace, sessionId, curlStr)
`'{"storage_specs": [ %s ]}'`, httpCodeStr, vcIp, namespace, sessionId, curlStr)

framework.Logf("Running command: %s", curlCmd)
result, err := fssh.SSH(ctx, curlCmd, vcAddress, framework.TestContext.Provider)
Expand Down

0 comments on commit 370dcff

Please sign in to comment.