@@ -125,6 +125,9 @@ var (
125
125
Namespace (namespace ).
126
126
Request (className ).
127
127
Obj ()
128
+ deleteClaim = st .FromResourceClaim (claim ).
129
+ OwnerReference (podName , podUID , podKind ).
130
+ Deleting (metav1 .Now ()).Obj ()
128
131
pendingClaim = st .FromResourceClaim (claim ).
129
132
OwnerReference (podName , podUID , podKind ).
130
133
Obj ()
@@ -188,6 +191,8 @@ var (
188
191
ResourceClaims (resourceapi.ResourceClaimSchedulingStatus {Name : resourceName },
189
192
resourceapi.ResourceClaimSchedulingStatus {Name : resourceName2 }).
190
193
Obj ()
194
+ resourceSlice = st .MakeResourceSlice (nodeName , driver ).Device ("instance-1" , nil ).Obj ()
195
+ resourceSliceUpdated = st .FromResourceSlice (resourceSlice ).Device ("instance-1" , map [resourceapi.QualifiedName ]resourceapi.DeviceAttribute {attrName : {BoolValue : ptr .To (true )}}).Obj ()
191
196
)
192
197
193
198
func reserve (claim * resourceapi.ResourceClaim , pod * v1.Pod ) * resourceapi.ResourceClaim {
@@ -1499,16 +1504,16 @@ func Test_isSchedulableAfterClaimChange(t *testing.T) {
1499
1504
gotHint , err := testCtx .p .isSchedulableAfterClaimChange (logger , tc .pod , oldObj , newObj )
1500
1505
if tc .wantErr {
1501
1506
if err == nil {
1502
- t .Fatal ("expected an error, got none" )
1507
+ t .Fatal ("want an error, got none" )
1503
1508
}
1504
1509
return
1505
1510
}
1506
1511
1507
1512
if err != nil {
1508
- t .Fatalf ("expected no error, got: %v" , err )
1513
+ t .Fatalf ("want no error, got: %v" , err )
1509
1514
}
1510
1515
if tc .wantHint != gotHint {
1511
- t .Fatalf ("expected hint %#v, got %#v" , tc .wantHint , gotHint )
1516
+ t .Fatalf ("want %#v, got %#v" , tc .wantHint . String () , gotHint . String () )
1512
1517
}
1513
1518
})
1514
1519
}
@@ -1577,16 +1582,16 @@ func Test_isSchedulableAfterPodChange(t *testing.T) {
1577
1582
gotHint , err := testCtx .p .isSchedulableAfterPodChange (logger , tc .pod , nil , tc .obj )
1578
1583
if tc .wantErr {
1579
1584
if err == nil {
1580
- t .Fatal ("expected an error, got none" )
1585
+ t .Fatal ("want an error, got none" )
1581
1586
}
1582
1587
return
1583
1588
}
1584
1589
1585
1590
if err != nil {
1586
- t .Fatalf ("expected no error, got: %v" , err )
1591
+ t .Fatalf ("want no error, got: %v" , err )
1587
1592
}
1588
1593
if tc .wantHint != gotHint {
1589
- t .Fatalf ("expected hint %#v, got %#v" , tc .wantHint , gotHint )
1594
+ t .Fatalf ("want %#v, got %#v" , tc .wantHint . String () , gotHint . String () )
1590
1595
}
1591
1596
})
1592
1597
}
@@ -1716,16 +1721,121 @@ func Test_isSchedulableAfterPodSchedulingContextChange(t *testing.T) {
1716
1721
gotHint , err := testCtx .p .isSchedulableAfterPodSchedulingContextChange (logger , tc .pod , tc .oldObj , tc .newObj )
1717
1722
if tc .wantErr {
1718
1723
if err == nil {
1719
- t .Fatal ("expected an error, got none" )
1724
+ t .Fatal ("want an error, got none" )
1725
+ }
1726
+ return
1727
+ }
1728
+
1729
+ if err != nil {
1730
+ t .Fatalf ("want no error, got: %v" , err )
1731
+ }
1732
+ if tc .wantHint != gotHint {
1733
+ t .Fatalf ("want %#v, got %#v" , tc .wantHint .String (), gotHint .String ())
1734
+ }
1735
+ })
1736
+ }
1737
+ }
1738
+
1739
+ func Test_isSchedulableAfterResourceSliceChange (t * testing.T ) {
1740
+ testcases := map [string ]struct {
1741
+ pod * v1.Pod
1742
+ claims []* resourceapi.ResourceClaim
1743
+ oldObj , newObj interface {}
1744
+ wantHint framework.QueueingHint
1745
+ wantErr bool
1746
+ }{
1747
+ "queue-new-resource-slice" : {
1748
+ pod : podWithClaimName ,
1749
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1750
+ newObj : resourceSlice ,
1751
+ wantHint : framework .Queue ,
1752
+ },
1753
+ "queue1-update-resource-slice-with-claim-is-allocated" : {
1754
+ pod : podWithClaimName ,
1755
+ claims : []* resourceapi.ResourceClaim {allocatedClaim },
1756
+ oldObj : resourceSlice ,
1757
+ newObj : resourceSliceUpdated ,
1758
+ wantHint : framework .Queue ,
1759
+ },
1760
+ "queue-update-resource-slice-with-claim-is-deleting" : {
1761
+ pod : podWithClaimName ,
1762
+ claims : []* resourceapi.ResourceClaim {deleteClaim },
1763
+ oldObj : resourceSlice ,
1764
+ newObj : resourceSliceUpdated ,
1765
+ wantHint : framework .QueueSkip ,
1766
+ },
1767
+ "queue-new-resource-slice-with-two-claim" : {
1768
+ pod : podWithTwoClaimNames ,
1769
+ claims : []* resourceapi.ResourceClaim {pendingClaim , pendingClaim2 },
1770
+ oldObj : resourceSlice ,
1771
+ newObj : resourceSliceUpdated ,
1772
+ wantHint : framework .Queue ,
1773
+ },
1774
+ "queue-update-resource-slice-with-two-claim-but-one-hasn't-been-created" : {
1775
+ pod : podWithTwoClaimNames ,
1776
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1777
+ oldObj : resourceSlice ,
1778
+ newObj : resourceSliceUpdated ,
1779
+ wantHint : framework .QueueSkip ,
1780
+ },
1781
+ "queue-update-resource-slice" : {
1782
+ pod : podWithClaimName ,
1783
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1784
+ oldObj : resourceSlice ,
1785
+ newObj : resourceSliceUpdated ,
1786
+ wantHint : framework .Queue ,
1787
+ },
1788
+ "skip-not-find-resource-claim" : {
1789
+ pod : podWithClaimName ,
1790
+ claims : []* resourceapi.ResourceClaim {},
1791
+ oldObj : resourceSlice ,
1792
+ newObj : resourceSliceUpdated ,
1793
+ wantHint : framework .QueueSkip ,
1794
+ },
1795
+ "backoff-unexpected-object-with-oldObj-newObj" : {
1796
+ pod : podWithClaimName ,
1797
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1798
+ oldObj : scheduling ,
1799
+ newObj : scheduling ,
1800
+ wantErr : true ,
1801
+ },
1802
+ "backoff-unexpected-object-with-oldObj" : {
1803
+ pod : podWithClaimName ,
1804
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1805
+ oldObj : scheduling ,
1806
+ newObj : resourceSlice ,
1807
+ wantErr : true ,
1808
+ },
1809
+ "backoff-unexpected-object-with-newObj" : {
1810
+ pod : podWithClaimName ,
1811
+ claims : []* resourceapi.ResourceClaim {pendingClaim },
1812
+ oldObj : resourceSlice ,
1813
+ newObj : scheduling ,
1814
+ wantErr : true ,
1815
+ },
1816
+ }
1817
+ for name , tc := range testcases {
1818
+ tc := tc
1819
+ t .Run (name , func (t * testing.T ) {
1820
+ t .Parallel ()
1821
+ logger , _ := ktesting .NewTestContext (t )
1822
+ features := feature.Features {
1823
+ EnableDynamicResourceAllocation : true ,
1824
+ }
1825
+ testCtx := setup (t , nil , tc .claims , nil , nil , nil , features )
1826
+ gotHint , err := testCtx .p .isSchedulableAfterResourceSliceChange (logger , tc .pod , tc .oldObj , tc .newObj )
1827
+ if tc .wantErr {
1828
+ if err == nil {
1829
+ t .Fatal ("want an error, got none" )
1720
1830
}
1721
1831
return
1722
1832
}
1723
1833
1724
1834
if err != nil {
1725
- t .Fatalf ("expected no error, got: %v" , err )
1835
+ t .Fatalf ("want no error, got: %v" , err )
1726
1836
}
1727
1837
if tc .wantHint != gotHint {
1728
- t .Fatalf ("expected hint %#v, got %#v" , tc .wantHint , gotHint )
1838
+ t .Fatalf ("want %#v, got %#v" , tc .wantHint . String () , gotHint . String () )
1729
1839
}
1730
1840
})
1731
1841
}
0 commit comments