Skip to content

Commit

Permalink
Merge pull request #85 from Barakmor1/tests
Browse files Browse the repository at this point in the history
[Tests] Modifications to Support Wider Environments
  • Loading branch information
kubevirt-bot authored Aug 28, 2024
2 parents 2e5328b + 180d97d commit b9f5bc9
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 76 deletions.
28 changes: 14 additions & 14 deletions tests/aaq_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("ALL Operator tests", func() {
// Condition flags can be found here with their meaning https://github.com/kubevirt/hyperconverged-cluster-operator/blob/main/docs/conditions.md
It("Condition flags on CR should be healthy and operating", func() {
Eventually(func() error {
aaqObject, err := utils.GetAAQ(f)
aaqObject, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
conditionMap := sdk.GetConditionValues(aaqObject.Status.Conditions)
if conditionMap[conditions.ConditionAvailable] != corev1.ConditionTrue {
Expand Down Expand Up @@ -123,7 +123,7 @@ var _ = Describe("ALL Operator tests", func() {
})

It("should deploy components that tolerate CriticalAddonsOnly taint", func() {
aaq, err := utils.GetAAQ(f)
aaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
criticalAddonsToleration := corev1.Toleration{
Key: "CriticalAddonsOnly",
Expand Down Expand Up @@ -177,7 +177,7 @@ var _ = Describe("ALL Operator tests", func() {
var aaqPods *corev1.PodList

BeforeEach(func() {
cr, err = utils.GetAAQ(f)
cr, err = utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
aaqPods = getAAQPods(f)
})
Expand Down Expand Up @@ -205,7 +205,7 @@ var _ = Describe("ALL Operator tests", func() {
f := framework.NewFramework("operator-delete-aaq-test")

BeforeEach(func() {
currentCR, err := utils.GetAAQ(f)
currentCR, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())

aaqBackup = &aaqv1.AAQ{
Expand Down Expand Up @@ -346,7 +346,7 @@ var _ = Describe("ALL Operator tests", func() {
f := framework.NewFramework("operator-cert-config-test")

BeforeEach(func() {
aaqBackup, err = utils.GetAAQ(f)
aaqBackup, err = utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -393,7 +393,7 @@ var _ = Describe("ALL Operator tests", func() {
}

Eventually(func() error {
cr, err := utils.GetAAQ(f)
cr, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
cr.Spec.CertConfig = &aaqv1.AAQCertConfig{
CA: &aaqv1.CertConfig{
Expand Down Expand Up @@ -501,7 +501,7 @@ var _ = Describe("ALL Operator tests", func() {
if len(list.Items) < 3 {
Skip("This test require at least 3 nodes")
}
aaq, err := utils.GetAAQ(f)
aaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
if aaq.Spec.PriorityClass != nil {
By(fmt.Sprintf("Current priority class is: [%s]", *aaq.Spec.PriorityClass))
Expand All @@ -512,7 +512,7 @@ var _ = Describe("ALL Operator tests", func() {
if aaq == nil {
return
}
cr, err := utils.GetAAQ(f)
cr, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())

cr.Spec.PriorityClass = aaq.Spec.PriorityClass
Expand Down Expand Up @@ -553,7 +553,7 @@ var _ = Describe("ALL Operator tests", func() {
})

It("should use kubernetes priority class if set", func() {
cr, err := utils.GetAAQ(f)
cr, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
By("Setting the priority class to system cluster critical, which is known to exist")
cr.Spec.PriorityClass = &systemClusterCritical
Expand Down Expand Up @@ -583,13 +583,13 @@ var _ = Describe("ALL Operator tests", func() {
f := framework.NewFramework("operator-delete-mtq-test")

BeforeEach(func() {
cr, err = utils.GetAAQ(f)
cr, err = utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
Eventually(func() error {
currCr, err := utils.GetAAQ(f)
currCr, err := utils.GetAAQ(f.AaqClient)
if err != nil {
return err
}
Expand All @@ -604,7 +604,7 @@ var _ = Describe("ALL Operator tests", func() {
MatchLabels: map[string]string{"namespace": "fakenamespace"},
}
Eventually(func() error {
currCr, err := utils.GetAAQ(f)
currCr, err := utils.GetAAQ(f.AaqClient)
if err != nil {
return err
}
Expand All @@ -630,7 +630,7 @@ var _ = Describe("ALL Operator tests", func() {
It("if namespace selector is not set, should use the default target label", func() {
By("Updating AAQ to use a nil namespace selector")
Eventually(func() error {
currCr, err := utils.GetAAQ(f)
currCr, err := utils.GetAAQ(f.AaqClient)
if err != nil {
return err
}
Expand Down Expand Up @@ -661,7 +661,7 @@ var _ = Describe("ALL Operator tests", func() {
It("if namespace selector is empty, should target any namespace", func() {
By("Updating AAQ to use a nil namespace selector")
Eventually(func() error {
currCr, err := utils.GetAAQ(f)
currCr, err := utils.GetAAQ(f.AaqClient)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tests/aaq_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("AAQ Server", func() {
})

It("should be invalid to create two AAQ instances", func() {
currentAaq, err := utils.GetAAQ(f)
currentAaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())

secondAaq := &aaqv1.AAQ{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_application_aware_cluster_resource_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = Describe("ApplicationAwareAppliedClusterResourceQuota", func() {
var labelSelector *v12.LabelSelector

BeforeEach(func() {
aaq, err := f.AaqClient.AaqV1alpha1().AAQs().Get(context.Background(), "aaq", v12.GetOptions{})
aaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
if !aaq.Spec.Configuration.AllowApplicationAwareClusterResourceQuota {
aaq.Spec.Configuration.AllowApplicationAwareClusterResourceQuota = true
Expand Down
37 changes: 19 additions & 18 deletions tests/e2e_application_aware_resource_quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
})
Expand All @@ -88,7 +88,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -109,7 +109,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status captures service creation")
usedResources = v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceServices] = resource.MustParse("2")
usedResources[v1.ResourceServicesNodePorts] = resource.MustParse("1")
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expand Down Expand Up @@ -162,7 +162,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceSecrets] = resource.MustParse(defaultSecrets)
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -203,7 +203,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -223,7 +223,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {
podToUpdate := pod

By("Ensuring ApplicationAwareResourceQuota status captures the pod usage")
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourcePods] = resource.MustParse("1")
usedResources[v1.ResourceCPU] = requests[v1.ResourceCPU]
usedResources[v1.ResourceMemory] = requests[v1.ResourceMemory]
Expand Down Expand Up @@ -275,7 +275,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {
Expect(err).ToNot(HaveOccurred())

By("Ensuring Application Aware Resource Quota status released the pod usage")
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourcePods] = resource.MustParse("0")
usedResources[v1.ResourceCPU] = resource.MustParse("0")
usedResources[v1.ResourceMemory] = resource.MustParse("0")
Expand Down Expand Up @@ -318,7 +318,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceConfigMaps] = resource.MustParse(defaultConfigMaps)
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -330,7 +330,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status captures configMap creation")
usedResources = v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceConfigMaps] = resource.MustParse(hardConfigMaps)
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -358,7 +358,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceReplicationControllers] = resource.MustParse("0")
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -407,7 +407,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceName("count/replicasets.apps")] = resource.MustParse("0")
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -446,7 +446,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourcePersistentVolumeClaims] = resource.MustParse("0")
usedResources[v1.ResourceRequestsStorage] = resource.MustParse("0")
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expand Down Expand Up @@ -488,7 +488,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourcePersistentVolumeClaims] = resource.MustParse("0")
usedResources[v1.ResourceRequestsStorage] = resource.MustParse("0")
usedResources[core.V1ResourceByStorageClass(classGold, v1.ResourcePersistentVolumeClaims)] = resource.MustParse("0")
Expand Down Expand Up @@ -560,7 +560,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated since the managed quota should be created")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
usedResources[v1.ResourceName(countResourceName)] = resource.MustParse("1")
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -1257,7 +1257,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -1297,7 +1297,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -1336,7 +1336,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -1812,7 +1812,7 @@ var _ = Describe("ApplicationAwareResourceQuota", func() {

By("Ensuring Application Aware Resource Quota status is calculated")
usedResources := v1.ResourceList{}
usedResources[v1.ResourceQuotas] = resource.MustParse(strconv.Itoa(c + 1))
usedResources["count/applicationawareresourcequotas.aaq.kubevirt.io"] = resource.MustParse(strconv.Itoa(c + 1))
err = waitForApplicationAwareResourceQuota(ctx, f.AaqClient, f.Namespace.Name, quotaName, usedResources)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -1914,6 +1914,7 @@ func newTestApplicationAwareResourceQuota(name string) *v1alpha1.ApplicationAwar
hard[core.V1ResourceByStorageClass(classGold, v1.ResourceRequestsStorage)] = resource.MustParse("10Gi")
// test quota on discovered resource type
hard[v1.ResourceName("count/replicasets.apps")] = resource.MustParse("5")
hard[v1.ResourceName("count/applicationawareresourcequotas.aaq.kubevirt.io")] = resource.MustParse("2")
// test quota on extended resource
hard[v1.ResourceName(v1.DefaultResourceRequestsPrefix+extendedResourceName)] = resource.MustParse("3")
return &v1alpha1.ApplicationAwareResourceQuota{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_mirrors_quotas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ var _ = Describe("ApplicationAwareAppliedClusterResourceQuota mirrors Applicatio
var labelSelector *v12.LabelSelector

BeforeEach(func() {
aaq, err := f.AaqClient.AaqV1alpha1().AAQs().Get(context.Background(), "aaq", v12.GetOptions{})
aaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
if !aaq.Spec.Configuration.AllowApplicationAwareClusterResourceQuota {
aaq.Spec.Configuration.AllowApplicationAwareClusterResourceQuota = true
Expand Down
20 changes: 16 additions & 4 deletions tests/e2e_plugable_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,33 @@ var _ = Describe("ApplicationAwareQuota plugable policies", func() {
Context("label-sidecar evaluator", func() {
ctx := context.Background()
BeforeEach(func() {
currAAQ, err := utils.GetAAQ(f)
currAAQ, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
if libaaq.CheckIfPlugablePolicyExistInAAQ(currAAQ, libaaq.LabelSidecar, libaaq.Double) {
return
}
Eventually(func() error {
currAAQ, err = utils.GetAAQ(f)
currAAQ, err = utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
currAAQ = libaaq.AddPlugablePolicy(currAAQ, libaaq.LabelSidecar, libaaq.Double)
_, err = f.AaqClient.AaqV1alpha1().AAQs().Update(context.Background(), currAAQ, v12.UpdateOptions{})
return err
}, 60*time.Second, 1*time.Second).ShouldNot(HaveOccurred(), "waiting for aaq policies update")

Eventually(func() bool {
return isAaqControllerReadyForAtLeast5Seconds(f.K8sClient, f.AAQInstallNs)
if isAaqControllerReadyForAtLeast5Seconds(f.K8sClient, f.AAQInstallNs) {
return true
}
aaqControllerPods := utils.GetAAQControllerPods(f.K8sClient, f.AAQInstallNs)
for _, p := range aaqControllerPods.Items {
for _, cs := range p.Status.ContainerStatuses {
if cs.Name == string(libaaq.LabelSidecar) && cs.State.Waiting != nil &&
(cs.State.Waiting.Reason == "ImagePullBackOff" || cs.State.Waiting.Reason == "ErrImagePull") {
Skip("label-sidecar doesn't exist in the current environment")
}
}
}
return false
}, 120*time.Second, 1*time.Second).Should(BeTrue(), "waiting for aaq controller to be ready for at least 5 seconds")
})

Expand All @@ -64,7 +76,7 @@ var _ = Describe("ApplicationAwareQuota plugable policies", func() {
Expect(err).ToNot(HaveOccurred())

Eventually(func() error {
aaq, err := utils.GetAAQ(f)
aaq, err := utils.GetAAQ(f.AaqClient)
Expect(err).ToNot(HaveOccurred())
aaq.Spec.Configuration.SidecarEvaluators = []v1.Container{}
aaq = libaaq.AddPlugablePolicy(aaq, libaaq.LabelSidecar, libaaq.Triple)
Expand Down
Loading

0 comments on commit b9f5bc9

Please sign in to comment.