eksdetector

package
v1.300037.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NewDetector creates a new singleton detector for EKS
	NewDetector = func() (Detector, error) {
		var errors error
		if clientset, err := getClient(); err != nil {
			errors = err
		} else {
			detector = &EksDetector{Clientset: clientset}
		}

		return detector, errors
	}

	// IsEKS checks if the agent is running on EKS. This is done by using the kubernetes API to determine if the aws-auth
	// configmap exists in the kube-system namespace
	IsEKS = func() IsEKSCache {
		once.Do(func() {
			var errors error
			var value bool

			eksDetector, err := NewDetector()
			if err != nil {
				errors = err
			}

			if eksDetector != nil {

				awsAuth, err := eksDetector.getConfigMap(authConfigNamespace, authConfigConfigMap)
				if err == nil {
					value = awsAuth != nil
				}
			}
			isEKSCacheSingleton = IsEKSCache{Value: value, Err: errors}
		})

		return isEKSCacheSingleton
	}
)
View Source
var (
	// TestEKSDetector is used for unit testing EKS route
	TestEKSDetector = func() (Detector, error) {
		cm := &v1.ConfigMap{
			TypeMeta:   metav1.TypeMeta{Kind: "ConfigMap", APIVersion: "v1"},
			ObjectMeta: metav1.ObjectMeta{Namespace: "kube-system", Name: "aws-auth"},
			Data:       make(map[string]string),
		}
		return &EksDetector{Clientset: fake.NewSimpleClientset(cm)}, nil
	}
	// TestK8sDetector is used for unit testing k8s route
	TestK8sDetector = func() (Detector, error) {
		return &EksDetector{Clientset: fake.NewSimpleClientset()}, nil
	}

	// TestIsEKSCacheEKS os used for unit testing EKS route
	TestIsEKSCacheEKS = func() IsEKSCache {
		return IsEKSCache{Value: true, Err: nil}
	}

	// TestIsEKSCacheK8s is used for unit testing K8s route
	TestIsEKSCacheK8s = func() IsEKSCache {
		return IsEKSCache{Value: false, Err: nil}
	}
)

Functions

This section is empty.

Types

type Detector

type Detector interface {
	// contains filtered or unexported methods
}

type EksDetector

type EksDetector struct {
	Clientset kubernetes.Interface
}

type IsEKSCache

type IsEKSCache struct {
	Value bool
	Err   error
}

type MockDetector

type MockDetector struct {
	mock.Mock
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL