chenyulin0719 commented on code in PR #900:
URL: https://github.com/apache/yunikorn-k8shim/pull/900#discussion_r1733208904
##########
pkg/common/utils/utils.go:
##########
@@ -213,6 +213,51 @@ func GetApplicationIDFromPod(pod *v1.Pod) string {
return GenerateApplicationID(pod.Namespace,
conf.GetSchedulerConf().GenerateUniqueAppIds, string(pod.UID))
}
+func CheckAppIdInPod(pod *v1.Pod) error {
+ 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 {
+ 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
+}
+
+// return true if all non-empty values are same across all provided
label/annotation
+func ValidatePodLabelAnnotation(pod *v1.Pod, labelKeys []string,
annotationKeys []string) error {
+ var referenceValue string
+
+ for _, key := range labelKeys {
+ value := GetPodLabelValue(pod, key)
+ if value == "" {
+ continue
+ }
+ if referenceValue == "" {
+ referenceValue = value
+ } else if referenceValue != value {
+ return fmt.Errorf("inconsistent values: %s, %s",
referenceValue, value)
+ }
Review Comment:
@ryankert01 Thanks for the review. The earily empty check is required(Line
236~238), and the example you provided is logically different.
For example, if there are 3 values: "", "dummy", ""
-> my version will return nil. (means no conflicting metadata)
-> your version will return an error
loop 1, referenceValue = "", value =""
loop 2, referenceValue ="", value ="dummy" , referenceValue != value, so
return an error
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]