Skip to content

Commit

Permalink
code review: change label/annotation key list to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyulin0719 committed Aug 27, 2024
1 parent 5a958b0 commit 21f9972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 6 additions & 0 deletions pkg/common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ const AutoGenAppSuffix = "autogen"

// Compression Algorithms for schedulerConfig
const GzipSuffix = "gz"

// The key list which are used to identify the application ID or queue name in pod.
var AppIdLabelKeys = []string{CanonicalLabelApplicationID, SparkLabelAppID, LabelApplicationID}
var AppIdAnnotationKeys = []string{AnnotationApplicationID}
var QueueLabelKeys = []string{CanonicalLabelQueueName, LabelQueueName}
var QueueAnnotationKeys = []string{AnnotationQueueName}
19 changes: 2 additions & 17 deletions pkg/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,29 +214,14 @@ func GetApplicationIDFromPod(pod *v1.Pod) string {
}

func CheckAppIdInPod(pod *v1.Pod) error {
appIdLabelKeys := []string{
constants.CanonicalLabelApplicationID,
constants.SparkLabelAppID,
constants.LabelApplicationID,
}
appIdAnnotationKeys := []string{
constants.AnnotationApplicationID,
}
if err := ValidatePodLabelAnnotation(pod, appIdLabelKeys, appIdAnnotationKeys); err != nil {
if err := ValidatePodLabelAnnotation(pod, constants.AppIdLabelKeys, constants.AppIdAnnotationKeys); err != nil {
return fmt.Errorf("pod has inconsistent application ID in labels and annotations. %w", err)
}
return nil
}

func CheckQueueNameInPod(pod *v1.Pod) error {
queueLabelKeys := []string{
constants.CanonicalLabelQueueName,
constants.LabelQueueName,
}
queueAnnotationKeys := []string{
constants.AnnotationQueueName,
}
if err := ValidatePodLabelAnnotation(pod, queueLabelKeys, queueAnnotationKeys); err != nil {
if err := ValidatePodLabelAnnotation(pod, constants.QueueLabelKeys, constants.QueueAnnotationKeys); err != nil {
return fmt.Errorf("pod has inconsistent queue name in labels and annotations. %w", err)
}
return nil
Expand Down

0 comments on commit 21f9972

Please sign in to comment.