From 63ae7682a78af830bbb7442debacba77885a0ef8 Mon Sep 17 00:00:00 2001 From: bobz965 Date: Fri, 26 Jan 2024 13:48:18 +0800 Subject: [PATCH] fix webhook Signed-off-by: bobz965 --- pkg/webhook/ip.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pkg/webhook/ip.go b/pkg/webhook/ip.go index f8a1074df330..dcafef642dc0 100644 --- a/pkg/webhook/ip.go +++ b/pkg/webhook/ip.go @@ -45,19 +45,19 @@ func (v *ValidatingHook) IPUpdateHook(ctx context.Context, req admission.Request } // ip can not change these specs below - if ipNew.Spec.Namespace != ipOld.Spec.Namespace { - err := fmt.Errorf("ip %s namespace can not change", ipNew.Name) + if ipOld.Spec.Subnet != "" && ipNew.Spec.Subnet != ipOld.Spec.Subnet { + err := fmt.Errorf("ip %s subnet can not change", ipNew.Name) return ctrlwebhook.Errored(http.StatusBadRequest, err) } - if ipNew.Spec.PodName != ipOld.Spec.PodName { - err := fmt.Errorf("ip %s podName can not change", ipNew.Name) + if ipOld.Spec.Namespace != "" && ipNew.Spec.Namespace != ipOld.Spec.Namespace { + err := fmt.Errorf("ip %s namespace can not change", ipNew.Name) return ctrlwebhook.Errored(http.StatusBadRequest, err) } - if ipNew.Spec.Subnet != ipOld.Spec.Subnet { - err := fmt.Errorf("ip %s subnet can not change", ipNew.Name) + if ipOld.Spec.PodName != "" && ipNew.Spec.PodName != ipOld.Spec.PodName { + err := fmt.Errorf("ip %s podName can not change", ipNew.Name) return ctrlwebhook.Errored(http.StatusBadRequest, err) } - if ipNew.Spec.PodType != ipOld.Spec.PodType { + if ipOld.Spec.PodType != "" && ipNew.Spec.PodType != ipOld.Spec.PodType { err := fmt.Errorf("ip %s podType can not change", ipNew.Name) return ctrlwebhook.Errored(http.StatusBadRequest, err) } @@ -102,15 +102,10 @@ func (v *ValidatingHook) ValidateIP(ctx context.Context, ip *ovnv1.IP) error { } } - if ip.Spec.NodeName != "" { - // node ip skip later necessary specs check - return nil - } - - // invalid ip who has no namespace, name, subnet, podType, no need to handle it here - if ip.Spec.Namespace == "" || ip.Spec.PodName == "" || ip.Spec.Subnet == "" || ip.Spec.PodType == "" { - err := fmt.Errorf("invalid ip %s, ip spec should set namespace podName subnet podType", ip.Name) + if ip.Spec.Subnet == "" { + err := fmt.Errorf("subnet parameter cannot be empty") return err } + return nil }