in pkg/common/utils/utils.go [152:214]
func GetApplicationIDFromPod(pod *v1.Pod) string {
// SchedulerName needs to match
if strings.Compare(pod.Spec.SchedulerName, constants.SchedulerName) != 0 {
return ""
}
// If pod was tagged with ignore-application and plugin mode is active, return
if pluginMode {
if value := GetPodAnnotationValue(pod, constants.AnnotationIgnoreApplication); value != "" {
ignore, err := strconv.ParseBool(value)
if err != nil {
log.Log(log.ShimUtils).Warn("Failed to parse annotation "+constants.AnnotationIgnoreApplication, zap.Error(err))
} else if ignore {
return ""
}
}
}
// Application ID can be defined in multiple places
// The application ID is determined by the following order.
// 1. Label: constants.CanonicalLabelApplicationID
// 2. Annotation: constants.AnnotationApplicationID
// 3. Label: constants.LabelApplicationID
// 4. Label: constants.SparkLabelAppID
appID := GetPodLabelValue(pod, constants.CanonicalLabelApplicationID)
if appID == "" {
appID = GetPodAnnotationValue(pod, constants.AnnotationApplicationID)
}
if appID == "" {
labelKeys := []string{
constants.LabelApplicationID,
constants.SparkLabelAppID,
}
for _, label := range labelKeys {
appID = GetPodLabelValue(pod, label)
if appID != "" {
break
}
}
}
// If plugin mode, interpret missing Application ID as a non-YuniKorn pod
if pluginMode && appID == "" {
return ""
}
// does appID end with '-uniqueautogen'?
if strings.HasSuffix(appID, uniqueAutogenSuffix) {
// replace suffix with pod UID
appID = fmt.Sprintf("%s-%s", strings.TrimSuffix(appID, uniqueAutogenSuffix), string(pod.UID))
}
// if app ID is not empty, return it
if appID != "" {
return appID
}
// Standard deployment mode, so we need a valid Application ID to proceed. Generate one now.
return GenerateApplicationID(pod.Namespace, conf.GetSchedulerConf().GenerateUniqueAppIds, string(pod.UID))
}