Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Add functional tests for in-progress nodeset webhook
Browse files Browse the repository at this point in the history
This change adds functional tests for the NodeSet webhook that checks if a Deployment is active.
This test verifies that we allow NodeSet updates with Completed deployments, while blocking
NodeSet updates on NodeSets that have in-progress Deployments.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Apr 26, 2024
1 parent cebb84c commit 4d4ab4d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/functional/openstackdataplanenodeset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"

v1beta1 "github.com/openstack-k8s-operators/dataplane-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1"
Expand All @@ -17,12 +19,17 @@ import (
var _ = Describe("DataplaneNodeSet Webhook", func() {

var dataplaneNodeSetName types.NamespacedName
var dataplaneDeploymentName types.NamespacedName

BeforeEach(func() {
dataplaneNodeSetName = types.NamespacedName{
Name: "edpm-compute-nodeset",
Namespace: namespace,
}
dataplaneDeploymentName = types.NamespacedName{
Name: "edpm-deployment",
Namespace: namespace,
}
err := os.Setenv("OPERATOR_SERVICES", "../../config/services")
Expect(err).NotTo(HaveOccurred())
})
Expand Down Expand Up @@ -181,4 +188,58 @@ var _ = Describe("DataplaneNodeSet Webhook", func() {
}).Should(ContainSubstring("already exists in another cluster"))
})
})
When("A NodeSet is updated with a OpenStackDataPlaneDeployment", func() {
BeforeEach(func() {
nodeSetSpec := DefaultDataPlaneNoNodeSetSpec(false)
nodeSetSpec["preProvisioned"] = true
nodeSetSpec["nodes"] = map[string]interface{}{
"compute-0": map[string]interface{}{
"hostName": "compute-0"},
}

DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(dataplaneNodeSetName, nodeSetSpec))
DeferCleanup(th.DeleteInstance, CreateDataplaneDeployment(dataplaneDeploymentName, DefaultDataPlaneDeploymentSpec()))
})
It("Should allow for NodeSet updates if Deployment is Completed", func() {
Eventually(func(g Gomega) error {
instance := GetDataplaneNodeSet(dataplaneNodeSetName)
instance.Spec.NodeTemplate.Ansible = v1beta1.AnsibleOpts{
AnsibleUser: "random-user",
}

deploymentReadyConditions := condition.Conditions{}
deploymentReadyConditions.MarkTrue(
condition.ReadyCondition,
condition.ReadyMessage)

instance.Status.DeploymentStatuses = make(map[string]condition.Conditions)
instance.Status.DeploymentStatuses[dataplaneDeploymentName.Name] = deploymentReadyConditions
g.Expect(th.K8sClient.Status().Update(th.Ctx, instance)).To(Succeed())

return th.K8sClient.Update(th.Ctx, instance)
}).Should(Succeed())
})
It("Should block NodeSet updates if Deployment is NOT completed", func() {
Eventually(func(g Gomega) string {
instance := GetDataplaneNodeSet(dataplaneNodeSetName)

deploymentReadyConditions := condition.Conditions{}
deploymentReadyConditions.MarkFalse(
condition.ReadyCondition,
"mock-error",
condition.SeverityWarning,
condition.ReadyMessage)

instance.Status.DeploymentStatuses = make(map[string]condition.Conditions)
instance.Status.DeploymentStatuses[dataplaneDeploymentName.Name] = deploymentReadyConditions
g.Expect(th.K8sClient.Status().Update(th.Ctx, instance)).To(Succeed())

instance.Spec.NodeTemplate.Ansible = v1beta1.AnsibleOpts{
AnsibleUser: "random-user",
}
err := th.K8sClient.Update(th.Ctx, instance)
return fmt.Sprintf("%s", err)
}).Should(ContainSubstring("could not patch openstackdataplanenodeset while openstackdataplanedeployment is running"))
})
})
})

0 comments on commit 4d4ab4d

Please sign in to comment.