Skip to content

Commit

Permalink
feat: use the config's scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 6, 2024
1 parent 4ce4113 commit 1ce87f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 11 additions & 6 deletions connection/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// +kubebuilder:object:generate=true
type ExecConnections struct {
FromConfigItem string `yaml:"fromConfigItem,omitempty" json:"fromConfigItem,omitempty" template:"true"`
FromConfigItem *string `yaml:"fromConfigItem,omitempty" json:"fromConfigItem,omitempty" template:"true"`

Kubernetes *KubernetesConnection `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty"`
AWS *AWSConnection `yaml:"aws,omitempty" json:"aws,omitempty"`
Expand Down Expand Up @@ -67,21 +67,26 @@ aws_secret_access_key = {{.SecretKey.ValueStatic}}
kubernetesConfigTemplate = textTemplate.Must(textTemplate.New("").Parse(`{{.KubeConfig.ValueStatic}}`))
}

// SetupCConnections creates the necessary credential files and injects env vars
// SetupConnections creates the necessary credential files and injects env vars
// into the cmd
func SetupConnection(ctx context.Context, connections ExecConnections, cmd *osExec.Cmd) (func() error, error) {
var cleaner = func() error {
return nil
}

if connections.FromConfigItem != "" {
if lo.FromPtr(connections.FromConfigItem) != "" {
var configItem models.ConfigItem
if err := ctx.DB().Where("id = ?", connections.FromConfigItem).First(&configItem).Error; err != nil {
return nil, fmt.Errorf("failed to get config (%s): %w", connections.FromConfigItem, err)
if err := ctx.DB().Where("id = ?", *connections.FromConfigItem).First(&configItem).Error; err != nil {
return nil, fmt.Errorf("failed to get config (%s): %w", *connections.FromConfigItem, err)
}

if lo.FromPtr(configItem.Type) != "MissionControl::ScrapeConfig" {
return nil, fmt.Errorf("provided config item (type=%s) cannot be used to populate connection. must be a MissionControl::ScrapeConfig", lo.FromPtr(configItem.Type))
var scrapeConfig models.ConfigItem
if err := ctx.DB().Where("id = ?", lo.FromPtr(configItem.ScraperID)).First(&scrapeConfig).Error; err != nil {
return nil, fmt.Errorf("failed to get scraper config (%s): %w", lo.FromPtr(configItem.ScraperID), err)
}

configItem = scrapeConfig
}

if config, err := configItem.ConfigJSONStringMap(); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions connection/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ce87f3

Please sign in to comment.