@@ -42,6 +42,15 @@ func (m *PacketMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
42
42
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
43
43
func (m * PacketMachine ) ValidateCreate () error {
44
44
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
+ }
45
54
46
55
return nil
47
56
}
@@ -65,11 +74,6 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
65
74
"failed to convert old PacketMachine to unstructured object" )))
66
75
}
67
76
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
-
73
77
newPacketMachineSpec , _ := newPacketMachine ["spec" ].(map [string ]interface {})
74
78
oldPacketMachineSpec , _ := oldPacketMachine ["spec" ].(map [string ]interface {})
75
79
@@ -81,6 +85,14 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
81
85
delete (oldPacketMachineSpec , "tags" )
82
86
delete (newPacketMachineSpec , "tags" )
83
87
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
+
84
96
if ! reflect .DeepEqual (oldPacketMachineSpec , newPacketMachineSpec ) {
85
97
allErrs = append (allErrs ,
86
98
field .Invalid (field .NewPath ("spec" ),
0 commit comments