linter

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToPerc

func ToPerc(v1, v2 int64) int64

ToPerc computes the percentage from one number over another.

Types

type ConfigMap added in v0.3.0

type ConfigMap struct {
	*Linter
}

ConfigMap represents a ConfigMap linter.

func NewConfigMap added in v0.3.0

func NewConfigMap(l Loader, log *zerolog.Logger) *ConfigMap

NewConfigMap returns a new ConfigMap linter.

func (*ConfigMap) Lint added in v0.3.0

func (c *ConfigMap) Lint(ctx context.Context) error

Lint a ConfigMap.

type ConsumptionMetrics added in v0.3.0

type ConsumptionMetrics struct {
	CurrentCPU       resource.Quantity
	CurrentMEM       resource.Quantity
	RequestedCPU     resource.Quantity
	RequestedMEM     resource.Quantity
	RequestedStorage resource.Quantity
}

ConsumptionMetrics tracks managed pods resource utilization.

func (*ConsumptionMetrics) ReqCPURatio added in v0.3.0

func (d *ConsumptionMetrics) ReqCPURatio() int64

ReqCPURatio returns current cpu usage over requested percentage.

func (*ConsumptionMetrics) ReqMEMRatio added in v0.3.0

func (d *ConsumptionMetrics) ReqMEMRatio() int64

ReqMEMRatio returns current memory usage over requested percentage.

type Container

type Container struct {
	*Linter
}

Container represents a Container linter.

func NewContainer

func NewContainer(l Loader, log *zerolog.Logger) *Container

NewContainer returns a new container linter.

type Deployment added in v0.3.0

type Deployment struct {
	*Linter
}

Deployment represents a Deployment linter.

func NewDeployment added in v0.3.0

func NewDeployment(l Loader, log *zerolog.Logger) *Deployment

NewDeployment returns a new Deployment linter.

func (*Deployment) Lint added in v0.3.0

func (d *Deployment) Lint(ctx context.Context) error

Lint a Deployment.

type Error

type Error struct {
	Level   Level  `json:"level" yaml:"level"`
	Message string `json:"message" yaml:"message"`
	Subs    Issues `json:"containers,omitempty" yaml:"containers,omitempty"`
}

Error tracks a linter issue.

func NewError

func NewError(level Level, description string) *Error

NewError returns a new lint issue.

func NewErrorf

func NewErrorf(level Level, format string, args ...interface{}) *Error

NewErrorf returns a new lint issue using a formatter.

func (*Error) Description

func (e *Error) Description() string

Description returns the lint Message.

func (*Error) HasSubIssues added in v0.3.0

func (e *Error) HasSubIssues() bool

HasSubIssues checks if error contains sub issues.

func (*Error) SetSeverity added in v0.3.0

func (e *Error) SetSeverity(l Level)

SetSeverity sets the severity level.

func (*Error) Severity

func (e *Error) Severity() Level

Severity returns the Level of the message.

func (*Error) SubIssues added in v0.3.0

func (e *Error) SubIssues() Issues

SubIssues returns the lint Message.

type Fetcher added in v0.2.0

type Fetcher interface {
	ActiveCluster() string
	ActiveNamespace() string

	ClusterHasMetrics() (bool, error)
	FetchNodesMetrics() ([]mv1beta1.NodeMetrics, error)
	FetchPodsMetrics(ns string) ([]mv1beta1.PodMetrics, error)

	FetchNodes() (*v1.NodeList, error)
	FetchNamespaces() (*v1.NamespaceList, error)
	FetchPods() (*v1.PodList, error)
	FetchPodsByLabels(string) (*v1.PodList, error)
	FetchConfigMaps() (*v1.ConfigMapList, error)
	FetchSecrets() (*v1.SecretList, error)
	FetchServiceAccounts() (*v1.ServiceAccountList, error)
	FetchEndpoints() (*v1.EndpointsList, error)
	FetchServices() (*v1.ServiceList, error)
	FetchClusterRoleBindings() (*rbacv1.ClusterRoleBindingList, error)
	FetchRoleBindings() (*rbacv1.RoleBindingList, error)
	FetchPersistentVolumes() (*v1.PersistentVolumeList, error)
	FetchPersistentVolumeClaims() (*v1.PersistentVolumeClaimList, error)
	FetchHorizontalPodAutoscalers() (*autoscalingv1.HorizontalPodAutoscalerList, error)
	FetchDeployments() (*appsv1.DeploymentList, error)
	FetchStatefulSets() (*appsv1.StatefulSetList, error)
}

