mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
fix delete nil pointer panic
This commit is contained in:
parent
a0f9c8c277
commit
af19d7f415
@ -57,6 +57,8 @@ type GarbageCollectionDeleteStrategy interface {
|
|||||||
type RESTGracefulDeleteStrategy interface {
|
type RESTGracefulDeleteStrategy interface {
|
||||||
// CheckGracefulDelete should return true if the object can be gracefully deleted and set
|
// CheckGracefulDelete should return true if the object can be gracefully deleted and set
|
||||||
// any default values on the DeleteOptions.
|
// any default values on the DeleteOptions.
|
||||||
|
// NOTE: if return true, `options.GracePeriodSeconds` must be non-nil (nil will fail),
|
||||||
|
// that's what tells the deletion how "graceful" to be.
|
||||||
CheckGracefulDelete(ctx context.Context, obj runtime.Object, options *metav1.DeleteOptions) bool
|
CheckGracefulDelete(ctx context.Context, obj runtime.Object, options *metav1.DeleteOptions) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +128,15 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.
|
|||||||
return false, true, nil
|
return false, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `CheckGracefulDelete` will be implemented by specific strategy
|
||||||
if !gracefulStrategy.CheckGracefulDelete(ctx, obj, options) {
|
if !gracefulStrategy.CheckGracefulDelete(ctx, obj, options) {
|
||||||
return false, false, nil
|
return false, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.GracePeriodSeconds == nil {
|
||||||
|
return false, false, errors.NewInternalError(fmt.Errorf("options.GracePeriodSeconds should not be nil"))
|
||||||
|
}
|
||||||
|
|
||||||
now := metav1.NewTime(metav1.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
|
now := metav1.NewTime(metav1.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
|
||||||
objectMeta.SetDeletionTimestamp(&now)
|
objectMeta.SetDeletionTimestamp(&now)
|
||||||
objectMeta.SetDeletionGracePeriodSeconds(options.GracePeriodSeconds)
|
objectMeta.SetDeletionGracePeriodSeconds(options.GracePeriodSeconds)
|
||||||
@ -139,6 +147,7 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.
|
|||||||
if objectMeta.GetGeneration() > 0 {
|
if objectMeta.GetGeneration() > 0 {
|
||||||
objectMeta.SetGeneration(objectMeta.GetGeneration() + 1)
|
objectMeta.SetGeneration(objectMeta.GetGeneration() + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, false, nil
|
return true, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user