@@ -45,10 +45,7 @@ func initContainerPos(container string, pod *corev1.Pod) int {
4545}
4646
4747var FilterTerminatingContainers = func (p * corev1.Pod , c * corev1.Container ) bool {
48- if IsPodTerminating (p ) {
49- return true
50- }
51- return false
48+ return IsPodTerminating (p )
5249}
5350
5451var FilterNonRunningContainers = func (p * corev1.Pod , c * corev1.Container ) bool {
@@ -108,19 +105,15 @@ func (s Selector) String() string {
108105}
109106
110107type FilterContainer func (p * corev1.Pod , c * corev1.Container ) bool
111-
112- type SortPods func (pods []* corev1.Pod , i , j int ) bool
113108type SortContainers func (containers []* SelectedPodContainer , i , j int ) bool
114109
115110type Filter interface {
116111 SelectContainers (ctx context.Context , selectors ... Selector ) ([]* SelectedPodContainer , error )
117- SelectPods (ctx context.Context , selectors ... Selector ) ([]* corev1.Pod , error )
118112}
119113
120114type filter struct {
121115 client kubectl.Client
122116
123- sortPods SortPods
124117 sortContainers SortContainers
125118}
126119
@@ -130,30 +123,13 @@ func NewFilter(client kubectl.Client) Filter {
130123 }
131124}
132125
133- func NewFilterWithSort (client kubectl.Client , sortPods SortPods , sortContainers SortContainers ) Filter {
126+ func NewFilterWithSort (client kubectl.Client , sortContainers SortContainers ) Filter {
134127 return & filter {
135128 client : client ,
136- sortPods : sortPods ,
137129 sortContainers : sortContainers ,
138130 }
139131}
140132
141- func (f * filter ) SelectPods (ctx context.Context , selectors ... Selector ) ([]* corev1.Pod , error ) {
142- retList , err := f .SelectContainers (ctx , selectors ... )
143- if err != nil {
144- return nil , err
145- }
146-
147- pods := podsFromPodContainer (retList )
148- if f .sortPods != nil {
149- sort .Slice (pods , func (i , j int ) bool {
150- return f .sortPods (pods , i , j )
151- })
152- }
153-
154- return pods , nil
155- }
156-
157133func (f * filter ) SelectContainers (ctx context.Context , selectors ... Selector ) ([]* SelectedPodContainer , error ) {
158134 retList := []* SelectedPodContainer {}
159135 for _ , s := range selectors {
@@ -205,13 +181,17 @@ func deduplicate(stack []*SelectedPodContainer) []*SelectedPodContainer {
205181 return retStack
206182}
207183
208- func podsFromPodContainer (stack []* SelectedPodContainer ) []* corev1.Pod {
184+ func PodsFromPodContainer (stack []* SelectedPodContainer ) []* corev1.Pod {
209185 retPods := []* corev1.Pod {}
210186 for _ , s := range stack {
211187 if ! containsPod (retPods , key (s .Pod .Namespace , s .Pod .Name , "" )) {
212188 retPods = append (retPods , s .Pod )
213189 }
214190 }
191+
192+ sort .Slice (retPods , func (i , j int ) bool {
193+ return SortPodsByNewest (retPods , i , j )
194+ })
215195 return retPods
216196}
217197
0 commit comments