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

Commit 8c72289

Browse files
committed
Make faciilty and metro mutable
Signed-off-by: Chris Privitere <[email protected]>
1 parent e71691b commit 8c72289

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

api/v1beta1/packetcluster_webhook.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ func (c *PacketCluster) Default() {
4747
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
4848
func (c *PacketCluster) ValidateCreate() error {
4949
clusterlog.Info("validate create", "name", c.Name)
50+
allErrs := field.ErrorList{}
51+
52+
// Must have either one of Metro or Facility
53+
if len(c.Spec.Facility) == 0 && len(c.Spec.Metro) == 0 {
54+
allErrs = append(allErrs,
55+
field.Invalid(field.NewPath("spec", "Metro"),
56+
c.Spec.Metro, "field is required when Facility is not set"),
57+
)
58+
}
59+
60+
// If both Metro and Facility are set, ignore Facility, we'll leave this to
61+
// the controller to deal with - the facility will need to reside in the
62+
// metro.
63+
64+
if len(allErrs) > 0 {
65+
return apierrors.NewInvalid(GroupVersion.WithKind("PacketCluster").GroupKind(), c.Name, allErrs)
66+
}
5067

5168
return nil
5269
}
@@ -64,20 +81,6 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) error {
6481
)
6582
}
6683

67-
if !reflect.DeepEqual(c.Spec.Facility, old.Spec.Facility) {
68-
allErrs = append(allErrs,
69-
field.Invalid(field.NewPath("spec", "Facility"),
70-
c.Spec.Facility, "field is immutable"),
71-
)
72-
}
73-
74-
if !reflect.DeepEqual(c.Spec.Metro, old.Spec.Metro) {
75-
allErrs = append(allErrs,
76-
field.Invalid(field.NewPath("spec", "Metro"),
77-
c.Spec.Metro, "field is immutable"),
78-
)
79-
}
80-
8184
if !reflect.DeepEqual(c.Spec.VIPManager, old.Spec.VIPManager) {
8285
allErrs = append(allErrs,
8386
field.Invalid(field.NewPath("spec", "VIPManager"),
@@ -93,11 +96,6 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) error {
9396
)
9497
}
9598

96-
// If both Metro and Facility are set, ignore Facility
97-
if len(c.Spec.Facility) > 0 && len(c.Spec.Metro) > 0 {
98-
clusterlog.Info("Metro and Facility are both set, ignoring Facility.")
99-
}
100-
10199
if len(allErrs) == 0 {
102100
return nil
103101
}

0 commit comments

Comments
 (0)