mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Merge pull request #74447 from WanLinghao/builder_ptr_replace
Remove and replace ptr functions
This commit is contained in:
@@ -55,6 +55,7 @@ go_test(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -28,10 +28,9 @@ import (
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func boolptr(b bool) *bool { return &b }
|
||||
|
||||
func TestGetJobFromTemplate(t *testing.T) {
|
||||
// getJobFromTemplate() needs to take the job template and copy the labels and annotations
|
||||
// and other fields, and add a created-by reference.
|
||||
@@ -134,7 +133,7 @@ func TestGetParentUIDFromJob(t *testing.T) {
|
||||
{
|
||||
Kind: "CronJob",
|
||||
UID: types.UID("5ef034e0-1890-11e6-8935-42010af0003e"),
|
||||
Controller: boolptr(true),
|
||||
Controller: utilpointer.BoolPtr(true),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -158,19 +157,19 @@ func TestGroupJobsByParent(t *testing.T) {
|
||||
ownerReference1 := metav1.OwnerReference{
|
||||
Kind: "CronJob",
|
||||
UID: uid1,
|
||||
Controller: boolptr(true),
|
||||
Controller: utilpointer.BoolPtr(true),
|
||||
}
|
||||
|
||||
ownerReference2 := metav1.OwnerReference{
|
||||
Kind: "CronJob",
|
||||
UID: uid2,
|
||||
Controller: boolptr(true),
|
||||
Controller: utilpointer.BoolPtr(true),
|
||||
}
|
||||
|
||||
ownerReference3 := metav1.OwnerReference{
|
||||
Kind: "CronJob",
|
||||
UID: uid3,
|
||||
Controller: boolptr(true),
|
||||
Controller: utilpointer.BoolPtr(true),
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -46,5 +46,6 @@ go_test(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func newPod(podName string, nodeName string, label map[string]string) *v1.Pod {
|
||||
@@ -51,8 +52,8 @@ func newPod(podName string, nodeName string, label map[string]string) *v1.Pod {
|
||||
}
|
||||
|
||||
func TestIsPodUpdated(t *testing.T) {
|
||||
templateGeneration := int64Ptr(12345)
|
||||
badGeneration := int64Ptr(12345)
|
||||
templateGeneration := utilpointer.Int64Ptr(12345)
|
||||
badGeneration := utilpointer.Int64Ptr(12345)
|
||||
hash := "55555"
|
||||
labels := map[string]string{extensions.DaemonSetTemplateGenerationKey: fmt.Sprint(templateGeneration), extensions.DefaultDaemonSetUniqueLabelKey: hash}
|
||||
labelsNoHash := map[string]string{extensions.DaemonSetTemplateGenerationKey: fmt.Sprint(templateGeneration)}
|
||||
@@ -148,8 +149,8 @@ func TestCreatePodTemplate(t *testing.T) {
|
||||
hash string
|
||||
expectUniqueLabel bool
|
||||
}{
|
||||
{int64Ptr(1), "", false},
|
||||
{int64Ptr(2), "3242341807", true},
|
||||
{utilpointer.Int64Ptr(1), "", false},
|
||||
{utilpointer.Int64Ptr(2), "3242341807", true},
|
||||
}
|
||||
for _, test := range tests {
|
||||
podTemplateSpec := v1.PodTemplateSpec{}
|
||||
@@ -168,11 +169,6 @@ func TestCreatePodTemplate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func int64Ptr(i int) *int64 {
|
||||
li := int64(i)
|
||||
return &li
|
||||
}
|
||||
|
||||
func TestReplaceDaemonSetPodNodeNameNodeAffinity(t *testing.T) {
|
||||
tests := []struct {
|
||||
affinity *v1.Affinity
|
||||
|
||||
@@ -36,6 +36,7 @@ go_test(
|
||||
"//staging/src/k8s.io/api/batch/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
batch "k8s.io/api/batch/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func newJob(completionTime, failedTime metav1.Time, ttl *int32) *batch.Job {
|
||||
@@ -74,10 +75,6 @@ func durationPointer(n int) *time.Duration {
|
||||
return &s
|
||||
}
|
||||
|
||||
func int32Ptr(n int32) *int32 {
|
||||
return &n
|
||||
}
|
||||
|
||||
func TestTimeLeft(t *testing.T) {
|
||||
now := metav1.Now()
|
||||
|
||||
@@ -93,7 +90,7 @@ func TestTimeLeft(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Error case: Job unfinished",
|
||||
ttl: int32Ptr(100),
|
||||
ttl: utilpointer.Int32Ptr(100),
|
||||
since: &now.Time,
|
||||
expectErr: true,
|
||||
expectErrStr: "should not be cleaned up",
|
||||
@@ -108,21 +105,21 @@ func TestTimeLeft(t *testing.T) {
|
||||
{
|
||||
name: "Job completed now, 0s TTL",
|
||||
completionTime: now,
|
||||
ttl: int32Ptr(0),
|
||||
ttl: utilpointer.Int32Ptr(0),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(0),
|
||||
},
|
||||
{
|
||||
name: "Job completed now, 10s TTL",
|
||||
completionTime: now,
|
||||
ttl: int32Ptr(10),
|
||||
ttl: utilpointer.Int32Ptr(10),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(10),
|
||||
},
|
||||
{
|
||||
name: "Job completed 10s ago, 15s TTL",
|
||||
completionTime: metav1.NewTime(now.Add(-10 * time.Second)),
|
||||
ttl: int32Ptr(15),
|
||||
ttl: utilpointer.Int32Ptr(15),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(5),
|
||||
},
|
||||
@@ -136,21 +133,21 @@ func TestTimeLeft(t *testing.T) {
|
||||
{
|
||||
name: "Job failed now, 0s TTL",
|
||||
failedTime: now,
|
||||
ttl: int32Ptr(0),
|
||||
ttl: utilpointer.Int32Ptr(0),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(0),
|
||||
},
|
||||
{
|
||||
name: "Job failed now, 10s TTL",
|
||||
failedTime: now,
|
||||
ttl: int32Ptr(10),
|
||||
ttl: utilpointer.Int32Ptr(10),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(10),
|
||||
},
|
||||
{
|
||||
name: "Job failed 10s ago, 15s TTL",
|
||||
failedTime: metav1.NewTime(now.Add(-10 * time.Second)),
|
||||
ttl: int32Ptr(15),
|
||||
ttl: utilpointer.Int32Ptr(15),
|
||||
since: &now.Time,
|
||||
expectedTimeLeft: durationPointer(5),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user