Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 9433bc1

Browse files
committed
Permit changes to facility and metro
Signed-off-by: Chris Privitere <[email protected]>
1 parent 5cf41bd commit 9433bc1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

api/v1beta1/packetmachine_webhook.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ func (m *PacketMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
4242
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
4343
func (m *PacketMachine) ValidateCreate() error {
4444
machineLog.Info("validate create", "name", m.Name)
45+
allErrs := field.ErrorList{}
46+
47+
// If both Metro and Facility are set, ignore Facility, we'll leave this to
48+
// the controller to deal with - the facility will need to reside in the
49+
// metro.
50+
51+
if len(allErrs) > 0 {
52+
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, allErrs)
53+
}
4554

4655
return nil
4756
}
@@ -65,11 +74,6 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
6574
"failed to convert old PacketMachine to unstructured object")))
6675
}
6776

68-
// If both Metro and Facility are set, ignore Facility
69-
if m.Spec.Metro != "" && m.Spec.Facility != "" {
70-
machineLog.Info("Metro and Facility are both set, ignoring Facility.")
71-
}
72-
7377
newPacketMachineSpec, _ := newPacketMachine["spec"].(map[string]interface{})
7478
oldPacketMachineSpec, _ := oldPacketMachine["spec"].(map[string]interface{})
7579

@@ -81,6 +85,14 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
8185
delete(oldPacketMachineSpec, "tags")
8286
delete(newPacketMachineSpec, "tags")
8387

88+
// allow changes to facility
89+
delete(oldPacketMachineSpec, "facility")
90+
delete(newPacketMachineSpec, "facility")
91+
92+
// allow changes to metro
93+
delete(oldPacketMachineSpec, "metro")
94+
delete(newPacketMachineSpec, "metro")
95+
8496
if !reflect.DeepEqual(oldPacketMachineSpec, newPacketMachineSpec) {
8597
allErrs = append(allErrs,
8698
field.Invalid(field.NewPath("spec"),

0 commit comments

Comments
 (0)