[Apiserver-extension] RESTGracefulDeleteStrategy
impl leads to nil panic #103228
Closed
Description
What happened:
Use apiserver extension(APIService) RESTGracefulDeleteStrategy
interface, impl its method CheckGracefulDelete
to gracefully control resource deletion, when the field options.GracePeriodSeconds
is nil, will lead to panic!!
What you expected to happen:
To first check if options.GracePeriodSeconds
is nil, then get its value.
How to reproduce it (as minimally and precisely as possible):
Use apiserver extension(APIService) strategy, impl this function below will lead to panic:
// just impl this method and return true, then will lead to delete resource panic
func (s Strategy) CheckGracefulDelete(ctx context.Context, obj runtime.Object, options *metav1.DeleteOptions) bool {
return true
}
Anything else we need to know?:
As the field DeleteOptions.GracePeriodSeconds
is a int64 pointer, need to be careful when init the struct.
type DeleteOptions struct {
GracePeriodSeconds *int64
Environment:
- Kubernetes version (use
kubectl version
):v1.21.0
- Cloud provider or hardware configuration:
- OS (e.g:
cat /etc/os-release
):Linux
- Kernel (e.g.
uname -a
): - Install tools:
- Network plugin and version (if this is a network-related bug):
- Others: