forked from openshift/insights-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkloads_gatherer.go
57 lines (47 loc) · 1.44 KB
/
workloads_gatherer.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
55
56
57
package workloads
import (
"context"
"time"
"k8s.io/client-go/rest"
"github.com/openshift/insights-operator/pkg/gatherers"
"github.com/openshift/insights-operator/pkg/record"
"github.com/openshift/insights-operator/pkg/utils"
)
var workloadsGathererPeriod = time.Hour * 12
type Gatherer struct {
gatherKubeConfig *rest.Config
gatherProtoKubeConfig *rest.Config
lastProcessingTime time.Time
runtimeExtractorEnabled bool
}
func New(gatherKubeConfig, gatherProtoKubeConfig *rest.Config, runtimeExtractorEnabled bool) *Gatherer {
return &Gatherer{
gatherKubeConfig: gatherKubeConfig,
gatherProtoKubeConfig: gatherProtoKubeConfig,
lastProcessingTime: time.Unix(0, 0),
runtimeExtractorEnabled: runtimeExtractorEnabled,
}
}
func (g *Gatherer) GetName() string {
return "workloads"
}
func (g *Gatherer) GetGatheringFunctions(context.Context) (map[string]gatherers.GatheringClosure, error) {
return map[string]gatherers.GatheringClosure{
"workload_info": {
Run: func(ctx context.Context) ([]record.Record, []error) {
return g.GatherWorkloadInfo(ctx)
},
},
"helmchart_info": {
Run: func(ctx context.Context) ([]record.Record, []error) {
return g.GatherHelmInfo(ctx)
},
},
}, nil
}
func (g *Gatherer) ShouldBeProcessedNow() bool {
return utils.ShouldBeProcessedNow(g.lastProcessingTime, workloadsGathererPeriod)
}
func (g *Gatherer) UpdateLastProcessingTime() {
g.lastProcessingTime = time.Now()
}