Merge pull request #114902 from TommyStarK/pkg-apis/replace-deprecated-pointer-function

pkg/apis: Replace deprecated pointer function
This commit is contained in:
Kubernetes Prow Robot
2023-03-09 21:34:15 -08:00
committed by GitHub
29 changed files with 396 additions and 396 deletions

View File

@@ -44,7 +44,7 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
j.Parallelism = &parallelism
j.BackoffLimit = &backoffLimit
if c.Rand.Int31()%2 == 0 {
j.ManualSelector = pointer.BoolPtr(true)
j.ManualSelector = pointer.Bool(true)
} else {
j.ManualSelector = nil
}
@@ -55,7 +55,7 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
j.CompletionMode = &mode
// We're fuzzing the internal JobSpec type, not the v1 type, so we don't
// need to fuzz the nil value.
j.Suspend = pointer.BoolPtr(c.RandBool())
j.Suspend = pointer.Bool(c.RandBool())
},
func(sj *batch.CronJobSpec, c fuzz.Continue) {
c.FuzzNoCustom(sj)

View File

@@ -31,14 +31,14 @@ func SetDefaults_Job(obj *batchv1.Job) {
// For a non-parallel job, you can leave both `.spec.completions` and
// `.spec.parallelism` unset. When both are unset, both are defaulted to 1.
if obj.Spec.Completions == nil && obj.Spec.Parallelism == nil {
obj.Spec.Completions = utilpointer.Int32Ptr(1)
obj.Spec.Parallelism = utilpointer.Int32Ptr(1)
obj.Spec.Completions = utilpointer.Int32(1)
obj.Spec.Parallelism = utilpointer.Int32(1)
}
if obj.Spec.Parallelism == nil {
obj.Spec.Parallelism = utilpointer.Int32Ptr(1)
obj.Spec.Parallelism = utilpointer.Int32(1)
}
if obj.Spec.BackoffLimit == nil {
obj.Spec.BackoffLimit = utilpointer.Int32Ptr(6)
obj.Spec.BackoffLimit = utilpointer.Int32(6)
}
labels := obj.Spec.Template.Labels
if labels != nil && len(obj.Labels) == 0 {
@@ -49,7 +49,7 @@ func SetDefaults_Job(obj *batchv1.Job) {
obj.Spec.CompletionMode = &mode
}
if obj.Spec.Suspend == nil {
obj.Spec.Suspend = utilpointer.BoolPtr(false)
obj.Spec.Suspend = utilpointer.Bool(false)
}
if obj.Spec.PodFailurePolicy != nil {
for _, rule := range obj.Spec.PodFailurePolicy.Rules {
@@ -69,12 +69,12 @@ func SetDefaults_CronJob(obj *batchv1.CronJob) {
obj.Spec.ConcurrencyPolicy = batchv1.AllowConcurrent
}
if obj.Spec.Suspend == nil {
obj.Spec.Suspend = utilpointer.BoolPtr(false)
obj.Spec.Suspend = utilpointer.Bool(false)
}
if obj.Spec.SuccessfulJobsHistoryLimit == nil {
obj.Spec.SuccessfulJobsHistoryLimit = utilpointer.Int32Ptr(3)
obj.Spec.SuccessfulJobsHistoryLimit = utilpointer.Int32(3)
}
if obj.Spec.FailedJobsHistoryLimit == nil {
obj.Spec.FailedJobsHistoryLimit = utilpointer.Int32Ptr(1)
obj.Spec.FailedJobsHistoryLimit = utilpointer.Int32(1)
}
}

View File

@@ -85,11 +85,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
PodFailurePolicy: &batchv1.PodFailurePolicy{
Rules: []batchv1.PodFailurePolicyRule{
{
@@ -141,11 +141,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -160,11 +160,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -172,7 +172,7 @@ func TestSetDefaultJob(t *testing.T) {
"suspend set, everything else is defaulted": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Suspend: pointer.BoolPtr(true),
Suspend: pointer.Bool(true),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -180,11 +180,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(true),
Suspend: pointer.Bool(true),
},
},
expectLabels: true,
@@ -202,18 +202,18 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
},
"WQ: Parallelism explicitly 0 and completions unset -> BackoffLimit is defaulted": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Parallelism: pointer.Int32Ptr(0),
Parallelism: pointer.Int32(0),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -221,10 +221,10 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Parallelism: pointer.Int32Ptr(0),
BackoffLimit: pointer.Int32Ptr(6),
Parallelism: pointer.Int32(0),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -232,7 +232,7 @@ func TestSetDefaultJob(t *testing.T) {
"WQ: Parallelism explicitly 2 and completions unset -> BackoffLimit is defaulted": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Parallelism: pointer.Int32Ptr(2),
Parallelism: pointer.Int32(2),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -240,10 +240,10 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Parallelism: pointer.Int32Ptr(2),
BackoffLimit: pointer.Int32Ptr(6),
Parallelism: pointer.Int32(2),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -251,7 +251,7 @@ func TestSetDefaultJob(t *testing.T) {
"Completions explicitly 2 and others unset -> parallelism and BackoffLimit are defaulted": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(2),
Completions: pointer.Int32(2),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -259,11 +259,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(2),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(6),
Completions: pointer.Int32(2),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(6),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -271,7 +271,7 @@ func TestSetDefaultJob(t *testing.T) {
"BackoffLimit explicitly 5 and others unset -> parallelism and completions are defaulted": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
BackoffLimit: pointer.Int32Ptr(5),
BackoffLimit: pointer.Int32(5),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -279,11 +279,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(1),
Parallelism: pointer.Int32Ptr(1),
BackoffLimit: pointer.Int32Ptr(5),
Completions: pointer.Int32(1),
Parallelism: pointer.Int32(1),
BackoffLimit: pointer.Int32(5),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
},
},
expectLabels: true,
@@ -291,11 +291,11 @@ func TestSetDefaultJob(t *testing.T) {
"All set -> no change": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(8),
Parallelism: pointer.Int32Ptr(9),
BackoffLimit: pointer.Int32Ptr(10),
Completions: pointer.Int32(8),
Parallelism: pointer.Int32(9),
BackoffLimit: pointer.Int32(10),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -303,11 +303,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(8),
Parallelism: pointer.Int32Ptr(9),
BackoffLimit: pointer.Int32Ptr(10),
Completions: pointer.Int32(8),
Parallelism: pointer.Int32(9),
BackoffLimit: pointer.Int32(10),
CompletionMode: completionModePtr(batchv1.NonIndexedCompletion),
Suspend: pointer.BoolPtr(false),
Suspend: pointer.Bool(false),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -318,11 +318,11 @@ func TestSetDefaultJob(t *testing.T) {
"All set, flipped -> no change": {
original: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(11),
Parallelism: pointer.Int32Ptr(10),
BackoffLimit: pointer.Int32Ptr(9),
Completions: pointer.Int32(11),
Parallelism: pointer.Int32(10),
BackoffLimit: pointer.Int32(9),
CompletionMode: completionModePtr(batchv1.IndexedCompletion),
Suspend: pointer.BoolPtr(true),
Suspend: pointer.Bool(true),
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
},
@@ -330,11 +330,11 @@ func TestSetDefaultJob(t *testing.T) {
},
expected: &batchv1.Job{
Spec: batchv1.JobSpec{
Completions: pointer.Int32Ptr(11),
Parallelism: pointer.Int32Ptr(10),
BackoffLimit: pointer.Int32Ptr(9),
Completions: pointer.Int32(11),
Parallelism: pointer.Int32(10),
BackoffLimit: pointer.Int32(9),
CompletionMode: completionModePtr(batchv1.IndexedCompletion),
Suspend: pointer.BoolPtr(true),
Suspend: pointer.Bool(true),
},
},
expectLabels: true,
@@ -416,9 +416,9 @@ func TestSetDefaultCronJob(t *testing.T) {
expected: &batchv1.CronJob{
Spec: batchv1.CronJobSpec{
ConcurrencyPolicy: batchv1.AllowConcurrent,
Suspend: pointer.BoolPtr(false),
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(3),
FailedJobsHistoryLimit: pointer.Int32Ptr(1),
Suspend: pointer.Bool(false),
SuccessfulJobsHistoryLimit: pointer.Int32(3),
FailedJobsHistoryLimit: pointer.Int32(1),
},
},
},
@@ -426,17 +426,17 @@ func TestSetDefaultCronJob(t *testing.T) {
original: &batchv1.CronJob{
Spec: batchv1.CronJobSpec{
ConcurrencyPolicy: batchv1.ForbidConcurrent,
Suspend: pointer.BoolPtr(true),
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(5),
FailedJobsHistoryLimit: pointer.Int32Ptr(5),
Suspend: pointer.Bool(true),
SuccessfulJobsHistoryLimit: pointer.Int32(5),
FailedJobsHistoryLimit: pointer.Int32(5),
},
},
expected: &batchv1.CronJob{
Spec: batchv1.CronJobSpec{
ConcurrencyPolicy: batchv1.ForbidConcurrent,
Suspend: pointer.BoolPtr(true),
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(5),
FailedJobsHistoryLimit: pointer.Int32Ptr(5),
Suspend: pointer.Bool(true),
SuccessfulJobsHistoryLimit: pointer.Int32(5),
FailedJobsHistoryLimit: pointer.Int32(5),
},
},
},

View File

@@ -41,8 +41,8 @@ func TestSetDefaultCronJob(t *testing.T) {
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.AllowConcurrent,
Suspend: newBool(false),
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(3),
FailedJobsHistoryLimit: utilpointer.Int32Ptr(1),
SuccessfulJobsHistoryLimit: utilpointer.Int32(3),
FailedJobsHistoryLimit: utilpointer.Int32(1),
},
},
},
@@ -51,16 +51,16 @@ func TestSetDefaultCronJob(t *testing.T) {
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(5),
FailedJobsHistoryLimit: utilpointer.Int32Ptr(5),
SuccessfulJobsHistoryLimit: utilpointer.Int32(5),
FailedJobsHistoryLimit: utilpointer.Int32(5),
},
},
expected: &batchv1beta1.CronJob{
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(5),
FailedJobsHistoryLimit: utilpointer.Int32Ptr(5),
SuccessfulJobsHistoryLimit: utilpointer.Int32(5),
FailedJobsHistoryLimit: utilpointer.Int32(5),
},
},
},

View File

@@ -168,7 +168,7 @@ func TestValidateJob(t *testing.T) {
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: validPodTemplateSpecForManual,
},
},
@@ -211,8 +211,8 @@ func TestValidateJob(t *testing.T) {
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
CompletionMode: completionModePtr(batch.IndexedCompletion),
Completions: pointer.Int32Ptr(2),
Parallelism: pointer.Int32Ptr(100000),
Completions: pointer.Int32(2),
Parallelism: pointer.Int32(100000),
},
},
},
@@ -709,7 +709,7 @@ func TestValidateJob(t *testing.T) {
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"y": "z"},
@@ -730,7 +730,7 @@ func TestValidateJob(t *testing.T) {
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"controller-uid": "4d5e6f"},
@@ -751,7 +751,7 @@ func TestValidateJob(t *testing.T) {
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: validManualSelector.MatchLabels,
@@ -772,7 +772,7 @@ func TestValidateJob(t *testing.T) {
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: validManualSelector.MatchLabels,
@@ -819,8 +819,8 @@ func TestValidateJob(t *testing.T) {
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
CompletionMode: completionModePtr(batch.IndexedCompletion),
Completions: pointer.Int32Ptr(2),
Parallelism: pointer.Int32Ptr(100001),
Completions: pointer.Int32(2),
Parallelism: pointer.Int32(100001),
},
},
"metadata.annotations[batch.kubernetes.io/job-tracking]: cannot add this annotation": {
@@ -920,16 +920,16 @@ func TestValidateJobUpdate(t *testing.T) {
Spec: batch.JobSpec{
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
Parallelism: pointer.Int32Ptr(5),
ActiveDeadlineSeconds: pointer.Int64Ptr(2),
TTLSecondsAfterFinished: pointer.Int32Ptr(1),
Parallelism: pointer.Int32(5),
ActiveDeadlineSeconds: pointer.Int64(2),
TTLSecondsAfterFinished: pointer.Int32(1),
},
},
update: func(job *batch.Job) {
job.Spec.Parallelism = pointer.Int32Ptr(2)
job.Spec.ActiveDeadlineSeconds = pointer.Int64Ptr(3)
job.Spec.TTLSecondsAfterFinished = pointer.Int32Ptr(2)
job.Spec.ManualSelector = pointer.BoolPtr(true)
job.Spec.Parallelism = pointer.Int32(2)
job.Spec.ActiveDeadlineSeconds = pointer.Int64(3)
job.Spec.TTLSecondsAfterFinished = pointer.Int32(2)
job.Spec.ManualSelector = pointer.Bool(true)
},
},
"immutable completions for non-indexed jobs": {
@@ -957,7 +957,7 @@ func TestValidateJobUpdate(t *testing.T) {
},
},
update: func(job *batch.Job) {
job.Spec.Completions = pointer.Int32Ptr(1)
job.Spec.Completions = pointer.Int32(1)
},
err: &field.Error{
Type: field.ErrorTypeInvalid,
@@ -1097,7 +1097,7 @@ func TestValidateJobUpdate(t *testing.T) {
Selector: validGeneratedSelector,
Template: validPodTemplateSpecForGenerated,
CompletionMode: completionModePtr(batch.IndexedCompletion),
Completions: pointer.Int32Ptr(2),
Completions: pointer.Int32(2),
},
},
update: func(job *batch.Job) {
@@ -2025,7 +2025,7 @@ func TestValidateCronJob(t *testing.T) {
ConcurrencyPolicy: batch.AllowConcurrent,
JobTemplate: batch.JobTemplateSpec{
Spec: batch.JobSpec{
ManualSelector: pointer.BoolPtr(true),
ManualSelector: pointer.Bool(true),
Template: validPodTemplateSpec,
},
},