@@ -1771,20 +1771,24 @@ var _ ArgumentsProvider = &Arguments{}
1771
1771
1772
1772
type Nodes map [string ]NodeStatus
1773
1773
1774
- func (in Nodes ) FindByDisplayName (name string ) * NodeStatus {
1775
- return in .Find (NodeWithDisplayName (name ))
1774
+ func (n Nodes ) FindByDisplayName (name string ) * NodeStatus {
1775
+ return n .Find (NodeWithDisplayName (name ))
1776
1776
}
1777
1777
1778
- func (in Nodes ) FindByName (name string ) * NodeStatus {
1779
- return in .Find (NodeWithName (name ))
1778
+ func (n Nodes ) FindByName (name string ) * NodeStatus {
1779
+ return n .Find (NodeWithName (name ))
1780
1780
}
1781
1781
1782
- func (in Nodes ) Any ( f func ( NodeStatus ) bool ) bool {
1783
- return in .Find (f ) != nil
1782
+ func (n Nodes ) FindByChild ( childID string ) * NodeStatus {
1783
+ return n .Find (NodeWithChild ( childID ))
1784
1784
}
1785
1785
1786
- func (in Nodes ) Find (f func (NodeStatus ) bool ) * NodeStatus {
1787
- for _ , i := range in {
1786
+ func (n Nodes ) Any (f func (NodeStatus ) bool ) bool {
1787
+ return n .Find (f ) != nil
1788
+ }
1789
+
1790
+ func (n Nodes ) Find (f func (NodeStatus ) bool ) * NodeStatus {
1791
+ for _ , i := range n {
1788
1792
if f (i ) {
1789
1793
return & i
1790
1794
}
@@ -1794,57 +1798,57 @@ func (in Nodes) Find(f func(NodeStatus) bool) *NodeStatus {
1794
1798
1795
1799
// Get a NodeStatus from the hashmap of Nodes.
1796
1800
// Return a nil along with an error if non existent.
1797
- func (in Nodes ) Get (key string ) (* NodeStatus , error ) {
1798
- val , ok := in [key ]
1801
+ func (n Nodes ) Get (key string ) (* NodeStatus , error ) {
1802
+ val , ok := n [key ]
1799
1803
if ! ok {
1800
1804
return nil , fmt .Errorf ("key was not found for %s" , key )
1801
1805
}
1802
1806
return & val , nil
1803
1807
}
1804
1808
1805
1809
// Check if the Nodes map has a key entry
1806
- func (in Nodes ) Has (key string ) bool {
1807
- _ , err := in .Get (key )
1810
+ func (n Nodes ) Has (key string ) bool {
1811
+ _ , err := n .Get (key )
1808
1812
return err == nil
1809
1813
}
1810
1814
1811
1815
// Get the Phase of a Node
1812
- func (in Nodes ) GetPhase (key string ) (* NodePhase , error ) {
1813
- val , err := in .Get (key )
1816
+ func (n Nodes ) GetPhase (key string ) (* NodePhase , error ) {
1817
+ val , err := n .Get (key )
1814
1818
if err != nil {
1815
1819
return nil , err
1816
1820
}
1817
1821
return & val .Phase , nil
1818
1822
}
1819
1823
1820
1824
// Set the status of a node by key
1821
- func (in Nodes ) Set (key string , status NodeStatus ) {
1825
+ func (n Nodes ) Set (key string , status NodeStatus ) {
1822
1826
if status .Name == "" {
1823
1827
log .Warnf ("Name was not set for key %s" , key )
1824
1828
}
1825
1829
if status .ID == "" {
1826
1830
log .Warnf ("ID was not set for key %s" , key )
1827
1831
}
1828
- _ , ok := in [key ]
1832
+ _ , ok := n [key ]
1829
1833
if ok {
1830
1834
log .Tracef ("Changing NodeStatus for %s to %+v" , key , status )
1831
1835
}
1832
- in [key ] = status
1836
+ n [key ] = status
1833
1837
}
1834
1838
1835
1839
// Delete a node from the Nodes by key
1836
- func (in Nodes ) Delete (key string ) {
1837
- has := in .Has (key )
1840
+ func (n Nodes ) Delete (key string ) {
1841
+ has := n .Has (key )
1838
1842
if ! has {
1839
1843
log .Warnf ("Trying to delete non existent key %s" , key )
1840
1844
return
1841
1845
}
1842
- delete (in , key )
1846
+ delete (n , key )
1843
1847
}
1844
1848
1845
1849
// Get the name of a node by key
1846
- func (in Nodes ) GetName (key string ) (string , error ) {
1847
- val , err := in .Get (key )
1850
+ func (n Nodes ) GetName (key string ) (string , error ) {
1851
+ val , err := n .Get (key )
1848
1852
if err != nil {
1849
1853
return "" , err
1850
1854
}
@@ -1858,6 +1862,12 @@ func NodeWithDisplayName(name string) func(n NodeStatus) bool {
1858
1862
return func (n NodeStatus ) bool { return n .DisplayName == name }
1859
1863
}
1860
1864
1865
+ func NodeWithChild (childID string ) func (n NodeStatus ) bool {
1866
+ return func (n NodeStatus ) bool {
1867
+ return n .HasChild (childID )
1868
+ }
1869
+ }
1870
+
1861
1871
func FailedPodNode (n NodeStatus ) bool {
1862
1872
return n .Type == NodeTypePod && n .Phase == NodeFailed
1863
1873
}
@@ -1867,14 +1877,14 @@ func SucceededPodNode(n NodeStatus) bool {
1867
1877
}
1868
1878
1869
1879
// Children returns the children of the parent.
1870
- func (in Nodes ) Children (parentNodeID string ) Nodes {
1880
+ func (n Nodes ) Children (parentNodeID string ) Nodes {
1871
1881
childNodes := make (Nodes )
1872
- parentNode , ok := in [parentNodeID ]
1882
+ parentNode , ok := n [parentNodeID ]
1873
1883
if ! ok {
1874
1884
return childNodes
1875
1885
}
1876
1886
for _ , childID := range parentNode .Children {
1877
- if childNode , ok := in [childID ]; ok {
1887
+ if childNode , ok := n [childID ]; ok {
1878
1888
childNodes [childID ] = childNode
1879
1889
}
1880
1890
}
@@ -1883,8 +1893,8 @@ func (in Nodes) Children(parentNodeID string) Nodes {
1883
1893
1884
1894
// NestedChildrenStatus takes in a nodeID and returns all its children, this involves a tree search using DFS.
1885
1895
// This is needed to mark all children nodes as failed for example.
1886
- func (in Nodes ) NestedChildrenStatus (parentNodeID string ) ([]NodeStatus , error ) {
1887
- parentNode , ok := in [parentNodeID ]
1896
+ func (n Nodes ) NestedChildrenStatus (parentNodeID string ) ([]NodeStatus , error ) {
1897
+ parentNode , ok := n [parentNodeID ]
1888
1898
if ! ok {
1889
1899
return nil , fmt .Errorf ("could not find %s in nodes when searching for nested children" , parentNodeID )
1890
1900
}
@@ -1896,7 +1906,7 @@ func (in Nodes) NestedChildrenStatus(parentNodeID string) ([]NodeStatus, error)
1896
1906
childNode := toexplore [0 ]
1897
1907
toexplore = toexplore [1 :]
1898
1908
for _ , nodeID := range childNode .Children {
1899
- toexplore = append (toexplore , in [nodeID ])
1909
+ toexplore = append (toexplore , n [nodeID ])
1900
1910
}
1901
1911
1902
1912
if childNode .Name == parentNode .Name {
@@ -1909,9 +1919,9 @@ func (in Nodes) NestedChildrenStatus(parentNodeID string) ([]NodeStatus, error)
1909
1919
}
1910
1920
1911
1921
// Filter returns the subset of the nodes that match the predicate, e.g. only failed nodes
1912
- func (in Nodes ) Filter (predicate func (NodeStatus ) bool ) Nodes {
1922
+ func (n Nodes ) Filter (predicate func (NodeStatus ) bool ) Nodes {
1913
1923
filteredNodes := make (Nodes )
1914
- for _ , node := range in {
1924
+ for _ , node := range n {
1915
1925
if predicate (node ) {
1916
1926
filteredNodes [node .ID ] = node
1917
1927
}
@@ -1920,9 +1930,9 @@ func (in Nodes) Filter(predicate func(NodeStatus) bool) Nodes {
1920
1930
}
1921
1931
1922
1932
// Map maps the nodes to new values, e.g. `x.Hostname`
1923
- func (in Nodes ) Map (f func (x NodeStatus ) interface {}) map [string ]interface {} {
1933
+ func (n Nodes ) Map (f func (x NodeStatus ) interface {}) map [string ]interface {} {
1924
1934
values := make (map [string ]interface {})
1925
- for _ , node := range in {
1935
+ for _ , node := range n {
1926
1936
values [node .ID ] = f (node )
1927
1937
}
1928
1938
return values
0 commit comments