Fetcher fetches Kubernetes resources from the apiserver.

type Filter added in v0.2.0

type Filter struct {
	Spinach
	Fetcher
	// contains filtered or unexported fields
}

Filter represents a Kubernetes resources filter based on configuration.

func NewFilter added in v0.2.0

func NewFilter(f Fetcher, s Spinach) *Filter

NewFilter returns a new Kubernetes resource filter.

func (*Filter) GetEndpoints added in v0.2.0

func (f *Filter) GetEndpoints(svcFQN string) (*v1.Endpoints, error)

GetEndpoints returns a endpoint instance if present or an error if not.

func (*Filter) GetPod added in v0.2.0

func (f *Filter) GetPod(sel map[string]string) (*v1.Pod, error)

GetPod returns a pod via a label query.

func (*Filter) ListAllClusterRoleBindings added in v0.2.0

func (f *Filter) ListAllClusterRoleBindings() (map[string]rbacv1.ClusterRoleBinding, error)

ListAllClusterRoleBindings returns a ClusterRoleBindings.

func (*Filter) ListAllConfigMaps added in v0.2.0

func (f *Filter) ListAllConfigMaps() (map[string]v1.ConfigMap, error)

ListAllConfigMaps fetch all configmaps on the cluster.

func (*Filter) ListAllDeployments added in v0.3.0

func (f *Filter) ListAllDeployments() (map[string]appsv1.Deployment, error)

ListAllDeployments returns all Deployments on cluster.

func (*Filter) ListAllEndpoints added in v0.2.0

func (f *Filter) ListAllEndpoints() (map[string]v1.Endpoints, error)

ListAllEndpoints returns all the endpoints on a cluster.

func (*Filter) ListAllHorizontalPodAutoscalers added in v0.3.0

func (f *Filter) ListAllHorizontalPodAutoscalers() (map[string]autoscalingv1.HorizontalPodAutoscaler, error)

ListAllHorizontalPodAutoscalers returns all HorizontalPodAutoscaler.

func (*Filter) ListAllNamespaces added in v0.2.0

func (f *Filter) ListAllNamespaces() (map[string]v1.Namespace, error)

ListAllNamespaces fetch all namespaces on this cluster.

func (*Filter) ListAllPersistentVolumeClaims added in v0.3.0

func (f *Filter) ListAllPersistentVolumeClaims() (map[string]v1.PersistentVolumeClaim, error)

ListAllPersistentVolumeClaims returns all PersistentVolumeClaims.

func (*Filter) ListAllPods added in v0.2.0

func (f *Filter) ListAllPods() (map[string]v1.Pod, error)

ListAllPods fetch all pods on the cluster.

func (*Filter) ListAllRoleBindings added in v0.2.0

func (f *Filter) ListAllRoleBindings() (map[string]rbacv1.RoleBinding, error)

ListAllRoleBindings returns all RoleBindings.

func (*Filter) ListAllSecrets added in v0.2.0

func (f *Filter) ListAllSecrets() (map[string]v1.Secret, error)

ListAllSecrets fetch all secrets on the cluster.

func (*Filter) ListAllServiceAccounts added in v0.2.0

func (f *Filter) ListAllServiceAccounts() (map[string]v1.ServiceAccount, error)

ListAllServiceAccounts fetch all ServiceAccount on the cluster.

func (*Filter) ListAllServices added in v0.2.0

func (f *Filter) ListAllServices() (map[string]v1.Service, error)

ListAllServices lists services in the cluster.

func (*Filter) ListAllStatefulSets added in v0.3.0

func (f *Filter) ListAllStatefulSets() (map[string]appsv1.StatefulSet, error)

ListAllStatefulSets returns all StatefulSets on cluster.

func (*Filter) ListConfigMaps added in v0.2.0

func (f *Filter) ListConfigMaps() (map[string]v1.ConfigMap, error)

