discovery

package
v0.56.11 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NSResourceLocation is the place under which namespaced API resources (pods, etc) are stored
	NSResourceLocation = "resources/ns"
	// ClusterResourceLocation is the place under which non-namespaced API resources (nodes, etc) are stored
	ClusterResourceLocation = "resources/cluster"
	// HostsLocation is the place under which host information (configz, healthz) is stored
	HostsLocation = "hosts"
)
View Source
const (

	// MetaLocation is the place under which snapshot metadata (query times, config) is stored
	// Also stored in query.go
	MetaLocation = "meta"
)
View Source
const (
	// PodLogsLocation is the location within the results tarball where pod
	// information is stored.
	PodLogsLocation = "podlogs"
)

Variables

This section is empty.

Functions

func AutoAttachResultsDir added in v0.56.6

func AutoAttachResultsDir(plugins []*manifest.Manifest, resultsDir string)

AutoAttachResultsDir will either add the volumemount for the results dir or modify the existing one to have the right path set.

func FilterNamespaces

func FilterNamespaces(kubeClient kubernetes.Interface, filter string, defaultNS ...string) ([]string, error)

FilterNamespaces filter the list of namespaces according to the filter string. If unable to query all the namespaces, an optional defaultNS can be provided which will be added to the returned list if it matches the filter.

func QueryCluster added in v0.56.0

func QueryCluster(restConf *rest.Config, cfg *config.Config) error

Query cluster runs multiple queries against the cluster in order to obtain debug information.

func QueryHostData added in v0.14.2

func QueryHostData(kubeClient kubernetes.Interface, recorder *QueryRecorder, cfg *config.Config) error

QueryHostData gets the host data and records it.

func QueryPodLogs added in v0.14.2

func QueryPodLogs(kubeClient kubernetes.Interface, recorder *QueryRecorder, ns string, cfg *config.Config,
	visitedPods map[string]struct{}) error

QueryPodLogs gets the pod logs for each pod in the given namespace. If namespace is not provided, get pod logs using field selectors. VisitedPods will eliminate duplicate pods when execute overlapping queries, e.g. query by namespaces and query by fieldSelectors.

func QueryResources added in v0.14.2

func QueryResources(
	client *dynamic.APIHelper,
	recorder *QueryRecorder,
	resources []schema.GroupVersionResource,
	ns *string,
	cfg *config.Config) error

QueryResources will query all the intended resources. If given a non-nil namespace it queries only namespaced objects; non-namespaced otherwise. Writing them out to <outputDir>/resources/ns/<ns>/*.json or <outputDir>/resources/cluster/*.json.

func QueryServerData added in v0.14.2

func QueryServerData(kubeClient kubernetes.Interface, recorder *QueryRecorder, cfg *config.Config) error

QueryServerData gets the server version and server group data and records it.

func Run

func Run(restConf *rest.Config, cfg *config.Config) (errCount int)

Run is the main entrypoint for discovery.

func SaveHealthSummary added in v0.56.2

func SaveHealthSummary(tarballRootDir string) error

SaveHealthSummary loads data from - CoreNodesFile in ClusterResourceLocation in tarballRootDir - ServerVersionFile in tarballRootDir - CorePodsFile in NSResourceLocation in tarballRootDir Extract health information, and saves the result as json to results.ClusterHealthFilePath() in tarballRootDir SaveHealthSummary assumes that all the directories including MetaLocation have already been created

func SerializeObj

func SerializeObj(obj interface{}, outpath string, file string) error

SerializeObj will write out an object

Types

type ClusterSummary added in v0.56.2

type ClusterSummary struct {
	NodeHealth HealthInfo `json:"node_health" yaml:"node_health"`
	PodHealth  HealthInfo `json:"pod_health" yaml:"pod_health"`
	APIVersion string     `json:"api_version" yaml:"api_version"`
	ErrorInfo  LogSummary `json:"error_summary" yaml:"error_summary"`
}

func ReadHealthSummary added in v0.56.2

func ReadHealthSummary(tarballRootDir string) (ClusterSummary, error)

ReadHealthSummary reads the core_v1_nodes.json file from ClusterResourceLocation and returns a summary of the health fo the cluster, ready to be saved tarballRootDir is the directory that will be used to provide the contents of the tarball

type HealthInfo added in v0.56.2

type HealthInfo struct {
	Total   int                 `json:"total_nodes" yaml:"total_nodes"`
	Healthy int                 `json:"healthy_nodes" yaml:"healthy_nodes"`
	Details []HealthInfoDetails `json:"details,omitempty" yaml:"details,omitempty"`
}

func ReadPodHealth added in v0.56.2

func ReadPodHealth(r *results.Reader) (HealthInfo, error)

ReadPodHealth lists all the directories in path.Join(tarballRootDir, NSResourceLocation) In each, check if it contains the file CorePodFile, if so, read each as v1.PodList, And loop through _, pod := range podList.Items, and scan _, condition := range pod.Status.Conditions and check if condition.Status == v1.ConditionTrue: for each of these, if they are false, add the condition.Reason and condition.Message to a string

type HealthInfoDetails added in v0.56.2

type HealthInfoDetails struct {
	Name      string `json:"name" yaml:"name"`
	Healthy   bool   `json:"healthy" yaml:"healthy"`
	Ready     string `json:"ready" yaml:"ready"`
	Reason    string `json:"reason,omitempty" yaml:"reason,omitempty"`
	Message   string `json:"message,omitempty" yaml:"message,omitempty"`
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}

type LogHitCounter added in v0.56.2

type LogHitCounter map[string]int

type LogPattern added in v0.56.2

type LogPattern struct {
	// contains filtered or unexported fields
}

LogPattern is a struct that defines a class of log patterns, a LogPatterns instance will contain one or more file name patterns, stored in filePathPattern and another list of patterns that are meant to be matched against the content of files whose name matches the filePathPattern. both filePathPattern and matchPatterns are one or more compiled regular expressions

A match for a pattern defined in LogPatterns will happen if: a certain file has a path that matches at least one of the regex in filePathPattern and at least one of the lines in the content of this file matches at least one of the regex patterns in matchPattern

type LogPatterns added in v0.56.2

type LogPatterns map[string]LogPattern

LogPatterns maps the name of a set of patterns to its components The LogPattern structure defines the components of a set of patterns

func GetDefaultLogPatterns added in v0.56.2

func GetDefaultLogPatterns() LogPatterns

GetDefaultLogPatterns returns the default set of log patterns that can be used with ReadLogSummary

type LogSummary added in v0.56.2

type LogSummary map[string]LogHitCounter

func ReadLogSummary added in v0.56.2

func ReadLogSummary(r *results.Reader, patterns LogPatterns) (LogSummary, error)

ReadLogSummary will recursively scan the tarballRootDir looking for files with names matching pre-defined regular expressions and scanning the content of these files for pre-defined error matching regexes and counting the number of hits The return value is a map of results with key the type of condition and the values of the map are the file names and the hit count the patterns parameter is a list of LogPatterns objects that define what to scan for The GetDefaultLogPatterns can be used to obtain such list. Errors encountered while scanning the directory are logged but no error will be returned.

func ReadLogSummaryWithDefaultPatterns added in v0.56.2

func ReadLogSummaryWithDefaultPatterns(r *results.Reader) (LogSummary, error)

ReadLogSummaryWithDefaultPatterns is a wrapper to ReadLogSummary + GetDefaultLogPatterns

type QueryData added in v0.11.0

type QueryData struct {
	QueryObj    string `json:"queryobj,omitempty"`
	Namespace   string `json:"namespace,omitempty"`
	ElapsedTime string `json:"time,omitempty"`
	Error       error  `json:"error,omitempty"`
}

QueryData captures the results of the run for post-processing

type QueryRecorder added in v0.9.0

type QueryRecorder struct {
	// contains filtered or unexported fields
}

QueryRecorder records a sequence of queries

func NewQueryRecorder added in v0.9.0

func NewQueryRecorder() *QueryRecorder

NewQueryRecorder returns a new empty QueryRecorder

func (*QueryRecorder) DumpQueryData added in v0.9.0

func (q *QueryRecorder) DumpQueryData(filepath string) error

DumpQueryData writes query information out to a file at the give filepath

func (*QueryRecorder) RecordQuery added in v0.9.0

func (q *QueryRecorder) RecordQuery(name string, namespace string, duration time.Duration, recerr error)

RecordQuery transcribes a query by name, namespace, duration and error

type RunInfo added in v0.16.1

type RunInfo struct {
	LoadedPlugins []string `json:"plugins,omitempty"`
}

Jump to

Keyboard shortcuts

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