in pkg/common/utils/utils.go [286:324]
func GetUserFromPod(pod *v1.Pod) (string, []string) {
if pod.Annotations[userInfoKey] != "" {
userInfoJSON := pod.Annotations[userInfoKey]
var userGroup si.UserGroupInformation
err := json.Unmarshal([]byte(userInfoJSON), &userGroup)
if err != nil {
log.Log(log.ShimUtils).Error("unable to process user info annotation", zap.Error(err))
return constants.DefaultUser, nil
}
user := userGroup.User
groups := userGroup.Groups
if user == "" {
log.Log(log.ShimUtils).Warn("got empty username, using default")
user = constants.DefaultUser
}
log.Log(log.ShimUtils).Info("found user info from pod annotations",
zap.String("username", user), zap.Strings("groups", groups))
return user, groups
}
// Label is processed for backwards compatibility
userLabelKey := conf.GetSchedulerConf().UserLabelKey
// UserLabelKey should not be empty
if len(userLabelKey) == 0 {
userLabelKey = constants.DefaultUserLabel
}
// User name to be defined in labels
if username := GetPodLabelValue(pod, userLabelKey); username != "" && len(username) > 0 {
log.Log(log.ShimUtils).Info("Found user name from pod labels.",
zap.String("userLabel", userLabelKey), zap.String("user", username))
return username, nil
}
value := constants.DefaultUser
log.Log(log.ShimUtils).Debug("Unable to retrieve user name from pod labels. Empty user label",
zap.String("userLabel", userLabelKey))
return value, nil
}