ListConfigMaps list all included ConfigMaps.

func (*Filter) ListDeployments added in v0.3.0

func (f *Filter) ListDeployments() (map[string]appsv1.Deployment, error)

ListDeployments lists all available Deployments in allowed namespace.

func (*Filter) ListEndpoints added in v0.2.0

func (f *Filter) ListEndpoints() (map[string]v1.Endpoints, error)

ListEndpoints returns a collection of endpoints in allowed namespaces.

func (*Filter) ListHorizontalPodAutoscalers added in v0.3.0

func (f *Filter) ListHorizontalPodAutoscalers() (map[string]autoscalingv1.HorizontalPodAutoscaler, error)

ListHorizontalPodAutoscalers lists all available PVCs on the cluster.

func (*Filter) ListNamespaces added in v0.2.0

func (f *Filter) ListNamespaces() (map[string]v1.Namespace, error)

ListNamespaces lists all available namespaces.

func (*Filter) ListNodes added in v0.2.0

func (f *Filter) ListNodes() ([]v1.Node, error)

ListNodes list all available nodes on the cluster.

func (*Filter) ListNodesMetrics added in v0.2.0

func (*Filter) ListNodesMetrics(nodes []v1.Node, metrics []mv1beta1.NodeMetrics, nmx k8s.NodesMetrics)

ListNodesMetrics retrieves metrics for a given set of nodes.

func (*Filter) ListPersistentVolumeClaims added in v0.3.0

func (f *Filter) ListPersistentVolumeClaims() (map[string]v1.PersistentVolumeClaim, error)

ListPersistentVolumeClaims lists all available PVCs on the cluster.

func (*Filter) ListPersistentVolumes added in v0.3.0

func (f *Filter) ListPersistentVolumes() (map[string]v1.PersistentVolume, error)

ListPersistentVolumes returns all PersistentVolumes.

func (*Filter) ListPods added in v0.2.0

func (f *Filter) ListPods() (map[string]v1.Pod, error)

ListPods list all available pods.

func (*Filter) ListPodsByLabels added in v0.3.0

func (f *Filter) ListPodsByLabels(sel string) (map[string]v1.Pod, error)

ListPodsByLabels retrieves all pods matching a label selector in the allowed namespaces.

func (*Filter) ListPodsMetrics added in v0.2.0

func (*Filter) ListPodsMetrics(pods []mv1beta1.PodMetrics, nmx k8s.PodsMetrics)

ListPodsMetrics retrieves metrics for all pods in a given namespace.

func (*Filter) ListRoleBindings added in v0.2.0

func (f *Filter) ListRoleBindings() (map[string]rbacv1.RoleBinding, error)

ListRoleBindings lists all available RBs in the allowed namespaces.

func (*Filter) ListSecrets added in v0.2.0

func (f *Filter) ListSecrets() (map[string]v1.Secret, error)

ListSecrets list included Secrets.

func (*Filter) ListServiceAccounts added in v0.2.0

func (f *Filter) ListServiceAccounts() (map[string]v1.ServiceAccount, error)

ListServiceAccounts list included ServiceAccounts.

func (*Filter) ListServices added in v0.2.0

func (f *Filter) ListServices() (map[string]v1.Service, error)

ListServices lists services in tolerated namespaces.

func (*Filter) ListStatefulSets added in v0.3.0

func (f *Filter) ListStatefulSets() (map[string]appsv1.StatefulSet, error)

ListStatefulSets lists all available StatefulSets in allowed namespace.

func (*Filter) PodsNamespaces added in v0.2.0

func (f *Filter) PodsNamespaces(nss []string)

PodsNamespaces fetch a list of all namespaces used by pods.

type HorizontalPodAutoscaler added in v0.3.0

type HorizontalPodAutoscaler struct {
	*Linter
}

HorizontalPodAutoscaler represents a HorizontalPodAutoscaler linter.

func NewHorizontalPodAutoscaler added in v0.3.0

func NewHorizontalPodAutoscaler(l Loader, log *zerolog.Logger) *HorizontalPodAutoscaler

NewHorizontalPodAutoscaler returns a new ServiceAccount linter.

