github.com/kubeflow/training-operator@v1.7.0/pkg/apis/kubeflow.org/v1/tensorflow_defaults.go (about) 1 // Copyright 2018 The Kubeflow Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package v1 16 17 import ( 18 corev1 "k8s.io/api/core/v1" 19 "k8s.io/apimachinery/pkg/runtime" 20 ) 21 22 // addTensorflowDefaultingFuncs is used to register default funcs 23 func addTensorflowDefaultingFuncs(scheme *runtime.Scheme) error { 24 return RegisterDefaults(scheme) 25 } 26 27 // setTensorflowDefaultPort sets the default ports for tensorflow container. 28 func setTensorflowDefaultPort(spec *corev1.PodSpec) { 29 index := getDefaultContainerIndex(spec, TFJobDefaultContainerName) 30 if ok := hasDefaultPort(spec, index, TFJobDefaultPortName); !ok { 31 setDefaultPort(spec, TFJobDefaultPortName, TFJobDefaultPort, index) 32 } 33 } 34 35 // setTensorflowTypeNamesToCamelCase sets the name of all replica types from any case to correct case. 36 func setTensorflowTypeNamesToCamelCase(tfJob *TFJob) { 37 replicaTypes := []ReplicaType{ 38 TFJobReplicaTypePS, 39 TFJobReplicaTypeWorker, 40 TFJobReplicaTypeChief, 41 TFJobReplicaTypeMaster, 42 TFJobReplicaTypeEval, 43 } 44 for _, replicaType := range replicaTypes { 45 setTypeNameToCamelCase(tfJob.Spec.TFReplicaSpecs, replicaType) 46 } 47 } 48 49 // SetDefaults_TFJob sets any unspecified values to defaults. 50 func SetDefaults_TFJob(tfJob *TFJob) { 51 // Set default cleanpod policy to None. 52 if tfJob.Spec.RunPolicy.CleanPodPolicy == nil { 53 tfJob.Spec.RunPolicy.CleanPodPolicy = CleanPodPolicyPointer(CleanPodPolicyNone) 54 } 55 // Set default success policy to "". 56 if tfJob.Spec.SuccessPolicy == nil { 57 defaultPolicy := SuccessPolicyDefault 58 tfJob.Spec.SuccessPolicy = &defaultPolicy 59 } 60 61 // Update the key of TFReplicaSpecs to camel case. 62 setTensorflowTypeNamesToCamelCase(tfJob) 63 64 for _, spec := range tfJob.Spec.TFReplicaSpecs { 65 // Set default replicas to 1. 66 setDefaultReplicas(spec, 1) 67 // Set default restartPolicy 68 setDefaultRestartPolicy(spec, TFJobDefaultRestartPolicy) 69 // Set default port to tensorFlow container. 70 setTensorflowDefaultPort(&spec.Template.Spec) 71 } 72 }