github.com/kubeflow/training-operator@v1.7.0/pkg/apis/kubeflow.org/v1/xgboost_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 func addXGBoostJobDefaultingFuncs(scheme *runtime.Scheme) error { 23 return RegisterDefaults(scheme) 24 } 25 26 // setXGBoostJobDefaultPort sets the default ports for mxnet container. 27 func setXGBoostJobDefaultPort(spec *corev1.PodSpec) { 28 index := getDefaultContainerIndex(spec, XGBoostJobDefaultContainerName) 29 if ok := hasDefaultPort(spec, index, XGBoostJobDefaultPortName); !ok { 30 setDefaultPort(spec, XGBoostJobDefaultPortName, XGBoostJobDefaultPort, index) 31 } 32 } 33 34 // setXGBoostJobTypeNamesToCamelCase sets the name of all replica types from any case to correct case. 35 func setXGBoostJobTypeNamesToCamelCase(xgboostJob *XGBoostJob) { 36 replicaTypes := []ReplicaType{ 37 XGBoostJobReplicaTypeMaster, 38 XGBoostJobReplicaTypeWorker, 39 } 40 for _, replicaType := range replicaTypes { 41 setTypeNameToCamelCase(xgboostJob.Spec.XGBReplicaSpecs, replicaType) 42 } 43 } 44 45 // SetDefaults_XGBoostJob sets any unspecified values to defaults. 46 func SetDefaults_XGBoostJob(xgboostJob *XGBoostJob) { 47 // Set default cleanpod policy to None. 48 if xgboostJob.Spec.RunPolicy.CleanPodPolicy == nil { 49 xgboostJob.Spec.RunPolicy.CleanPodPolicy = CleanPodPolicyPointer(CleanPodPolicyNone) 50 } 51 52 // Update the key of MXReplicaSpecs to camel case. 53 setXGBoostJobTypeNamesToCamelCase(xgboostJob) 54 55 for _, spec := range xgboostJob.Spec.XGBReplicaSpecs { 56 // Set default replicas to 1. 57 setDefaultReplicas(spec, 1) 58 // Set default restartPolicy 59 setDefaultRestartPolicy(spec, XGBoostJobDefaultRestartPolicy) 60 // Set default port to mxnet container. 61 setXGBoostJobDefaultPort(&spec.Template.Spec) 62 } 63 }