...

Source file src/k8s.io/kubernetes/pkg/api/job/warnings.go

Documentation: k8s.io/kubernetes/pkg/api/job

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package job
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	"k8s.io/apimachinery/pkg/util/validation/field"
    24  	"k8s.io/kubernetes/pkg/api/pod"
    25  	"k8s.io/kubernetes/pkg/apis/batch"
    26  	"k8s.io/kubernetes/pkg/apis/core"
    27  	"k8s.io/utils/ptr"
    28  )
    29  
    30  const (
    31  	completionsSoftLimit                        = 100_000
    32  	parallelismSoftLimitForUnlimitedCompletions = 10_000
    33  )
    34  
    35  // WarningsForJobSpec produces warnings for fields in the JobSpec.
    36  func WarningsForJobSpec(ctx context.Context, path *field.Path, spec, oldSpec *batch.JobSpec) []string {
    37  	var warnings []string
    38  	if spec.CompletionMode != nil && *spec.CompletionMode == batch.IndexedCompletion {
    39  		completions := ptr.Deref(spec.Completions, 0)
    40  		parallelism := ptr.Deref(spec.Parallelism, 0)
    41  		if completions > completionsSoftLimit && parallelism > parallelismSoftLimitForUnlimitedCompletions {
    42  			msg := "In Indexed Jobs with a number of completions higher than 10^5 and a parallelism higher than 10^4, Kubernetes might not be able to track completedIndexes when a big number of indexes fail"
    43  			warnings = append(warnings, fmt.Sprintf("%s: %s", path, msg))
    44  		}
    45  	}
    46  	var oldPodTemplate *core.PodTemplateSpec
    47  	if oldSpec != nil {
    48  		oldPodTemplate = &oldSpec.Template
    49  	}
    50  	warnings = append(warnings, pod.GetWarningsForPodTemplate(ctx, path.Child("template"), &spec.Template, oldPodTemplate)...)
    51  	return warnings
    52  }
    53  

View as plain text