analysis

package
v2.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	NormalResultOutput string = "没有检测到问题"
)

Variables

View Source
var (
	AnalyzerErrorsMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "analyzer_errors",
		Help: "Number of errors detected by analyzer",
	}, []string{"analyzer_name", "object_name", "namespace"})
)

Functions

func CheckCronScheduleIsValid

func CheckCronScheduleIsValid(schedule string) (bool, error)

Check CRON schedule format

func EnsureDirExists

func EnsureDirExists(dir string) error

func FetchLatestEvent

func FetchLatestEvent(ctx context.Context, kubernetesClient *Client, namespace string, name string) (*v1.Event, error)

func FileExists

func FileExists(path string) (bool, error)

func GetAnalyzerMap

func GetAnalyzerMap() (map[string]IAnalyzer, map[string]IAnalyzer)

func GetParent

func GetParent(client *Client, meta metav1.ObjectMeta) (string, bool)

func GetPodListByLabels

func GetPodListByLabels(client k.Interface,
	namespace string,
	labels map[string]string) (*v1.PodList, error)

func ListFilters

func ListFilters() ([]string, []string, []string)

func MaskString

func MaskString(input string) string

func RemoveDuplicates

func RemoveDuplicates(slice []string) ([]string, []string)

func ReplaceIfMatch

func ReplaceIfMatch(text string, pattern string, replacement string) string

func SliceContainsString

func SliceContainsString(slice []string, s string) bool

func SliceDiff

func SliceDiff(source, dest []string) []string

Types

type Analysis

type Analysis struct {
	Context            context.Context
	Filters            []string
	Client             *Client
	AIClient           llm.ILLM
	Results            []Result
	Errors             []string
	Namespace          string
	Cache              cache.ICache
	Explain            bool
	MaxConcurrency     int
	AnalysisAIProvider string // The name of the AI Provider used for this analysis
	WithDoc            bool
}

func NewAnalysis

func NewAnalysis(ctx context.Context, hubserverAddr, clusterID string, llmClient llm.ILLM, filters []string, namespace string, noCache bool, explain bool, maxConcurrency int, withDoc bool) (*Analysis, error)

func (*Analysis) GetAIResults

func (a *Analysis) GetAIResults(anonymize bool) error

func (*Analysis) PrintOutput

func (a *Analysis) PrintOutput(format string) ([]byte, error)

func (*Analysis) RunAnalysis

func (a *Analysis) RunAnalysis(activeFilters []string)

type AnalysisErrors

type AnalysisErrors []string

type AnalysisStatus

type AnalysisStatus string
const (
	StateOK              AnalysisStatus = "OK"
	StateProblemDetected AnalysisStatus = "ProblemDetected"
)

type Analyzer

type Analyzer struct {
	Client        *Client
	Context       context.Context
	Namespace     string
	AIClient      llm.ILLM
	PreAnalysis   map[string]PreAnalysis
	Results       []Result
	OpenapiSchema *openapi_v2.Document
}

type Client

type Client struct {
	Client        kubernetes.Interface
	RestClient    rest.Interface
	Config        *rest.Config
	ServerVersion *version.Info
}

func NewClient

func NewClient(hubserverAddr, clusterID string) (*Client, error)

func (*Client) GetClient

func (c *Client) GetClient() kubernetes.Interface

func (*Client) GetConfig

func (c *Client) GetConfig() *rest.Config

func (*Client) GetRestClient

func (c *Client) GetRestClient() rest.Interface

type CronJobAnalyzer

type CronJobAnalyzer struct{}

func (CronJobAnalyzer) Analyze

func (analyzer CronJobAnalyzer) Analyze(a Analyzer) ([]Result, error)

type DeploymentAnalyzer

type DeploymentAnalyzer struct {
}

DeploymentAnalyzer is an analyzer that checks for misconfigured Deployments

func (DeploymentAnalyzer) Analyze

func (d DeploymentAnalyzer) Analyze(a Analyzer) ([]Result, error)

Analyze scans all namespaces for Deployments with misconfigurations

type DeploymentInfo

type DeploymentInfo struct {
	*appsv1.Deployment
}

func (DeploymentInfo) GetPodSpec

func (d DeploymentInfo) GetPodSpec() corev1.PodSpec

type Failure

type Failure struct {
	Text          string
	KubernetesDoc string
	Sensitive     []Sensitive
}

type HpaAnalyzer

