Merge pull request #132625 from ylink-lfs/chore/rest_delete_utilpointer_removal

chore: remove utilpointer usage in package staging/src/k8s.io/apiserver/pkg/registry/rest/delete

Kubernetes-commit: ffa8eb89dab40c15b8393cbe3c67df0b91d490e0
This commit is contained in:
Kubernetes Publisher 2025-07-01 00:25:24 -07:00
commit 09be259d76
4 changed files with 45 additions and 45 deletions

2
go.mod
View File

@ -49,7 +49,7 @@ require (
gopkg.in/go-jose/go-jose.v2 v2.6.3
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/api v0.0.0-20250626212533-a8e4c192362f
k8s.io/apimachinery v0.0.0-20250625172236-d6651abdfec8
k8s.io/apimachinery v0.0.0-20250701035829-6af1141f1085
k8s.io/client-go v0.0.0-20250630172937-5e8db78e0499
k8s.io/component-base v0.0.0-20250627214227-48c508093cdb
k8s.io/klog/v2 v2.130.1

4
go.sum
View File

@ -299,8 +299,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20250626212533-a8e4c192362f h1:2YOP2vawF3nJH5bLqFqE7/FSCEvLx3DlRwzw8U9plho=
k8s.io/api v0.0.0-20250626212533-a8e4c192362f/go.mod h1:LeP8EGRerQcaOFKs8aGWs2rBBrJi5ByIeqfuMPuxCPk=
k8s.io/apimachinery v0.0.0-20250625172236-d6651abdfec8 h1:MsspBt/pf3hqgJCgzv8XGYLMuKtRIKq77uZ13QyJ/eU=
k8s.io/apimachinery v0.0.0-20250625172236-d6651abdfec8/go.mod h1:8gnN3W0XUgFL9P1KdRepAJFA98YuYViPoaUkwNZ1q70=
k8s.io/apimachinery v0.0.0-20250701035829-6af1141f1085 h1:WTdKiwMcJVA+3R/tMrthrvY5MSOXgPa6HAhD1E8B0ok=
k8s.io/apimachinery v0.0.0-20250701035829-6af1141f1085/go.mod h1:8gnN3W0XUgFL9P1KdRepAJFA98YuYViPoaUkwNZ1q70=
k8s.io/client-go v0.0.0-20250630172937-5e8db78e0499 h1:H1ALazQeWf1yF0qhlkwsdEvMFgUorS4vAIaB5hxw/tA=
k8s.io/client-go v0.0.0-20250630172937-5e8db78e0499/go.mod h1:S35/NV7N0qaT+n8zdnMvSHhv01b7Gh36CDzj/Ei/1G0=
k8s.io/component-base v0.0.0-20250627214227-48c508093cdb h1:/SlQXukQyfHPZgdysGd7/sFbCbkAbUIYbdU/lix9YxA=

View File

@ -27,7 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/admission"
utilpointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)
// RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes
@ -92,10 +92,10 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx context.Context, obj runtime.
// Negative values will be treated as the value `1s` on the delete path.
if gracePeriodSeconds := options.GracePeriodSeconds; gracePeriodSeconds != nil && *gracePeriodSeconds < 0 {
options.GracePeriodSeconds = utilpointer.Int64(1)
options.GracePeriodSeconds = ptr.To[int64](1)
}
if deletionGracePeriodSeconds := objectMeta.GetDeletionGracePeriodSeconds(); deletionGracePeriodSeconds != nil && *deletionGracePeriodSeconds < 0 {
objectMeta.SetDeletionGracePeriodSeconds(utilpointer.Int64(1))
objectMeta.SetDeletionGracePeriodSeconds(ptr.To[int64](1))
}
gracefulStrategy, ok := strategy.(RESTGracefulDeleteStrategy)

View File