func (*HorizontalPodAutoscaler) Lint added in v0.3.0

Lint a serviceaccount.

type Issue

type Issue interface {
	Severity() Level
	SetSeverity(Level)
	Description() string
	HasSubIssues() bool
	SubIssues() Issues
}

Issue indicates a potential linter issue.

type Issues

type Issues map[string][]Issue

Issues a collection of linter issues.

func (Issues) MaxSeverity added in v0.3.0

func (i Issues) MaxSeverity(res string) Level

MaxSeverity scans the issues and reports the highest severity.

type Level

type Level int

Level tracks lint check level.

const (
	// OkLevel denotes no linting issues.
	OkLevel Level = iota
	// InfoLevel denotes FIY linting issues.
	InfoLevel
	// WarnLevel denotes a warning issue.
	WarnLevel
	// ErrorLevel denotes a serious issue.
	ErrorLevel
)

type Linter

type Linter struct {
	Loader
	// contains filtered or unexported fields
}

Linter describes a lint resource.

func NewLinter added in v0.2.0

func NewLinter(l Loader, log *zerolog.Logger) *Linter

NewLinter returns a new linter.

func (*Linter) Issues

func (l *Linter) Issues() Issues

Issues returns a collection of linter issues.

func (*Linter) MaxSeverity

func (l *Linter) MaxSeverity(res string) Level

MaxSeverity return the highest severity level.

func (*Linter) NoIssues

func (l *Linter) NoIssues(res string) bool

NoIssues return true if not lint errors were detected. False otherwize

type Lister added in v0.2.0

type Lister interface {
	ListNodesMetrics([]v1.Node, []mv1beta1.NodeMetrics, k8s.NodesMetrics)
	ListPodsMetrics([]mv1beta1.PodMetrics, k8s.PodsMetrics)

	ListServices() (map[string]v1.Service, error)
	ListNodes() ([]v1.Node, error)
	GetEndpoints(fqn string) (*v1.Endpoints, error)
	PodsNamespaces(used []string)
	GetPod(map[string]string) (*v1.Pod, error)
	ListPods() (map[string]v1.Pod, error)
	ListPodsByLabels(string) (map[string]v1.Pod, error)
	ListAllPods() (map[string]v1.Pod, error)
	ListNamespaces() (map[string]v1.Namespace, error)
	ListRoleBindings() (map[string]rbacv1.RoleBinding, error)
	ListAllRoleBindings() (map[string]rbacv1.RoleBinding, error)
	ListAllClusterRoleBindings() (map[string]rbacv1.ClusterRoleBinding, error)
	ListConfigMaps() (map[string]v1.ConfigMap, error)
	ListSecrets() (map[string]v1.Secret, error)
	ListServiceAccounts() (map[string]v1.ServiceAccount, error)
	ListPersistentVolumes() (map[string]v1.PersistentVolume, error)
	ListPersistentVolumeClaims() (map[string]v1.PersistentVolumeClaim, error)
	ListAllPersistentVolumeClaims() (map[string]v1.PersistentVolumeClaim, error)
	ListHorizontalPodAutoscalers() (map[string]autoscalingv1.HorizontalPodAutoscaler, error)
	ListAllHorizontalPodAutoscalers() (map[string]autoscalingv1.HorizontalPodAutoscaler, error)
	ListDeployments() (map[string]appsv1.Deployment, error)
	ListAllDeployments() (map[string]appsv1.Deployment, error)
	ListStatefulSets() (map[string]appsv1.StatefulSet, error)
	ListAllStatefulSets() (map[string]appsv1.StatefulSet, error)
}

Lister list Kubernetes resource based on configuration scopes.

type Loader added in v0.2.0

type Loader interface {
	Spinach
	Fetcher
	Lister
}

Loader loads prefiltered Kubernetes resources.

type Namespace

type Namespace struct {
	*Linter
}

Namespace represents a Namespace linter.

func NewNamespace

func NewNamespace(l Loader, log *zerolog.Logger) *Namespace

NewNamespace returns a new namespace linter.

func (*Namespace) Lint

func (n *Namespace) Lint(ctx context.Context) error

Lint a namespace

type Node

type Node struct {
	*Linter
}

