Skip to content

Commit

Permalink
fix webhook
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
zbb88888 committed Jan 26, 2024
1 parent 7830fcd commit 63ae768
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions pkg/webhook/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

0 comments on commit 63ae768

Please sign in to comment.