-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
hpa.go
54 lines (45 loc) 路 1.29 KB
/
hpa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dao
import (
"context"
"fmt"
"github.com/derailed/k9s/internal"
"github.com/rs/zerolog/log"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
)
var (
_ Accessor = (*HorizontalPodAutoscaler)(nil)
_ Nuker = (*HorizontalPodAutoscaler)(nil)
)
// HorizontalPodAutoscaler represents a HPA resource model.
type HorizontalPodAutoscaler struct {
Resource
}
// List returns a collection of nodes.
func (h *HorizontalPodAutoscaler) List(ctx context.Context, ns string) ([]runtime.Object, error) {
strLabel, ok := ctx.Value(internal.KeyLabels).(string)
lsel := labels.Everything()
if sel, err := labels.ConvertSelectorToLabelsMap(strLabel); ok && err == nil {
lsel = sel.AsSelector()
}
gvrs := []string{
"autoscaling/v2beta2/horizontalpodautoscalers",
"autoscaling/v2beta1/horizontalpodautoscalers",
"autoscaling/v1/horizontalpodautoscalers",
}
for _, gvr := range gvrs {
oo, err := h.list(gvr, ns, lsel)
if err == nil && len(oo) > 0 {
return oo, nil
}
}
log.Error().Err(fmt.Errorf("No results for any known HPA versions"))
return []runtime.Object{}, nil
}
func (h *HorizontalPodAutoscaler) list(gvr, ns string, sel labels.Selector) ([]runtime.Object, error) {
oo, err := h.Factory.List(gvr, ns, true, sel)
if err != nil {
return nil, err
}
return oo, nil
}