|
582 | 582 | (is (= "required-cook-job-container" (.getName container))) |
583 | 583 | (is (not (set/subset? |
584 | 584 | #{"TEST_AGENT"} |
585 | | - (->> container-env (map #(.getName %)) set)))))))))) |
| 585 | + (->> container-env (map #(.getName %)) set))))))) |
| 586 | + |
| 587 | + (testing "job-labels->pod-annotations" |
| 588 | + (with-redefs [config/kubernetes (constantly {:job-label-to-pod-annotation-map {"label1" {"k1" "v1", "k2" "v2"}, |
| 589 | + "label2" {"k3" "v3", "k4" "v4"}, |
| 590 | + "label3" {"ka" "va", "kb" "vb", "kc" "vc"}}})] |
| 591 | + ; No labels |
| 592 | + (let [task-metadata {:command {:user "test-user"} |
| 593 | + :task-request {:job {:job/label []} |
| 594 | + :scalar-requests {"mem" 512 "cpus" 1.0}}}] |
| 595 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 596 | + fake-cc-config |
| 597 | + task-metadata) |
| 598 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 599 | + (is (empty? (select-keys pod-annotations ["k1", "k2", "k3", "k4", "ka", "kb", "kc"]))))) |
| 600 | + |
| 601 | + ; Single label |
| 602 | + (let [task-metadata {:command {:user "test-user"} |
| 603 | + :task-request {:job {:job/label [{:label/key "add-pod-annotation" |
| 604 | + :label/value "label1"} |
| 605 | + {:label/key "platform/baz" |
| 606 | + :label/value "qux"} |
| 607 | + {:label/key "platform/another" |
| 608 | + :label/value "included"}]} |
| 609 | + :scalar-requests {"mem" 512 "cpus" 1.0}}}] |
| 610 | + ; Simple match |
| 611 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 612 | + fake-cc-config |
| 613 | + task-metadata) |
| 614 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 615 | + (is (find pod-annotations "k1")) |
| 616 | + (is (find pod-annotations "k2")) |
| 617 | + (is (empty? (select-keys pod-annotations ["k3", "k4", "ka", "kb", "kc"])))) |
| 618 | + ; No pod-annotations |
| 619 | + (with-redefs [config/kubernetes (constantly {})] |
| 620 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 621 | + fake-cc-config |
| 622 | + task-metadata) |
| 623 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 624 | + (is (empty? (select-keys pod-annotations ["k1", "k2", "k3", "k4", "ka", "kb", "kc"])))))) |
| 625 | + ; Comma-delimited multi-match |
| 626 | + (let [task-metadata {:command {:user "test-user"} |
| 627 | + :task-request {:job {:job/label [{:label/key "add-pod-annotation" |
| 628 | + :label/value "label3,label1"}]} |
| 629 | + :scalar-requests {"mem" 512 "cpus" 1.0}}}] |
| 630 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 631 | + fake-cc-config |
| 632 | + task-metadata) |
| 633 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 634 | + (is (find pod-annotations "k1")) |
| 635 | + (is (find pod-annotations "k2")) |
| 636 | + (is (find pod-annotations "ka")) |
| 637 | + (is (find pod-annotations "kb")) |
| 638 | + (is (find pod-annotations "kc")) |
| 639 | + (is (empty? (select-keys pod-annotations ["k3", "k4"]))))) |
| 640 | + ; Comma-delimited partial-match |
| 641 | + (let [task-metadata {:command {:user "test-user"} |
| 642 | + :task-request {:job {:job/label [{:label/key "add-pod-annotation" |
| 643 | + :label/value "label2,not-yet-defined"}]} |
| 644 | + :scalar-requests {"mem" 512 "cpus" 1.0}}}] |
| 645 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 646 | + fake-cc-config |
| 647 | + task-metadata) |
| 648 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 649 | + (is (find pod-annotations "k3")) |
| 650 | + (is (find pod-annotations "k4")) |
| 651 | + (is (empty? (select-keys pod-annotations ["k1", "k2", "ka", "kb", "kc"]))))) |
| 652 | + ; No-matches |
| 653 | + (let [task-metadata {:command {:user "test-user"} |
| 654 | + :task-request {:job {:job/label [{:label/key "add-pod-annotation" |
| 655 | + :label/value "not-yet-defined"}]} |
| 656 | + :scalar-requests {"mem" 512 "cpus" 1.0}}}] |
| 657 | + (let [^V1Pod pod (api/task-metadata->pod "test-namespace" |
| 658 | + fake-cc-config |
| 659 | + task-metadata) |
| 660 | + pod-annotations (-> pod .getMetadata .getAnnotations)] |
| 661 | + (is (empty? (select-keys pod-annotations ["k1", "k2", "k3", "k4", "ka", "kb", "kc"])))))))))) |
586 | 662 |
|
587 | 663 | (defn- k8s-volume->clj [^V1Volume volume] |
588 | 664 | {:name (.getName volume) |
|
0 commit comments