| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package kubemodel
- import (
- "fmt"
- "time"
- "github.com/opencost/opencost/core/pkg/env"
- ocexporter "github.com/opencost/opencost/core/pkg/opencost/exporter"
- "github.com/opencost/opencost/core/pkg/storage"
- "github.com/opencost/opencost/core/pkg/util/timeutil"
- )
- var (
- exportInterval = 5 * time.Minute
- janitorInterval = timeutil.Day
- )
- // Pipeline manages the KubeModel export controller group and the retention janitor.
- type Pipeline struct {
- controllers *ocexporter.PipelineExportControllers
- janitor *Janitor
- }
- // NewPipeline creates a new pipeline with preset settings
- func NewPipeline(appName, clusterUID string, store storage.Storage, cm ocexporter.ComputePipelineSource) (*Pipeline, error) {
- if store == nil {
- return nil, fmt.Errorf("NewPipeline: store cannot be nil")
- }
- if clusterUID == "" {
- return nil, fmt.Errorf("NewPipeline: clusterUID cannot be empty")
- }
- config := ocexporter.NewPipelinesExportConfig(appName, clusterUID, "", false, env.GetExportKubeModel())
- controllers := ocexporter.NewPipelineExportControllers(store, cm, config)
- return &Pipeline{
- controllers: controllers,
- janitor: NewJanitor(store, appName, clusterUID, config.KubeModelPipelineResolutions),
- }, nil
- }
- // Start launches the export controllers and the retention janitor.
- func (p *Pipeline) Start() {
- p.controllers.Start(exportInterval)
- p.janitor.Start(janitorInterval)
- }
- // Stop halts the export controllers and the retention janitor.
- func (p *Pipeline) Stop() {
- p.controllers.Stop()
- p.janitor.Stop()
- }
|