@ -26,7 +26,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilpointer "k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)
@ -103,8 +102,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(-1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: true,
},
@ -115,8 +114,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(0),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(0),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](0),
wantGraceful: true,
wantGracefulPending: false,
},
@ -127,8 +126,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: true,
},
@ -139,8 +138,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(2),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(2),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](2),
wantGraceful: false,
wantGracefulPending: true,
},
@ -152,8 +151,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(-1),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: false,
},
@ -164,8 +163,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(0),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(0),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](0),
wantGraceful: false,
wantGracefulPending: false,
},
@ -176,8 +175,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(1),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: false,
},
@ -188,8 +187,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(2),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(2),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](2),
wantGraceful: false,
wantGracefulPending: false,
},
@ -201,8 +200,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(-1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: true,
},
@ -213,8 +212,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(0),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(0),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](0),
wantGraceful: true,
wantGracefulPending: false,
},
@ -225,8 +224,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: false,
wantGracefulPending: true,
},
@ -237,8 +236,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(2),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(2),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](2),
wantGraceful: false,
wantGracefulPending: true,
},
@ -250,8 +249,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(-1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: true,
wantGracefulPending: false,
},
@ -262,8 +261,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(0),
},
// want 0
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(0),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](0),
wantGraceful: true,
wantGracefulPending: false,
},
@ -274,8 +273,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(1),
},
// want 1
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(1),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](1),
wantGraceful: true,
wantGracefulPending: false,
},
@ -286,8 +285,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(2),
},
// want 2
wantDeletionGracePeriodSeconds: utilpointer.Int64(2),
wantGracePeriodSeconds: utilpointer.Int64(2),
wantDeletionGracePeriodSeconds: ptr.To[int64](2),
wantGracePeriodSeconds: ptr.To[int64](2),
wantGraceful: false,
wantGracefulPending: true,
},
@ -298,8 +297,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(50),
},
wantDeletionTimestamp: &now,
wantDeletionGracePeriodSeconds: utilpointer.Int64(1),
wantGracePeriodSeconds: utilpointer.Int64(50),
wantDeletionGracePeriodSeconds: ptr.To[int64](1),
wantGracePeriodSeconds: ptr.To[int64](50),
wantGraceful: true,
},
{
@ -309,8 +308,8 @@ func TestBeforeDelete(t *testing.T) {
options: makeOption(0),
},
wantDeletionTimestamp: &now,
wantDeletionGracePeriodSeconds: utilpointer.Int64(0),
wantGracePeriodSeconds: utilpointer.Int64(0),
wantDeletionGracePeriodSeconds: ptr.To[int64](0),
wantGracePeriodSeconds: ptr.To[int64](0),
wantGraceful: true,
},
}
@ -337,10 +336,11 @@ func TestBeforeDelete(t *testing.T) {
if gotGracefulPending != tt.wantGracefulPending {
t.Errorf("BeforeDelete() gotGracefulPending = %v, want %v", gotGracefulPending, tt.wantGracefulPending)
}
if !utilpointer.Int64Equal(tt.args.pod.DeletionGracePeriodSeconds, tt.wantDeletionGracePeriodSeconds) {
if !ptr.Equal(tt.args.pod.DeletionGracePeriodSeconds, tt.wantDeletionGracePeriodSeconds) {
t.Errorf("metadata.DeletionGracePeriodSeconds = %v, want %v", ptr.Deref(tt.args.pod.DeletionGracePeriodSeconds, 0), ptr.Deref(tt.wantDeletionGracePeriodSeconds, 0))
}
if !utilpointer.Int64Equal(tt.args.options.GracePeriodSeconds, tt.wantGracePeriodSeconds) {
if !ptr.Equal(tt.args.options.GracePeriodSeconds, tt.wantGracePeriodSeconds) {
t.Errorf("options.GracePeriodSeconds = %v, want %v", ptr.Deref(tt.args.options.GracePeriodSeconds, 0), ptr.Deref(tt.wantGracePeriodSeconds, 0))
}
if tt.wantDeletionTimestamp != nil {