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

Commit 8a02964

Browse files
committed
Update logic to only permit one of metro or facility
Signed-off-by: Chris Privitere <[email protected]>
1 parent 9433bc1 commit 8a02964

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

api/v1beta1/packetcluster_webhook.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,22 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) error {
8888
)
8989
}
9090

91-
// Must have either one of Metro or Facility
91+
// Must have at least Metro or Facility specified
9292
if len(c.Spec.Facility) == 0 && len(c.Spec.Metro) == 0 {
9393
allErrs = append(allErrs,
9494
field.Invalid(field.NewPath("spec", "Metro"),
9595
c.Spec.Metro, "field is required when Facility is not set"),
9696
)
9797
}
9898

99+
// Must have only one of Metro or Facility
100+
if len(c.Spec.Facility) > 0 && len(c.Spec.Metro) > 0 {
101+
allErrs = append(allErrs,
102+
field.Invalid(field.NewPath("spec", "Metro"),
103+
c.Spec.Metro, "field and Facility field are mutually exclusive"),
104+
)
105+
}
106+
99107
if len(allErrs) == 0 {
100108
return nil
101109
}

api/v1beta1/packetmachine_webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
6060
machineLog.Info("validate update", "name", m.Name)
6161
var allErrs field.ErrorList
6262

63+
// Must have only one of Metro or Facility specified
64+
if len(m.Spec.Facility) > 0 && len(m.Spec.Metro) > 0 {
65+
allErrs = append(allErrs,
66+
field.Invalid(field.NewPath("spec", "Metro"),
67+
m.Spec.Metro, "field and Facility field are mutually exclusive"),
68+
)
69+
}
70+
6371
newPacketMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
6472
if err != nil {
6573
allErrs = append(allErrs,

0 commit comments

Comments
 (0)