collector

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeClient

func InitializeClient(ctx context.Context, l logr.Logger, c client.Client, numOfWorker int)

InitializeClient initializes a client implementing the CollectorInterface

Types

type CollectMethod

type CollectMethod func(ctx context.Context, c client.Client, requestorName string, logger logr.Logger) error

type CollectionType

type CollectionType int64
const (
	Snapshot CollectionType = iota
	Techsupport
)

type Collector

type Collector struct {
	client.Client
	// contains filtered or unexported fields
}

Collector represents a client implementing the CollectorInterface

func GetClient

func GetClient() *Collector

GetClient return a collector client, implementing the CollectorInterface

func (*Collector) CleanOldCollections

func (d *Collector) CleanOldCollections(storage, requestorName string, collectionType CollectionType,
	limit int32, logger logr.Logger) error

func (*Collector) CleanupEntries

func (d *Collector) CleanupEntries(storage, requestorName string, collectionType CollectionType) error

func (*Collector) Collect

func (d *Collector) Collect(ctx context.Context, requestorName string,
	collectionType CollectionType, collectMethd CollectMethod) error

func (*Collector) DumpObject

func (d *Collector) DumpObject(resource client.Object, logPath string, logger logr.Logger) error

DumpObject is a helper function to generically dump resource definition given the resource reference and file path for dumping location.

func (*Collector) DumpPodLogs

func (d *Collector) DumpPodLogs(ctx context.Context, clientSet *kubernetes.Clientset, logPath string,
	since *int64, pod *corev1.Pod) error

DumpPodLogs collects logs for all containers in a pod and store them. If pod has restarted, it will try to collect log from previous run as well.

func (*Collector) GetClusterResources

func (d *Collector) GetClusterResources(folder, kind string, logger logr.Logger,
) ([]*unstructured.Unstructured, error)

func (*Collector) GetFolder

func (d *Collector) GetFolder(storage, requestorName string, collectionType CollectionType,
	logger logr.Logger) (*string, error)

func (*Collector) GetFolderPath

func (d *Collector) GetFolderPath(storage, requestorName string, collectionType CollectionType, t time.Time) string

func (*Collector) GetNamespacedResources

func (d *Collector) GetNamespacedResources(folder, kind string, logger logr.Logger,
) (map[string][]*unstructured.Unstructured, error)

func (*Collector) GetResult

func (d *Collector) GetResult(ctx context.Context, requestorName string,
	collectionType CollectionType) Result

func (*Collector) GetUnstructured

func (d *Collector) GetUnstructured(object []byte) (*unstructured.Unstructured, error)

GetUnstructured returns an unstructured given a []bytes containing it

func (*Collector) IsInProgress

func (d *Collector) IsInProgress(requestorName string, collectionType CollectionType) bool

func (*Collector) ListCollections

func (d *Collector) ListCollections(storage, requestorName string, collectionType CollectionType,
	logger logr.Logger) ([]string, error)

func (*Collector) TarDir

func (d *Collector) TarDir(src string, logger logr.Logger) error

type CollectorInterface

type CollectorInterface interface {
	// RegisterMethod registers a collection method
	RegisterMethod(m CollectMethod)

	// Collect creates a request to collect resources for requestorName
	// When worker is available to fulfill such request, the CollectMethod registered
	// will be invoked in the worker context.
	// requestorName is the name of the instance making this request.
	Collect(ctx context.Context, requestorName string,
		collectionType CollectionType, collectMethd CollectMethod) error

	// IsInProgress returns true if requestorName's request to collect is currently in progress.
	IsInProgress(requestorName string, collectionType CollectionType) bool

	// GetResult returns result for requestorName's request
	GetResult(ctx context.Context, requestorName string, collectionType CollectionType) Result

	// ListCollections returns list all collections taken for a given requestorName
	ListCollections(storage, requestorName string, collectionType CollectionType,
		logger logr.Logger) ([]string, error)

	// GetFolderPath returns the path of folder where resources can be stored
	GetFolderPath(storage, requestorName string, collectionType CollectionType) string

	// GetFolder returns the artifact folder where all collections for a given
	// requestorName are stored
	GetFolder(storage, requestorName string, collectionType CollectionType,
		logger logr.Logger) (*string, error)

	// CleanupEntries removes any entry (from any internal data structure) for
	// given requestorName
	CleanupEntries(storage, requestorName string, collectionType CollectionType) error

	// GetNamespacedResources returns all namespaced resources contained in the
	// folder.
	// Returns a map with:
	// - key: <namespace name>
	// - value: list of resources of the Kind specified
	GetNamespacedResources(folder, kind string, logger logr.Logger) (map[string][]*unstructured.Unstructured, error)

	// GetClusterResources	returns all cluster resources contained in the folder
	GetClusterResources(folder, kind string, logger logr.Logger) ([]*unstructured.Unstructured, error)

	// CleanOldCollections removes old collection for requestorName. If more than limit collections
	// are present, the oldest ones are remove up till there are only limit-1 collections left.
	CleanOldCollections(storage, requestorName string, collectionType CollectionType,
		limit int32, logger logr.Logger) error

	// DumpObject is a helper function to generically dump resource definition
	// given the resource reference and file path for dumping location.
	DumpObject(resource client.Object, logPath string, logger logr.Logger) error
}

type Result

type Result struct {
	ResultStatus
	Err error
}

type ResultStatus

type ResultStatus int64
const (
	Collected ResultStatus = iota
	InProgress
	Failed
	Unavailable
)

func (ResultStatus) String

func (r ResultStatus) String() string

Jump to

Keyboard shortcuts

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