Skip to content

Commit

Permalink
[processor/resourcedetection] Fix EKS detector nil panic. (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien authored Aug 23, 2024
1 parent bfabe7d commit 13f78ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type eksDetectorUtils struct {
type detector struct {
utils detectorUtils
logger *zap.Logger
err error
ra metadata.ResourceAttributesConfig
rb *metadata.ResourceBuilder
}
Expand All @@ -66,11 +65,12 @@ var _ detectorUtils = (*eksDetectorUtils)(nil)
func NewDetector(set processor.Settings, dcfg internal.DetectorConfig) (internal.Detector, error) {
cfg := dcfg.(Config)
utils, err := newK8sDetectorUtils()

if err != nil {
return nil, err
}
return &detector{
utils: utils,
logger: set.Logger,
err: err,
ra: cfg.ResourceAttributes,
rb: metadata.NewResourceBuilder(cfg.ResourceAttributes),
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (detectorUtils *MockDetectorUtils) getClusterNameTagFromReservations(_ []*e
func TestNewDetector(t *testing.T) {
dcfg := CreateDefaultConfig()
detector, err := NewDetector(processortest.NewNopSettings(), dcfg)
assert.NoError(t, err)
assert.NotNil(t, detector)
assert.Error(t, err)
assert.Nil(t, detector)
}

// Tests EKS resource detector running in EKS environment
Expand All @@ -55,7 +55,7 @@ func TestEKS(t *testing.T) {
t.Setenv("KUBERNETES_SERVICE_HOST", "localhost")
detectorUtils.On("getConfigMap", authConfigmapNS, authConfigmapName).Return(map[string]string{conventions.AttributeK8SClusterName: clusterName}, nil)
// Call EKS Resource detector to detect resources
eksResourceDetector := &detector{utils: detectorUtils, err: nil, ra: metadata.DefaultResourceAttributesConfig(), rb: metadata.NewResourceBuilder(metadata.DefaultResourceAttributesConfig())}
eksResourceDetector := &detector{utils: detectorUtils, ra: metadata.DefaultResourceAttributesConfig(), rb: metadata.NewResourceBuilder(metadata.DefaultResourceAttributesConfig())}
res, _, err := eksResourceDetector.Detect(ctx)
require.NoError(t, err)

Expand Down

0 comments on commit 13f78ca

Please sign in to comment.