Skip to content

Commit

Permalink
add env variable for ingestor/grpc image (#264)
Browse files Browse the repository at this point in the history
* add env variable for ingestor/grpc image

* change bucket_name to bucket_url

* warning message for retrying connection

* typo
  • Loading branch information
jt-dd authored Sep 13, 2024
1 parent f80397e commit 57a2384
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 31 deletions.
2 changes: 1 addition & 1 deletion configs/etc/kubehound-reference.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ builder:
# ingestor:
# blob:
# # (i.e.: s3://<your-bucket>)
# bucket: ""
# bucket_url: ""
# # (i.e.: us-east-1)
# region: ""
# temp_dir: "/tmp/kubehound"
Expand Down
10 changes: 5 additions & 5 deletions configs/etc/kubehound.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ builder:

# Batch size for edge inserts
batch_size: 500

# Cluster impact batch size for edge inserts
batch_size_cluster_impact: 10

# Enable for large clusters to prevent number of edges growing exponentially
large_cluster_optimizations: true

# Ingestor configuration (for KHaaS)
ingestor:
blob:
# (i.e.: s3://<your-bucket>)
bucket: ""
bucket_url: ""
# (i.e.: us-east-1)
region: ""
region: ""
temp_dir: "/tmp/kubehound"
archive_name: "archive.tar.gz"
max_archive_size: 2147483648 # 2GB
# GRPC endpoint for the ingestor
api:
api:
endpoint: "127.0.0.1:9000"
insecure: true
6 changes: 3 additions & 3 deletions deployments/k8s/khaas/conf/ingestor/kubehound.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ collector:

# General storage configuration
storage:
# Whether or not to wipe all data on startup
# Whether or not to wipe all data on startup
wipe: false

# Number of connection retries before declaring an error
Expand Down Expand Up @@ -61,7 +61,7 @@ builder:

# Batch size for edge inserts
batch_size: 1000

# Cluster impact batch size for edge inserts
batch_size_cluster_impact: 10

Expand All @@ -70,7 +70,7 @@ builder:

ingestor:
blob:
bucket: "{{ $.Values.services.ingestor.bucket }}"
bucket_url: "{{ $.Values.services.ingestor.bucket_url }}"
region: "{{ $.Values.services.ingestor.region }}"
temp_dir: "/tmp/kubehound"
archive_name: "archive.tar.gz"
Expand Down
2 changes: 1 addition & 1 deletion deployments/k8s/khaas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
ingestor:
image: ghcr.io/datadog/kubehound-binary
version: latest
bucket: s3://<your_bucket>
bucket_url: s3://<your_bucket>
region: "us-east-1"
resources:
requests:
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/khaas-101.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ If you don't want to specify the bucket every time, you can set it up in your lo
ingestor:
blob:
# (i.e.: s3://<your-bucket>)
bucket: ""
bucket_url: ""
# (i.e.: us-east-1)
region: ""
```
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ type FileArchiveConfig struct {
}

type BlobConfig struct {
Bucket string `mapstructure:"bucket"` // Bucket to use to push k8s resources (e.g.: s3://<your_bucket>)
Region string `mapstructure:"region"` // Region to use for the bucket (only for s3)
BucketUrl string `mapstructure:"bucket_url"` // Bucket to use to push k8s resources (e.g.: s3://<your_bucket>)
Region string `mapstructure:"region"` // Region to use for the bucket (only for s3)
}
23 changes: 18 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ func SetDefaultValues(v *viper.Viper) {
v.SetDefault(TelemetryEnabled, false)

// Default value for MongoDB
v.SetDefault("mongodb.url", DefaultMongoUrl)
v.SetDefault("mongodb.connection_timeout", DefaultConnectionTimeout)
v.SetDefault(MongoUrl, DefaultMongoUrl)
v.SetDefault(MongoConnectionTimeout, DefaultConnectionTimeout)

// Defaults values for JanusGraph
v.SetDefault("janusgraph.url", DefaultJanusGraphUrl)
v.SetDefault("janusgraph.connection_timeout", DefaultConnectionTimeout)
v.SetDefault(JanusGraphUrl, DefaultJanusGraphUrl)
v.SetDefault(JanusGrapTimeout, DefaultConnectionTimeout)

// Profiler values
v.SetDefault(TelemetryProfilerPeriod, DefaultProfilerPeriod)
Expand All @@ -132,7 +132,7 @@ func SetDefaultValues(v *viper.Viper) {

v.SetDefault(IngestorAPIEndpoint, DefaultIngestorAPIEndpoint)
v.SetDefault(IngestorAPIInsecure, DefaultIngestorAPIInsecure)
v.SetDefault(IngestorBlobBucketName, DefaultBucketName)
v.SetDefault(IngestorBlobBucketURL, DefaultBucketName)
v.SetDefault(IngestorTempDir, DefaultTempDir)
v.SetDefault(IngestorMaxArchiveSize, DefaultMaxArchiveSize)
v.SetDefault(IngestorArchiveName, DefaultArchiveName)
Expand All @@ -149,6 +149,17 @@ func SetEnvOverrides(c *viper.Viper) {
res = multierror.Append(res, c.BindEnv("collector.file.directory", "KH_COLLECTOR_DIR"))
res = multierror.Append(res, c.BindEnv("collector.file.cluster", "KH_COLLECTOR_TARGET"))

res = multierror.Append(res, c.BindEnv(MongoUrl, "KH_MONGODB_URL"))
res = multierror.Append(res, c.BindEnv(JanusGraphUrl, "KH_JANUSGRAPH_URL"))

res = multierror.Append(res, c.BindEnv(IngestorAPIEndpoint, "KH_INGESTOR_API_ENDPOINT"))
res = multierror.Append(res, c.BindEnv(IngestorAPIInsecure, "KH_INGESTOR_API_INSECURE"))
res = multierror.Append(res, c.BindEnv(IngestorBlobBucketURL, "KH_INGESTOR_BUCKET_URL"))
res = multierror.Append(res, c.BindEnv(IngestorTempDir, "KH_INGESTOR_TEMP_DIR"))
res = multierror.Append(res, c.BindEnv(IngestorMaxArchiveSize, "KH_INGESTOR_MAX_ARCHIVE_SIZE"))
res = multierror.Append(res, c.BindEnv(IngestorArchiveName, "KH_INGESTOR_ARCHIVE_NAME"))
res = multierror.Append(res, c.BindEnv(IngestorBlobRegion, "KH_INGESTOR_REGION"))

if res.ErrorOrNil() != nil {
log.I.Fatalf("config environment override: %v", res.ErrorOrNil())
}
Expand Down Expand Up @@ -234,6 +245,8 @@ func NewEmbedConfig(v *viper.Viper, configPath string) (*KubehoundConfig, error)
v.SetConfigType(DefaultConfigType)
SetDefaultValues(v)

// Configure environment variable override
SetEnvOverrides(v)
data, err := embedconfig.F.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("reading embed config: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestMustLoadConfig(t *testing.T) {
Insecure: false,
},
Blob: &BlobConfig{
Bucket: "",
Region: "",
BucketUrl: "",
Region: "",
},
TempDir: "/tmp/kubehound",
ArchiveName: "archive.tar.gz",
Expand Down Expand Up @@ -155,8 +155,8 @@ func TestMustLoadConfig(t *testing.T) {
Insecure: false,
},
Blob: &BlobConfig{
Bucket: "",
Region: "",
BucketUrl: "",
Region: "",
},
TempDir: "/tmp/kubehound",
ArchiveName: "archive.tar.gz",
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const (
IngestorTempDir = "ingestor.temp_dir"
IngestorArchiveName = "ingestor.archive_name"

IngestorBlobBucketName = "ingestor.blob.bucket_name"
IngestorBlobRegion = "ingestor.blob.region"
IngestorBlobBucketURL = "ingestor.blob.bucket_url"
IngestorBlobRegion = "ingestor.blob.region"
)

type IngestorConfig struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/janusgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (

const (
DefaultJanusGraphUrl = "ws://localhost:8182/gremlin"

JanusGraphUrl = "janusgraph.url"
JanusGrapTimeout = "janusgraph.connection_timeout"
)

// JanusGraphConfig configures JanusGraph specific parameters.
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (

const (
DefaultMongoUrl = "mongodb://localhost:27017"

MongoUrl = "mongodb.url"
MongoConnectionTimeout = "mongodb.connection_timeout"
)

// MongoDBConfig configures mongodb specific parameters.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingestor/puller/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ type BlobStore struct {
var _ puller.DataPuller = (*BlobStore)(nil)

func NewBlobStorage(cfg *config.KubehoundConfig, blobConfig *config.BlobConfig) (*BlobStore, error) {
if blobConfig.Bucket == "" {
if blobConfig.BucketUrl == "" {
return nil, ErrInvalidBucketName
}

return &BlobStore{
bucketName: blobConfig.Bucket,
bucketName: blobConfig.BucketUrl,
cfg: cfg,
region: blobConfig.Region,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingestor/puller/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestNewBlobStorage(t *testing.T) {
name: "empty bucket name",
args: args{
blobConfig: &config.BlobConfig{
Bucket: "",
BucketUrl: "",
},
cfg: &config.KubehoundConfig{
Ingestor: config.IngestorConfig{
Expand All @@ -353,7 +353,7 @@ func TestNewBlobStorage(t *testing.T) {
name: "valid blob storage",
args: args{
blobConfig: &config.BlobConfig{
Bucket: "fakeBlobStorage",
BucketUrl: "fakeBlobStorage",
},
cfg: &config.KubehoundConfig{
Ingestor: config.IngestorConfig{
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubehound/storage/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/DataDog/KubeHound/pkg/config"
"github.com/DataDog/KubeHound/pkg/telemetry/log"
)

type Connector[T any] func(ctx context.Context, cfg *config.KubehoundConfig) (T, error)
Expand All @@ -17,6 +18,7 @@ func Retrier[T any](connector Connector[T], retries int, delay time.Duration) Co
if err == nil || r >= retries {
return provider, err
}
log.I.Warnf("Retrying to connect [%d/%d]", r+1, retries)

select {
case <-time.After(delay):
Expand Down
4 changes: 2 additions & 2 deletions test/system/kubehound_dump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ builder:
# Ingestor configuration (for KHaaS)
ingestor:
blob:
bucket: "" # (i.e.: s3://<your_bucket>)
bucket_url: "" # (i.e.: s3://<your_bucket>)
region: "" # (i.e.: us-west-2)
temp_dir: "/tmp/kubehound"
archive_name: "archive.tar.gz"
max_archive_size: 2147483648 # 2GB
api: # GRPC endpoint for the ingestor
endpoint: "127.0.0.1:9000"
insecure: true
insecure: true
2 changes: 1 addition & 1 deletion test/system/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func RunGRPC(ctx context.Context, runArgs *runArgs, p *providers.ProvidersFactor
log.I.Fatal(err.Error())
}

khCfg.Ingestor.Blob.Bucket = fmt.Sprintf("file://%s", fileFolder)
khCfg.Ingestor.Blob.BucketUrl = fmt.Sprintf("file://%s", fileFolder)
log.I.Info("Creating Blob Storage provider")
puller, err := blob.NewBlobStorage(khCfg, khCfg.Ingestor.Blob)
if err != nil {
Expand Down

0 comments on commit 57a2384

Please sign in to comment.