Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 7, 2024
1 parent c86398f commit 9306990
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions connection/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
osExec "os/exec"
"path/filepath"
"strings"

"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/context"
Expand Down Expand Up @@ -90,10 +89,7 @@ func SetupConnection(ctx context.Context, connections ExecConnections, cmd *osEx
if err := ctx.DB().Where("id = ?", lo.FromPtr(configItem.ScraperID)).First(&scrapeConfig).Error; err != nil {
return nil, fmt.Errorf("failed to get scrapeconfig (%s): %w", lo.FromPtr(configItem.ScraperID), err)
}

// TODO: get the namespace directly after https://github.com/flanksource/duty/pull/1182
splits := strings.SplitN(scrapeConfig.Name, "/", 2)
scraperNamespace = splits[0]
scraperNamespace = scrapeConfig.Namespace

if err := json.Unmarshal([]byte(scrapeConfig.Spec), &scraperSpec); err != nil {
return nil, fmt.Errorf("unable to unmarshal scrapeconfig spec (id=%s)", *configItem.ScraperID)
Expand All @@ -112,16 +108,21 @@ func SetupConnection(ctx context.Context, connections ExecConnections, cmd *osEx
return nil, err
}

ctx = ctx.WithNamespace(scraperNamespace)
if err := connections.Kubernetes.Populate(ctx.WithNamespace(scraperNamespace)); err != nil {
return nil, fmt.Errorf("failed to hydrate kubernetes connection: %w", err)
}

break
}
}
}
}

if connections.Kubernetes != nil {
if err := connections.Kubernetes.Populate(ctx); err != nil {
return nil, fmt.Errorf("failed to hydrate kubernetes connection: %w", err)
if lo.FromPtr(connections.FromConfigItem) == "" {
if err := connections.Kubernetes.Populate(ctx); err != nil {
return nil, fmt.Errorf("failed to hydrate kubernetes connection: %w", err)
}
}

configPath, err := saveConfig(kubernetesConfigTemplate, connections.Kubernetes)
Expand Down

0 comments on commit 9306990

Please sign in to comment.