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

Commit ee680d2

Browse files
committed
Handle facility and metro being set and make a log
Signed-off-by: Chris Privitere <[email protected]>
1 parent 1baec60 commit ee680d2

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

api/v1beta1/packetcluster_webhook.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,9 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) error {
9393
)
9494
}
9595

96-
// Must not have both Metro and Facility
96+
// If both Metro and Facility are set, ignore Facility
9797
if len(c.Spec.Facility) > 0 && len(c.Spec.Metro) > 0 {
98-
allErrs = append(allErrs,
99-
field.Invalid(field.NewPath("spec", "Facility"),
100-
c.Spec.Facility, "field is mutually exclusive with Metro"),
101-
)
98+
clusterlog.Info("Metro and Facility are both set, ignoring Facility.")
10299
}
103100

104101
if len(allErrs) == 0 {

api/v1beta1/packetmachine_webhook.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,26 @@ func (m *PacketMachine) ValidateCreate() error {
4848

4949
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
5050
func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
51+
machineLog.Info("validate update", "name", m.Name)
52+
var allErrs field.ErrorList
53+
5154
newPacketMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
5255
if err != nil {
53-
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, field.ErrorList{
54-
field.InternalError(nil, errors.Wrap(err, "failed to convert new PacketMachine to unstructured object")),
55-
})
56+
allErrs = append(allErrs,
57+
field.InternalError(nil, errors.Wrap(err,
58+
"failed to convert new PacketMachine to unstructured object")))
5659
}
60+
5761
oldPacketMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
5862
if err != nil {
59-
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, field.ErrorList{
60-
field.InternalError(nil, errors.Wrap(err, "failed to convert old PacketMachine to unstructured object")),
61-
})
63+
allErrs = append(allErrs,
64+
field.InternalError(nil, errors.Wrap(err,
65+
"failed to convert old PacketMachine to unstructured object")))
6266
}
6367

64-
// Either Metro or Facility must be set, but not both
68+
// If both Metro and Facility are set, ignore Facility
6569
if m.Spec.Metro != "" && m.Spec.Facility != "" {
66-
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, field.ErrorList{
67-
field.Forbidden(field.NewPath("spec", "metro"), "cannot be set when spec.facility is set"),
68-
})
69-
} else if m.Spec.Metro == "" && m.Spec.Facility == "" {
70-
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, field.ErrorList{
71-
field.Required(field.NewPath("spec", "metro"), "must be set when spec.facility is not set"),
72-
})
70+
machineLog.Info("Metro and Facility are both set, ignoring Facility.")
7371
}
7472

7573
newPacketMachineSpec, _ := newPacketMachine["spec"].(map[string]interface{})
@@ -84,12 +82,17 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
8482
delete(newPacketMachineSpec, "tags")
8583

8684
if !reflect.DeepEqual(oldPacketMachineSpec, newPacketMachineSpec) {
87-
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, field.ErrorList{
88-
field.Forbidden(field.NewPath("spec"), "cannot be modified"),
89-
})
85+
allErrs = append(allErrs,
86+
field.Invalid(field.NewPath("spec"),
87+
m.Spec, "cannot be modified"),
88+
)
9089
}
9190

92-
return nil
91+
if len(allErrs) == 0 {
92+
return nil
93+
}
94+
95+
return apierrors.NewInvalid(GroupVersion.WithKind("PacketMachine").GroupKind(), m.Name, allErrs)
9396
}
9497

9598
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.

0 commit comments

Comments
 (0)