This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block changes to baremetalSetTemplate
This will block changes to the baremetalSetTemplate to ensure that users don't try to change attributes about the baremetal nodes that would require re-provisioning the baremetal host via metal3. Signed-off-by: Brendan Shephard <[email protected]>
- Loading branch information
Showing
4 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
tests/functional/openstackdataplanenodeset_webhook_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package functional | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
baremetalv1 "github.com/openstack-k8s-operators/openstack-baremetal-operator/api/v1beta1" | ||
) | ||
|
||
var _ = Describe("DataplaneNodeSet Webhook", func() { | ||
|
||
var dataplaneNodeSetName types.NamespacedName | ||
|
||
BeforeEach(func() { | ||
dataplaneNodeSetName = types.NamespacedName{ | ||
Name: "edpm-compute-nodeset", | ||
Namespace: namespace, | ||
} | ||
err := os.Setenv("OPERATOR_SERVICES", "../../config/services") | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
When("User tries to change forbidden items in the baremetalSetTemplate", func() { | ||
BeforeEach(func() { | ||
nodeSetSpec := DefaultDataPlaneNoNodeSetSpec() | ||
nodeSetSpec["preProvisioned"] = false | ||
nodeSetSpec["baremetalSetTemplate"] = baremetalv1.OpenStackBaremetalSetSpec{ | ||
CloudUserName: "test-user", | ||
BmhLabelSelector: map[string]string{ | ||
"app": "test-openstack", | ||
}, | ||
BaremetalHosts: map[string]baremetalv1.InstanceSpec{ | ||
"compute-0": { | ||
CtlPlaneIP: "192.168.1.12", | ||
}, | ||
}, | ||
} | ||
DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(dataplaneNodeSetName, nodeSetSpec)) | ||
}) | ||
|
||
It("Should block changes to the BmhLabelSelector object in baremetalSetTemplate spec", func() { | ||
Eventually(func(g Gomega) string { | ||
instance := GetDataplaneNodeSet(dataplaneNodeSetName) | ||
instance.Spec.BaremetalSetTemplate = baremetalv1.OpenStackBaremetalSetSpec{ | ||
CloudUserName: "new-user", | ||
BmhLabelSelector: map[string]string{ | ||
"app": "openstack1", | ||
}, | ||
} | ||
err := th.K8sClient.Update(th.Ctx, instance) | ||
return fmt.Sprintf("%s", err) | ||
}).Should(ContainSubstring("Forbidden: cannot change")) | ||
}) | ||
}) | ||
|
||
When("A user changes an allowed field in the baremetalSetTemplate", func() { | ||
BeforeEach(func() { | ||
nodeSetSpec := DefaultDataPlaneNoNodeSetSpec() | ||
nodeSetSpec["preProvisioned"] = false | ||
nodeSetSpec["baremetalSetTemplate"] = baremetalv1.OpenStackBaremetalSetSpec{ | ||
CloudUserName: "test-user", | ||
BmhLabelSelector: map[string]string{ | ||
"app": "test-openstack", | ||
}, | ||
BaremetalHosts: map[string]baremetalv1.InstanceSpec{ | ||
"compute-0": { | ||
CtlPlaneIP: "192.168.1.12", | ||
}, | ||
}, | ||
} | ||
DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(dataplaneNodeSetName, nodeSetSpec)) | ||
}) | ||
|
||
It("Should allow changes to the CloudUserName", func() { | ||
Eventually(func(g Gomega) error { | ||
instance := GetDataplaneNodeSet(dataplaneNodeSetName) | ||
instance.Spec.BaremetalSetTemplate = baremetalv1.OpenStackBaremetalSetSpec{ | ||
CloudUserName: "new-user", | ||
BmhLabelSelector: map[string]string{ | ||
"app": "test-openstack", | ||
}, | ||
BaremetalHosts: map[string]baremetalv1.InstanceSpec{ | ||
"compute-0": { | ||
CtlPlaneIP: "192.168.1.12", | ||
}, | ||
}, | ||
} | ||
return th.K8sClient.Update(th.Ctx, instance) | ||
}).Should(Succeed()) | ||
}) | ||
}) | ||
}) |