-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add webhook vaildate the vpc resource whether can be deleted. (#1423)
- Loading branch information
Showing
4 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package webhook | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
ovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" | ||
) | ||
|
||
func (v *ValidatingHook) VpcDeleteHook(ctx context.Context, req admission.Request) admission.Response { | ||
vpc := ovnv1.Vpc{} | ||
if err := v.decoder.DecodeRaw(req.OldObject, &vpc); err != nil { | ||
return ctrlwebhook.Errored(http.StatusBadRequest, err) | ||
} | ||
if 0 != len(vpc.Status.Subnets) { | ||
err := fmt.Errorf("can't delete vpc when any subnet in the vpc") | ||
return ctrlwebhook.Denied(err.Error()) | ||
} | ||
return ctrlwebhook.Allowed("by pass") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters