Eks resource detector bugfix (#575)
* added failure scenario when getting container fails * fix test case failure * add changelog * fix ecs resource detector bug * fix struct name as per golint suggestion * minor changes * added NewResourceDetector func and interface assertions * fix golint failure * minor changes to address review comments * fix eks resource detector bug * comment changes * fix typo Co-authored-by: Anthony Mirabella <a9@aneurysm9.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
parent
e532370ba2
commit
bd90f3e3b2
|
|
@ -43,7 +43,7 @@ const (
|
|||
timeoutMillis = 2000
|
||||
)
|
||||
|
||||
// detectorUtils is used for testing the ResourceDetector by abstracting functions that rely on external systems.
|
||||
// detectorUtils is used for testing the resourceDetector by abstracting functions that rely on external systems.
|
||||
type detectorUtils interface {
|
||||
fileExists(filename string) bool
|
||||
fetchString(httpMethod string, URL string) (string, error)
|
||||
|
|
@ -53,8 +53,8 @@ type detectorUtils interface {
|
|||
// This struct will implement the detectorUtils interface
|
||||
type eksDetectorUtils struct{}
|
||||
|
||||
// ResourceDetector for detecting resources running on Amazon EKS
|
||||
type ResourceDetector struct {
|
||||
// resourceDetector for detecting resources running on Amazon EKS
|
||||
type resourceDetector struct {
|
||||
utils detectorUtils
|
||||
}
|
||||
|
||||
|
|
@ -63,14 +63,19 @@ type data struct {
|
|||
ClusterName string `json:"cluster.name"`
|
||||
}
|
||||
|
||||
// Compile time assertion that ResourceDetector implements the resource.Detector interface.
|
||||
var _ resource.Detector = (*ResourceDetector)(nil)
|
||||
// Compile time assertion that resourceDetector implements the resource.Detector interface.
|
||||
var _ resource.Detector = (*resourceDetector)(nil)
|
||||
|
||||
// Compile time assertion that eksDetectorUtils implements the detectorUtils interface.
|
||||
var _ detectorUtils = (*eksDetectorUtils)(nil)
|
||||
|
||||
// NewResourceDetector returns a resource detector that will detect AWS EKS resources.
|
||||
func NewResourceDetector() resource.Detector {
|
||||
return &resourceDetector{utils: eksDetectorUtils{}}
|
||||
}
|
||||
|
||||
// Detect returns a Resource describing the Amazon EKS environment being run in.
|
||||
func (detector *ResourceDetector) Detect(ctx context.Context) (*resource.Resource, error) {
|
||||
func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resource, error) {
|
||||
|
||||
isEks, err := isEKS(detector.utils)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func TestEks(t *testing.T) {
|
|||
expectedResource := resource.NewWithAttributes(eksResourceLabels...)
|
||||
|
||||
// Call EKS Resource detector to detect resources
|
||||
eksResourceDetector := ResourceDetector{detectorUtils}
|
||||
eksResourceDetector := resourceDetector{detectorUtils}
|
||||
resourceObj, err := eksResourceDetector.Detect(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ func TestNotEKS(t *testing.T) {
|
|||
// Mock functions and set expectations
|
||||
detectorUtils.On("fileExists", k8sTokenPath).Return(false)
|
||||
|
||||
detector := ResourceDetector{detectorUtils}
|
||||
detector := resourceDetector{detectorUtils}
|
||||
r, err := detector.Detect(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, resource.Empty(), r, "Resource object should be empty")
|
||||
|
|
|
|||
Loading…
Reference in New Issue