sources

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCacheDuration = 30 * time.Minute

Variables

This section is empty.

Functions

func EndpointsExtractor

func EndpointsExtractor(resource *v1.Endpoints, scope string) ([]*sdp.LinkedItemQuery, error)

func LabelSelectorToQuery

func LabelSelectorToQuery(labelSelector *metav1.LabelSelector) string

LabelSelectorToQuery converts a LabelSelector to JSON so that it can be passed to a SEARCH query

func ListOptionsToQuery

func ListOptionsToQuery(lo *metav1.ListOptions) string

func LoadAllSources

func LoadAllSources(cs *kubernetes.Clientset, cluster string, namespaces []string) []discovery.Source

func NetworkPolicyExtractor

func NetworkPolicyExtractor(resource *v1.NetworkPolicy, scope string) ([]*sdp.LinkedItemQuery, error)

func ObjectReferenceToQuery

func ObjectReferenceToQuery(ref *corev1.ObjectReference, parentScope ScopeDetails, blastProp *sdp.BlastPropagation) *sdp.LinkedItemQuery

ObjectReferenceToQuery Converts a K8s ObjectReference to a linked item request. Note that you must provide the parent scope since the reference could be an object in a different namespace, if it is we need to re-use the cluster name from the parent scope

func PersistentVolumeClaimExtractor added in v0.3.3

func PersistentVolumeClaimExtractor(resource *v1.PersistentVolumeClaim, scope string) ([]*sdp.LinkedItemQuery, error)

func PersistentVolumeExtractor

func PersistentVolumeExtractor(resource *v1.PersistentVolume, scope string) ([]*sdp.LinkedItemQuery, error)

func PodExtractor

func PodExtractor(resource *v1.Pod, scope string) ([]*sdp.LinkedItemQuery, error)

func QueryToListOptions

func QueryToListOptions(query string) (metav1.ListOptions, error)

QueryToListOptions converts a Search() query string to a ListOptions object that can be used to query the API

Types

type ClusterInterfaceBuilder

type ClusterInterfaceBuilder[Resource metav1.Object, ResourceList any] func() ItemInterface[Resource, ResourceList]

ClusterInterfaceBuilder The function that create a client to query a cluster-wide resource. e.g. `CoreV1().Nodes`

type ItemInterface

type ItemInterface[Resource metav1.Object, ResourceList any] interface {
	Get(ctx context.Context, name string, opts metav1.GetOptions) (Resource, error)
	List(ctx context.Context, opts metav1.ListOptions) (ResourceList, error)
}

ItemInterface An interface that matches the `Get` and `List` methods for K8s resources since these are the ones that we use for getting Overmind data. Kube's clients are usually namespaced when they are created, so this interface is expected to only returns items from a single namespace

type KubeTypeSource

type KubeTypeSource[Resource metav1.Object, ResourceList any] struct {
	// The function that creates a client to query a namespaced resource. e.g.
	// `CoreV1().Pods`. Either this or `NamespacedInterfaceBuilder` must be
	// specified
	ClusterInterfaceBuilder ClusterInterfaceBuilder[Resource, ResourceList]

	// The function that creates a client to query a cluster-wide resource. e.g.
	// `CoreV1().Nodes`. Either this or `ClusterInterfaceBuilder` must be
	// specified
	NamespacedInterfaceBuilder NamespacedInterfaceBuilder[Resource, ResourceList]

	// A function that extracts a slice of Resources from a ResourceList
	ListExtractor func(ResourceList) ([]Resource, error)

	// A function that returns a list of linked item queries for a given
	// resource and scope
	LinkedItemQueryExtractor func(resource Resource, scope string) ([]*sdp.LinkedItemQuery, error)

	// A function that extracts health from the resource, this is optional
	HealthExtractor func(resource Resource) *sdp.Health

	// A function that redacts sensitive data from the resource, this is
	// optional
	Redact func(resource Resource) Resource

	// The type of items that this source should return. This should be the
	// "Kind" of the kubernetes resources, e.g. "Pod", "Node", "ServiceAccount"
	TypeName string
	// List of namespaces that this source should query
	Namespaces []string
	// The name of the cluster that this source is for. This is used to generate
	// scopes
	ClusterName string

	CacheDuration time.Duration // How long to cache items for
	// contains filtered or unexported fields
}

func (*KubeTypeSource[Resource, ResourceList]) Cache added in v0.5.4

func (s *KubeTypeSource[Resource, ResourceList]) Cache() *sdpcache.Cache

func (*KubeTypeSource[Resource, ResourceList]) Get

func (s *KubeTypeSource[Resource, ResourceList]) Get(ctx context.Context, scope string, query string, ignoreCache bool) (*sdp.Item, error)

func (*KubeTypeSource[Resource, ResourceList]) List

func (s *KubeTypeSource[Resource, ResourceList]) List(ctx context.Context, scope string, ignoreCache bool) ([]*sdp.Item, error)

func (*KubeTypeSource[Resource, ResourceList]) Name

func (s *KubeTypeSource[Resource, ResourceList]) Name() string

func (*KubeTypeSource[Resource, ResourceList]) Scopes

func (s *KubeTypeSource[Resource, ResourceList]) Scopes() []string

func (*KubeTypeSource[Resource, ResourceList]) Search

func (s *KubeTypeSource[Resource, ResourceList]) Search(ctx context.Context, scope string, query string, ignoreCache bool) ([]*sdp.Item, error)

func (*KubeTypeSource[Resource, ResourceList]) Type

func (s *KubeTypeSource[Resource, ResourceList]) Type() string

func (*KubeTypeSource[Resource, ResourceList]) Validate

func (s *KubeTypeSource[Resource, ResourceList]) Validate() error

validate Validates that the source is correctly set up

func (*KubeTypeSource[Resource, ResourceList]) Weight

func (s *KubeTypeSource[Resource, ResourceList]) Weight() int

type NamespacedInterfaceBuilder

type NamespacedInterfaceBuilder[Resource metav1.Object, ResourceList any] func(namespace string) ItemInterface[Resource, ResourceList]

NamespacedInterfaceBuilder The function that create a client to query a namespaced resource. e.g. `CoreV1().Pods`

type ScopeDetails

type ScopeDetails struct {
	ClusterName string
	Namespace   string
}

func ParseScope

func ParseScope(itemScope string, namespaced bool) (ScopeDetails, error)

ParseScope Parses the custer and scope name out of a given SDP scope given that the naming convention is {clusterName}.{namespace}. Since all sources know whether they are namespaced or not, we can just pass that in to make parsing easier

func (ScopeDetails) String

func (sd ScopeDetails) String() string

type Selector

type Selector map[string]string

Selector represents a set of key value pairs that we are going to use as a selector

func (Selector) String

func (l Selector) String() string

String converts a set of key value pairs to the string format that a selector is expecting

type SourceLoader

type SourceLoader func(clientSet *kubernetes.Clientset, cluster string, namespaces []string) discovery.Source

Jump to

Keyboard shortcuts

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