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