type HpaAnalyzer struct{}

func (HpaAnalyzer) Analyze

func (HpaAnalyzer) Analyze(a Analyzer) ([]Result, error)

type IAnalyzer

type IAnalyzer interface {
	Analyze(analysis Analyzer) ([]Result, error)
}

type IngressAnalyzer

type IngressAnalyzer struct{}

func (IngressAnalyzer) Analyze

func (IngressAnalyzer) Analyze(a Analyzer) ([]Result, error)

type JsonOutput

type JsonOutput struct {
	Provider string         `json:"provider"`
	Errors   AnalysisErrors `json:"errors"`
	Status   AnalysisStatus `json:"status"`
	Problems int            `json:"problems"`
	Results  []Result       `json:"results"`
}

type NetworkPolicyAnalyzer

type NetworkPolicyAnalyzer struct{}

func (NetworkPolicyAnalyzer) Analyze

func (NetworkPolicyAnalyzer) Analyze(a Analyzer) ([]Result, error)

type NodeAnalyzer

type NodeAnalyzer struct{}

func (NodeAnalyzer) Analyze

func (NodeAnalyzer) Analyze(a Analyzer) ([]Result, error)

type PdbAnalyzer

type PdbAnalyzer struct{}

func (PdbAnalyzer) Analyze

func (PdbAnalyzer) Analyze(a Analyzer) ([]Result, error)

type PodAnalyzer

type PodAnalyzer struct {
}

func (PodAnalyzer) Analyze

func (PodAnalyzer) Analyze(a Analyzer) ([]Result, error)

type PodInfo

type PodInfo interface {
	GetPodSpec() corev1.PodSpec
}

type PreAnalysis

type PreAnalysis struct {
	Pod                      v1.Pod
	FailureDetails           []Failure
	Deployment               appsv1.Deployment
	ReplicaSet               appsv1.ReplicaSet
	PersistentVolumeClaim    v1.PersistentVolumeClaim
	Endpoint                 v1.Endpoints
	Ingress                  networkv1.Ingress
	HorizontalPodAutoscalers autov1.HorizontalPodAutoscaler
	PodDisruptionBudget      policyv1.PodDisruptionBudget
	StatefulSet              appsv1.StatefulSet
	NetworkPolicy            networkv1.NetworkPolicy
	Node                     v1.Node
}

type PvcAnalyzer

type PvcAnalyzer struct{}

func (PvcAnalyzer) Analyze

func (PvcAnalyzer) Analyze(a Analyzer) ([]Result, error)

type ReplicaSetAnalyzer

type ReplicaSetAnalyzer struct{}

func (ReplicaSetAnalyzer) Analyze

func (ReplicaSetAnalyzer) Analyze(a Analyzer) ([]Result, error)

type ReplicaSetInfo

type ReplicaSetInfo struct {
	*appsv1.ReplicaSet
}

define a structure for ReplicaSet

func (ReplicaSetInfo) GetPodSpec

func (rs ReplicaSetInfo) GetPodSpec() corev1.PodSpec

type ReplicationControllerInfo

type ReplicationControllerInfo struct {
	*corev1.ReplicationController
}

define a structure for ReplicationController

func (ReplicationControllerInfo) GetPodSpec

func (rc ReplicationControllerInfo) GetPodSpec() corev1.PodSpec

type Result

type Result struct {
	Kind         string    `json:"kind"`
	Name         string    `json:"name"`
	Error        []Failure `json:"error"`
	Details      string    `json:"details"`
	ParentObject string    `json:"parentObject"`
}

type Sensitive

type Sensitive struct {
	Unmasked string
	Masked   string
}

type ServiceAnalyzer

type ServiceAnalyzer struct{}

func (ServiceAnalyzer) Analyze

func (ServiceAnalyzer) Analyze(a Analyzer) ([]Result, error)

type StatefulSetAnalyzer

type StatefulSetAnalyzer struct{}

func (StatefulSetAnalyzer) Analyze

func (StatefulSetAnalyzer) Analyze(a Analyzer) ([]Result, error)

type StatefulSetInfo

type StatefulSetInfo struct {
	*appsv1.StatefulSet
}

define a structure for StatefulSet

func (StatefulSetInfo) GetPodSpec

func (ss StatefulSetInfo) GetPodSpec() corev1.PodSpec

implement PodInfo for StatefulSetInfo

Jump to

Keyboard shortcuts

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