Node represents a Node linter.

func NewNode

func NewNode(l Loader, log *zerolog.Logger) *Node

NewNode returns a new Node linter.

func (*Node) Lint

func (n *Node) Lint(ctx context.Context) error

Lint a Node.

type PersistentVolume added in v0.3.0

type PersistentVolume struct {
	*Linter
}

PersistentVolume represents a PersistentVolume linter.

func NewPersistentVolume added in v0.3.0

func NewPersistentVolume(l Loader, log *zerolog.Logger) *PersistentVolume

NewPersistentVolume returns a new PersistentVolume linter.

func (*PersistentVolume) Lint added in v0.3.0

func (p *PersistentVolume) Lint(ctx context.Context) error

Lint a PersistentVolume.

type PersistentVolumeClaim added in v0.3.0

type PersistentVolumeClaim struct {
	*Linter
}

PersistentVolumeClaim represents a PersistentVolumeClaim linter.

func NewPersistentVolumeClaim added in v0.3.0

func NewPersistentVolumeClaim(l Loader, log *zerolog.Logger) *PersistentVolumeClaim

NewPersistentVolumeClaim returns a new PersistentVolumeClaim linter.

func (*PersistentVolumeClaim) Lint added in v0.3.0

Lint a PersistentVolumeClaim.

type Pod

type Pod struct {
	*Linter
}

Pod represents a Pod linter.

func NewPod

func NewPod(l Loader, log *zerolog.Logger) *Pod

NewPod returns a new pod linter.

func (*Pod) Lint

func (p *Pod) Lint(ctx context.Context) error

Lint a Pod.

type PodMetric

type PodMetric interface {
	CurrentCPU() int64
	CurrentMEM() int64
	Empty() bool
}

PodMetric tracks node metrics available and current range.

type Reference added in v0.2.0

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

Reference tracks a configuration reference.

type References added in v0.2.0

type References map[string]TypedReferences

References tracks configuration references.

type Secret added in v0.2.0

type Secret struct {
	*Linter
}

Secret represents a Secret linter.

func NewSecret added in v0.2.0

func NewSecret(l Loader, log *zerolog.Logger) *Secret

NewSecret returns a new Secret linter.

func (*Secret) Lint added in v0.2.0

func (s *Secret) Lint(ctx context.Context) error

Lint a Secret.

type Service

type Service struct {
	*Linter
}

Service represents a service linter.

func NewService

func NewService(l Loader, log *zerolog.Logger) *Service

NewService returns a new service linter.

func (*Service) Lint

func (s *Service) Lint(ctx context.Context) error

Lint a service.

type ServiceAccount added in v0.3.0

type ServiceAccount struct {
	*Linter
}

ServiceAccount represents a ServiceAccount linter.

func NewServiceAccount added in v0.3.0

func NewServiceAccount(l Loader, log *zerolog.Logger) *ServiceAccount

NewServiceAccount returns a new ServiceAccount linter.

func (*ServiceAccount) Lint added in v0.3.0

func (s *ServiceAccount) Lint(ctx context.Context) error

Lint a serviceaccount.

type Spinach added in v0.2.0

type Spinach interface {
	PodCPULimit() float64
	PodMEMLimit() float64
	NodeCPULimit() float64
	NodeMEMLimit() float64
	RestartsLimit() int

	CPUResourceLimits() config.Allocations
	MEMResourceLimits() config.Allocations

	Sections() []string
	LinterLevel() int
	ExcludedNS(ns string) bool
	ExcludedNode(n string) bool
}

Spinach represents a Popeye configuration object.

type StatefulSet added in v0.3.0

type StatefulSet struct {
	*Linter
}

StatefulSet represents a StatefulSet linter.

func NewStatefulSet added in v0.3.0

func NewStatefulSet(l Loader, log *zerolog.Logger) *StatefulSet

NewStatefulSet returns a new StatefulSet linter.

func (*StatefulSet) Lint added in v0.3.0

func (s *StatefulSet) Lint(ctx context.Context) error

Lint a StatefulSet.

type TypedReferences added in v0.2.0

type TypedReferences map[string]*Reference

TypedReferences tracks configuration type references.

Jump to

Keyboard shortcuts

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