ryankert01 commented on code in PR #900:
URL: https://github.com/apache/yunikorn-k8shim/pull/900#discussion_r1733248105
##########
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:
I might just misunderstand something. You're right. This version makes sense
then.
```go
if referenceValue != "" && referenceValue != value {
return fmt.Errorf("inconsistent values: %s, %s", referenceValue, value)
}
referenceValue = value
```
It's real trivial tho.
--
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]