@@ -1451,10 +1451,10 @@ func stopCollectingMetrics(tCtx ktesting.TContext, collectorCtx ktesting.TContex
1451
1451
}
1452
1452
1453
1453
type WorkloadExecutor struct {
1454
- tCtx * ktesting.TContext
1455
- wg * sync.WaitGroup
1456
- collectorCtx * ktesting.TContext
1457
- collectorWG * sync.WaitGroup
1454
+ tCtx ktesting.TContext
1455
+ wg sync.WaitGroup
1456
+ collectorCtx ktesting.TContext
1457
+ collectorWG sync.WaitGroup
1458
1458
collectors []testDataCollector
1459
1459
dataItems []DataItem
1460
1460
numPodsScheduledPerNamespace map [string ]int
@@ -1511,10 +1511,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1511
1511
defer collectorWG .Wait ()
1512
1512
1513
1513
executor := WorkloadExecutor {
1514
- tCtx : & tCtx ,
1515
- wg : & wg ,
1516
- collectorCtx : & collectorCtx ,
1517
- collectorWG : & collectorWG ,
1514
+ tCtx : tCtx ,
1515
+ wg : wg ,
1516
+ collectorCtx : collectorCtx ,
1517
+ collectorWG : collectorWG ,
1518
1518
collectors : collectors ,
1519
1519
numPodsScheduledPerNamespace : make (map [string ]int ),
1520
1520
podInformer : podInformer ,
@@ -1543,8 +1543,8 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1543
1543
executor .runCreateNamespaceOp (opIndex , concreteOp )
1544
1544
case * createPodsOp :
1545
1545
executor .runCreatePodsOp (opIndex , concreteOp )
1546
- if * executor .collectorCtx != nil {
1547
- defer ( * executor .collectorCtx ) .Cancel ("cleaning up" )
1546
+ if executor .collectorCtx != nil {
1547
+ executor .collectorCtx .Cancel ("cleaning up" )
1548
1548
}
1549
1549
case * deletePodsOp :
1550
1550
executor .runDeletePodsOp (opIndex , concreteOp )
@@ -1556,7 +1556,7 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1556
1556
executor .runSleepOp (concreteOp )
1557
1557
case * startCollectingMetricsOp :
1558
1558
executor .runStartCollectingMetricsOp (opIndex , concreteOp )
1559
- defer ( * executor .collectorCtx ) .Cancel ("cleaning up" )
1559
+ defer executor .collectorCtx .Cancel ("cleaning up" )
1560
1560
case * stopCollectingMetricsOp :
1561
1561
executor .runStopCollectingMetrics (opIndex )
1562
1562
default :
@@ -1576,27 +1576,27 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1576
1576
}
1577
1577
1578
1578
func (e * WorkloadExecutor ) runCreateNodesOp (opIndex int , op * createNodesOp ) {
1579
- nodePreparer , err := getNodePreparer (fmt .Sprintf ("node-%d-" , opIndex ), op , ( * e .tCtx ) .Client ())
1579
+ nodePreparer , err := getNodePreparer (fmt .Sprintf ("node-%d-" , opIndex ), op , e .tCtx .Client ())
1580
1580
if err != nil {
1581
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1581
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1582
1582
}
1583
- if err := nodePreparer .PrepareNodes (* e .tCtx , e .nextNodeIndex ); err != nil {
1584
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1583
+ if err := nodePreparer .PrepareNodes (e .tCtx , e .nextNodeIndex ); err != nil {
1584
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1585
1585
}
1586
1586
e .nextNodeIndex += op .Count
1587
1587
}
1588
1588
1589
1589
func (e * WorkloadExecutor ) runCreateNamespaceOp (opIndex int , op * createNamespacesOp ) {
1590
- nsPreparer , err := newNamespacePreparer (* e .tCtx , op )
1590
+ nsPreparer , err := newNamespacePreparer (e .tCtx , op )
1591
1591
if err != nil {
1592
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1592
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1593
1593
}
1594
- if err := nsPreparer .prepare (* e .tCtx ); err != nil {
1595
- err2 := nsPreparer .cleanup (* e .tCtx )
1594
+ if err := nsPreparer .prepare (e .tCtx ); err != nil {
1595
+ err2 := nsPreparer .cleanup (e .tCtx )
1596
1596
if err2 != nil {
1597
1597
err = fmt .Errorf ("prepare: %w; cleanup: %w" , err , err2 )
1598
1598
}
1599
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1599
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1600
1600
}
1601
1601
for _ , n := range nsPreparer .namespaces () {
1602
1602
if _ , ok := e .numPodsScheduledPerNamespace [n ]; ok {
@@ -1610,20 +1610,20 @@ func (e *WorkloadExecutor) runCreateNamespaceOp(opIndex int, op *createNamespace
1610
1610
func (e * WorkloadExecutor ) runBarrierOp (opIndex int , op * barrierOp ) {
1611
1611
for _ , namespace := range op .Namespaces {
1612
1612
if _ , ok := e .numPodsScheduledPerNamespace [namespace ]; ! ok {
1613
- ( * e .tCtx ) .Fatalf ("op %d: unknown namespace %s" , opIndex , namespace )
1613
+ e .tCtx .Fatalf ("op %d: unknown namespace %s" , opIndex , namespace )
1614
1614
}
1615
1615
}
1616
1616
switch op .StageRequirement {
1617
1617
case Attempted :
1618
- if err := waitUntilPodsAttempted (* e .tCtx , e .podInformer , op .LabelSelector , op .Namespaces , e .numPodsScheduledPerNamespace ); err != nil {
1619
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1618
+ if err := waitUntilPodsAttempted (e .tCtx , e .podInformer , op .LabelSelector , op .Namespaces , e .numPodsScheduledPerNamespace ); err != nil {
1619
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1620
1620
}
1621
1621
case Scheduled :
1622
1622
// Default should be treated like "Scheduled", so handling both in the same way.
1623
1623
fallthrough
1624
1624
default :
1625
- if err := waitUntilPodsScheduled (* e .tCtx , e .podInformer , op .LabelSelector , op .Namespaces , e .numPodsScheduledPerNamespace ); err != nil {
1626
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1625
+ if err := waitUntilPodsScheduled (e .tCtx , e .podInformer , op .LabelSelector , op .Namespaces , e .numPodsScheduledPerNamespace ); err != nil {
1626
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1627
1627
}
1628
1628
// At the end of the barrier, we can be sure that there are no pods
1629
1629
// pending scheduling in the namespaces that we just blocked on.
@@ -1639,15 +1639,15 @@ func (e *WorkloadExecutor) runBarrierOp(opIndex int, op *barrierOp) {
1639
1639
1640
1640
func (e * WorkloadExecutor ) runSleepOp (op * sleepOp ) {
1641
1641
select {
1642
- case <- (* e .tCtx ).Done ():
1642
+ case <- (e .tCtx ).Done ():
1643
1643
case <- time .After (op .Duration .Duration ):
1644
1644
}
1645
1645
}
1646
1646
1647
1647
func (e * WorkloadExecutor ) runStopCollectingMetrics (opIndex int ) {
1648
- items := stopCollectingMetrics (* e .tCtx , * e .collectorCtx , e .collectorWG , e .workload .Threshold , * e .workload .ThresholdMetricSelector , opIndex , e .collectors )
1648
+ items := stopCollectingMetrics (e .tCtx , e .collectorCtx , & e .collectorWG , e .workload .Threshold , * e .workload .ThresholdMetricSelector , opIndex , e .collectors )
1649
1649
e .dataItems = append (e .dataItems , items ... )
1650
- * e .collectorCtx = nil
1650
+ e .collectorCtx = nil
1651
1651
}
1652
1652
1653
1653
func (e * WorkloadExecutor ) runCreatePodsOp (opIndex int , op * createPodsOp ) {
@@ -1656,41 +1656,44 @@ func (e *WorkloadExecutor) runCreatePodsOp(opIndex int, op *createPodsOp) {
1656
1656
if op .Namespace != nil {
1657
1657
namespace = * op .Namespace
1658
1658
}
1659
- createNamespaceIfNotPresent (* e .tCtx , namespace , & e .numPodsScheduledPerNamespace )
1659
+ createNamespaceIfNotPresent (e .tCtx , namespace , & e .numPodsScheduledPerNamespace )
1660
1660
if op .PodTemplatePath == nil {
1661
1661
op .PodTemplatePath = e .testCase .DefaultPodTemplatePath
1662
1662
}
1663
1663
1664
1664
if op .CollectMetrics {
1665
- if * e .collectorCtx != nil {
1666
- ( * e .tCtx ) .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1665
+ if e .collectorCtx != nil {
1666
+ e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1667
1667
}
1668
- * e .collectorCtx , e .collectors = startCollectingMetrics (* e .tCtx , e .collectorWG , e .podInformer , e .testCase .MetricsCollectorConfig , e .throughputErrorMargin , opIndex , namespace , []string {namespace }, nil )
1668
+ e .collectorCtx , e .collectors = startCollectingMetrics (e .tCtx , & e .collectorWG , e .podInformer , e .testCase .MetricsCollectorConfig , e .throughputErrorMargin , opIndex , namespace , []string {namespace }, nil )
1669
+ // e.collectorCtx.Cleanup(func() {
1670
+ // e.collectorCtx.Cancel("cleaning up")
1671
+ // })
1669
1672
}
1670
- if err := createPodsRapidly (* e .tCtx , namespace , op ); err != nil {
1671
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1673
+ if err := createPodsRapidly (e .tCtx , namespace , op ); err != nil {
1674
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1672
1675
}
1673
1676
switch {
1674
1677
case op .SkipWaitToCompletion :
1675
1678
// Only record those namespaces that may potentially require barriers
1676
1679
// in the future.
1677
1680
e .numPodsScheduledPerNamespace [namespace ] += op .Count
1678
1681
case op .SteadyState :
1679
- if err := createPodsSteadily (* e .tCtx , namespace , e .podInformer , op ); err != nil {
1680
- ( * e .tCtx ) .Fatalf ("op %d: %v" , opIndex , err )
1682
+ if err := createPodsSteadily (e .tCtx , namespace , e .podInformer , op ); err != nil {
1683
+ e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
1681
1684
}
1682
1685
default :
1683
- if err := waitUntilPodsScheduledInNamespace (* e .tCtx , e .podInformer , nil , namespace , op .Count ); err != nil {
1684
- ( * e .tCtx ) .Fatalf ("op %d: error in waiting for pods to get scheduled: %v" , opIndex , err )
1686
+ if err := waitUntilPodsScheduledInNamespace (e .tCtx , e .podInformer , nil , namespace , op .Count ); err != nil {
1687
+ e .tCtx .Fatalf ("op %d: error in waiting for pods to get scheduled: %v" , opIndex , err )
1685
1688
}
1686
1689
}
1687
1690
if op .CollectMetrics {
1688
1691
// CollectMetrics and SkipWaitToCompletion can never be true at the
1689
1692
// same time, so if we're here, it means that all pods have been
1690
1693
// scheduled.
1691
- items := stopCollectingMetrics (( * e .tCtx ), ( * e .collectorCtx ), e .collectorWG , e .workload .Threshold , * e .workload .ThresholdMetricSelector , opIndex , e .collectors )
1694
+ items := stopCollectingMetrics (e .tCtx , e .collectorCtx , & e .collectorWG , e .workload .Threshold , * e .workload .ThresholdMetricSelector , opIndex , e .collectors )
1692
1695
e .dataItems = append (e .dataItems , items ... )
1693
- * e .collectorCtx = nil
1696
+ e .collectorCtx = nil
1694
1697
}
1695
1698
}
1696
1699
@@ -1699,7 +1702,7 @@ func (e *WorkloadExecutor) runDeletePodsOp(opIndex int, op *deletePodsOp) {
1699
1702
1700
1703
podsToDelete , err := e .podInformer .Lister ().Pods (op .Namespace ).List (labelSelector )
1701
1704
if err != nil {
1702
- ( * e .tCtx ) .Fatalf ("op %d: error in listing pods in the namespace %s: %v" , opIndex , op .Namespace , err )
1705
+ e .tCtx .Fatalf ("op %d: error in listing pods in the namespace %s: %v" , opIndex , op .Namespace , err )
1703
1706
}
1704
1707
1705
1708
deletePods := func (opIndex int ) {
@@ -1710,13 +1713,13 @@ func (e *WorkloadExecutor) runDeletePodsOp(opIndex int, op *deletePodsOp) {
1710
1713
for i := 0 ; i < len (podsToDelete ); i ++ {
1711
1714
select {
1712
1715
case <- ticker .C :
1713
- if err := ( * e .tCtx ) .Client ().CoreV1 ().Pods (op .Namespace ).Delete (* e .tCtx , podsToDelete [i ].Name , metav1.DeleteOptions {}); err != nil {
1716
+ if err := e .tCtx .Client ().CoreV1 ().Pods (op .Namespace ).Delete (e .tCtx , podsToDelete [i ].Name , metav1.DeleteOptions {}); err != nil {
1714
1717
if errors .Is (err , context .Canceled ) {
1715
1718
return
1716
1719
}
1717
- ( * e .tCtx ) .Errorf ("op %d: unable to delete pod %v: %v" , opIndex , podsToDelete [i ].Name , err )
1720
+ e .tCtx .Errorf ("op %d: unable to delete pod %v: %v" , opIndex , podsToDelete [i ].Name , err )
1718
1721
}
1719
- case <- (* e .tCtx ).Done ():
1722
+ case <- (e .tCtx ).Done ():
1720
1723
return
1721
1724
}
1722
1725
}
@@ -1725,11 +1728,11 @@ func (e *WorkloadExecutor) runDeletePodsOp(opIndex int, op *deletePodsOp) {
1725
1728
listOpts := metav1.ListOptions {
1726
1729
LabelSelector : labelSelector .String (),
1727
1730
}
1728
- if err := ( * e .tCtx ) .Client ().CoreV1 ().Pods (op .Namespace ).DeleteCollection (* e .tCtx , metav1.DeleteOptions {}, listOpts ); err != nil {
1731
+ if err := e .tCtx .Client ().CoreV1 ().Pods (op .Namespace ).DeleteCollection (e .tCtx , metav1.DeleteOptions {}, listOpts ); err != nil {
1729
1732
if errors .Is (err , context .Canceled ) {
1730
1733
return
1731
1734
}
1732
- ( * e .tCtx ) .Errorf ("op %d: unable to delete pods in namespace %v: %v" , opIndex , op .Namespace , err )
1735
+ e .tCtx .Errorf ("op %d: unable to delete pods in namespace %v: %v" , opIndex , op .Namespace , err )
1733
1736
}
1734
1737
}
1735
1738
@@ -1751,43 +1754,43 @@ func (e *WorkloadExecutor) runChurnOp(opIndex int, op *churnOp) {
1751
1754
} else {
1752
1755
namespace = fmt .Sprintf ("namespace-%d" , opIndex )
1753
1756
}
1754
- restMapper := restmapper .NewDeferredDiscoveryRESTMapper (cacheddiscovery .NewMemCacheClient (( * e .tCtx ) .Client ().Discovery ()))
1757
+ restMapper := restmapper .NewDeferredDiscoveryRESTMapper (cacheddiscovery .NewMemCacheClient (e .tCtx .Client ().Discovery ()))
1755
1758
// Ensure the namespace exists.
1756
1759
nsObj := & v1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : namespace }}
1757
- if _ , err := ( * e .tCtx ) .Client ().CoreV1 ().Namespaces ().Create (* e .tCtx , nsObj , metav1.CreateOptions {}); err != nil && ! apierrors .IsAlreadyExists (err ) {
1758
- ( * e .tCtx ) .Fatalf ("op %d: unable to create namespace %v: %v" , opIndex , namespace , err )
1760
+ if _ , err := e .tCtx .Client ().CoreV1 ().Namespaces ().Create (e .tCtx , nsObj , metav1.CreateOptions {}); err != nil && ! apierrors .IsAlreadyExists (err ) {
1761
+ e .tCtx .Fatalf ("op %d: unable to create namespace %v: %v" , opIndex , namespace , err )
1759
1762
}
1760
1763
1761
1764
var churnFns []func (name string ) string
1762
1765
1763
1766
for i , path := range op .TemplatePaths {
1764
1767
unstructuredObj , gvk , err := getUnstructuredFromFile (path )
1765
1768
if err != nil {
1766
- ( * e .tCtx ) .Fatalf ("op %d: unable to parse the %v-th template path: %v" , opIndex , i , err )
1769
+ e .tCtx .Fatalf ("op %d: unable to parse the %v-th template path: %v" , opIndex , i , err )
1767
1770
}
1768
1771
// Obtain GVR.
1769
1772
mapping , err := restMapper .RESTMapping (gvk .GroupKind (), gvk .Version )
1770
1773
if err != nil {
1771
- ( * e .tCtx ) .Fatalf ("op %d: unable to find GVR for %v: %v" , opIndex , gvk , err )
1774
+ e .tCtx .Fatalf ("op %d: unable to find GVR for %v: %v" , opIndex , gvk , err )
1772
1775
}
1773
1776
gvr := mapping .Resource
1774
1777
// Distinguish cluster-scoped with namespaced API objects.
1775
1778
var dynRes dynamic.ResourceInterface
1776
1779
if mapping .Scope .Name () == meta .RESTScopeNameNamespace {
1777
- dynRes = ( * e .tCtx ) .Dynamic ().Resource (gvr ).Namespace (namespace )
1780
+ dynRes = e .tCtx .Dynamic ().Resource (gvr ).Namespace (namespace )
1778
1781
} else {
1779
- dynRes = ( * e .tCtx ) .Dynamic ().Resource (gvr )
1782
+ dynRes = e .tCtx .Dynamic ().Resource (gvr )
1780
1783
}
1781
1784
1782
1785
churnFns = append (churnFns , func (name string ) string {
1783
1786
if name != "" {
1784
- if err := dynRes .Delete (* e .tCtx , name , metav1.DeleteOptions {}); err != nil && ! errors .Is (err , context .Canceled ) {
1785
- ( * e .tCtx ) .Errorf ("op %d: unable to delete %v: %v" , opIndex , name , err )
1787
+ if err := dynRes .Delete (e .tCtx , name , metav1.DeleteOptions {}); err != nil && ! errors .Is (err , context .Canceled ) {
1788
+ e .tCtx .Errorf ("op %d: unable to delete %v: %v" , opIndex , name , err )
1786
1789
}
1787
1790
return ""
1788
1791
}
1789
1792
1790
- live , err := dynRes .Create (* e .tCtx , unstructuredObj , metav1.CreateOptions {})
1793
+ live , err := dynRes .Create (e .tCtx , unstructuredObj , metav1.CreateOptions {})
1791
1794
if err != nil {
1792
1795
return ""
1793
1796
}
@@ -1818,7 +1821,7 @@ func (e *WorkloadExecutor) runChurnOp(opIndex int, op *churnOp) {
1818
1821
churnFns [i ]("" )
1819
1822
}
1820
1823
count ++
1821
- case <- (* e .tCtx ).Done ():
1824
+ case <- (e .tCtx ).Done ():
1822
1825
return
1823
1826
}
1824
1827
}
@@ -1842,7 +1845,7 @@ func (e *WorkloadExecutor) runChurnOp(opIndex int, op *churnOp) {
1842
1845
retVals [i ][count % op .Number ] = churnFns [i ](retVals [i ][count % op .Number ])
1843
1846
}
1844
1847
count ++
1845
- case <- (* e .tCtx ).Done ():
1848
+ case <- (e .tCtx ).Done ():
1846
1849
return
1847
1850
}
1848
1851
}
@@ -1853,19 +1856,22 @@ func (e *WorkloadExecutor) runChurnOp(opIndex int, op *churnOp) {
1853
1856
func (e * WorkloadExecutor ) runDefaultOp (opIndex int , op realOp ) {
1854
1857
runable , ok := op .(runnableOp )
1855
1858
if ! ok {
1856
- ( * e .tCtx ) .Fatalf ("op %d: invalid op %v" , opIndex , op )
1859
+ e .tCtx .Fatalf ("op %d: invalid op %v" , opIndex , op )
1857
1860
}
1858
1861
for _ , namespace := range runable .requiredNamespaces () {
1859
- createNamespaceIfNotPresent (* e .tCtx , namespace , & e .numPodsScheduledPerNamespace )
1862
+ createNamespaceIfNotPresent (e .tCtx , namespace , & e .numPodsScheduledPerNamespace )
1860
1863
}
1861
- runable .run (* e .tCtx )
1864
+ runable .run (e .tCtx )
1862
1865
}
1863
1866
1864
1867
func (e * WorkloadExecutor ) runStartCollectingMetricsOp (opIndex int , op * startCollectingMetricsOp ) {
1865
- if * e .collectorCtx != nil {
1866
- ( * e .tCtx ) .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1868
+ if e .collectorCtx != nil {
1869
+ e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1867
1870
}
1868
- * e .collectorCtx , e .collectors = startCollectingMetrics ((* e .tCtx ), e .collectorWG , e .podInformer , e .testCase .MetricsCollectorConfig , e .throughputErrorMargin , opIndex , op .Name , op .Namespaces , op .LabelSelector )
1871
+ e .collectorCtx , e .collectors = startCollectingMetrics (e .tCtx , & e .collectorWG , e .podInformer , e .testCase .MetricsCollectorConfig , e .throughputErrorMargin , opIndex , op .Name , op .Namespaces , op .LabelSelector )
1872
+ // e.collectorCtx.Cleanup(func() {
1873
+ // collectorCtx.Cancel("cleaning up")
1874
+ // })
1869
1875
}
1870
1876
1871
1877
func createNamespaceIfNotPresent (tCtx ktesting.TContext , namespace string , podsPerNamespace * map [string ]int ) {
0 commit comments