volcano.sh/volcano@v1.9.0/pkg/controllers/jobflow/jobflow_controller_util.go (about) 1 /* 2 Copyright 2022 The Volcano 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 jobflow 18 19 import ( 20 "strings" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 "k8s.io/apimachinery/pkg/runtime/schema" 24 25 batch "volcano.sh/apis/pkg/apis/batch/v1alpha1" 26 ) 27 28 func getJobName(jobFlowName string, jobTemplateName string) string { 29 return jobFlowName + "-" + jobTemplateName 30 } 31 32 // GetTemplateString get the JobTemplate information string 33 func GetTemplateString(namespace, name string) string { 34 return namespace + "." + name 35 } 36 37 func isControlledBy(obj metav1.Object, gvk schema.GroupVersionKind) bool { 38 controllerRef := metav1.GetControllerOf(obj) 39 if controllerRef == nil { 40 return false 41 } 42 if controllerRef.APIVersion == gvk.GroupVersion().String() && controllerRef.Kind == gvk.Kind { 43 return true 44 } 45 return false 46 } 47 48 func getJobFlowNameByJob(job *batch.Job) string { 49 for _, owner := range job.OwnerReferences { 50 if owner.Kind == JobFlow && strings.Contains(owner.APIVersion, Volcano) { 51 return owner.Name 52 } 53 } 54 return "" 55 }