@@ -48,28 +48,26 @@ func (m *PacketMachine) ValidateCreate() error {
48
48
49
49
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
50
50
func (m * PacketMachine ) ValidateUpdate (old runtime.Object ) error {
51
+ machineLog .Info ("validate update" , "name" , m .Name )
52
+ var allErrs field.ErrorList
53
+
51
54
newPacketMachine , err := runtime .DefaultUnstructuredConverter .ToUnstructured (m )
52
55
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" )) )
56
59
}
60
+
57
61
oldPacketMachine , err := runtime .DefaultUnstructuredConverter .ToUnstructured (old )
58
62
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" )) )
62
66
}
63
67
64
- // Either Metro or Facility must be set, but not both
68
+ // If both Metro and Facility are set, ignore Facility
65
69
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." )
73
71
}
74
72
75
73
newPacketMachineSpec , _ := newPacketMachine ["spec" ].(map [string ]interface {})
@@ -84,12 +82,17 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) error {
84
82
delete (newPacketMachineSpec , "tags" )
85
83
86
84
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
+ )
90
89
}
91
90
92
- return nil
91
+ if len (allErrs ) == 0 {
92
+ return nil
93
+ }
94
+
95
+ return apierrors .NewInvalid (GroupVersion .WithKind ("PacketMachine" ).GroupKind (), m .Name , allErrs )
93
96
}
94
97
95
98
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
0 commit comments