kubernetes

package
v0.0.0-...-122797d Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	AuthTypeNone           string = "none"
	AuthTypeServiceAccount string = "serviceAccount"
	AuthTypeKubeConfig     string = "kubeConfig"

	// DefaultKubeConfigPath Default kubeconfig path
	DefaultKubeConfigPath string = "~/.kube/config"

	// DefaultMetaSetting
	DefaultAPONS         string = "apo"
	DefaultCMNAME        string = "apo-victoria-metrics-alert-server-alert-rules-config"
	DefaultAlertRuleFile string = "alert-rules.yaml"
	DefaultAMCMName      string = "apo-alertmanager-config"
	DefaultAMConfigFile  string = "alertmanager.yaml"
	DefaultVCNAME        string = "apo-vector-config"
	DefaultVCConfigFile  string = "aggregator.yaml"
)
View Source
const (
	AppLabelVal       = "应用指标"
	InfraLabelVal     = "主机相关"
	NetLabelVal       = "网络相关"
	ContainerLabelVal = "容器相关"
	CustomLabelVal    = "用户自定义组"

	AppLabelKey       = "app"
	InfraLabelKey     = "infra"
	NetLabelKey       = "network"
	ContainerLabelKey = "container"
	CustomLabelKey    = "custom"
)

Variables

View Source
var ErrKubernetesRepoNotReady = errors.New("kubernetes repo is not ready")

Functions

func ContainsIn

func ContainsIn(slices []string, expected string) bool

func GetLabel

func GetLabel(group string) (string, bool)

func ValidateAMConfigReceiver

func ValidateAMConfigReceiver(receiver amconfig.Receiver) error

func ValidateAlertRule

func ValidateAlertRule(rule request.AlertRule) error

Types

type AlertGroup

type AlertGroup struct {
	Name        string          `json:"name"`
	Interval    model.Duration  `json:"interval,omitempty"`
	QueryOffset *model.Duration `json:"query_offset,omitempty"`
	Limit       int             `json:"limit,omitempty"`
}

type AlertRules

type AlertRules struct {
	Rules []*request.AlertRule

	Groups []AlertGroup
}

func ParseAlertRules

func ParseAlertRules(strContent string) (*AlertRules, error)

type Metadata

type Metadata struct {
	AlertRulesMap map[string]*AlertRules

	AMConfigMap map[string]*amconfig.Config
	// contains filtered or unexported fields
}

func (*Metadata) AddAMConfigReceiver

func (m *Metadata) AddAMConfigReceiver(configFile string, receiver amconfig.Receiver) error

func (*Metadata) AddAlertRule

func (m *Metadata) AddAlertRule(configFile string, alertRule request.AlertRule) error

func (*Metadata) AlertManagerConfigMarshalToYaml

func (m *Metadata) AlertManagerConfigMarshalToYaml(configFile string) ([]byte, error)

func (*Metadata) AlertRuleMarshalToYaml

func (m *Metadata) AlertRuleMarshalToYaml(configFile string) ([]byte, error)

func (*Metadata) CheckAlertRuleExists

func (m *Metadata) CheckAlertRuleExists(configFile, group, alert string) (bool, error)

func (*Metadata) DeleteAMConfigReceiver

func (m *Metadata) DeleteAMConfigReceiver(configFile string, name string) (bool, error)

func (*Metadata) DeleteAlertRule

func (m *Metadata) DeleteAlertRule(configFile string, group, alert string) bool

func (*Metadata) GetAMConfigReceiver

func (m *Metadata) GetAMConfigReceiver(configFile string, filter *request.AMConfigReceiverFilter, pageParam *request.PageParam) ([]amconfig.Receiver, int)

func (*Metadata) GetAlertRules

func (m *Metadata) GetAlertRules(configFile string, filter *request.AlertRuleFilter, pageParam *request.PageParam) ([]*request.AlertRule, int)

func (*Metadata) SetAMConfig

func (m *Metadata) SetAMConfig(configFile string, configs *amconfig.Config)

func (*Metadata) SetAlertRules

func (m *Metadata) SetAlertRules(configFile string, rules *AlertRules)

func (*Metadata) UpdateAMConfigReceiver

func (m *Metadata) UpdateAMConfigReceiver(configFile string, receiver amconfig.Receiver, oldName string) error

func (*Metadata) UpdateAlertRule

func (m *Metadata) UpdateAlertRule(configFile string, alertRule request.AlertRule, oldGroup, oldAlert string) error

type NoneAPI

type NoneAPI struct{}

func (*NoneAPI) AddAMConfigReceiver

func (n *NoneAPI) AddAMConfigReceiver(configFile string, receiver amconfig.Receiver) error

func (*NoneAPI) AddAlertRule

func (n *NoneAPI) AddAlertRule(configFile string, alertRule request.AlertRule) error

func (*NoneAPI) CheckAlertRule

func (n *NoneAPI) CheckAlertRule(configFile, group, alert string) (bool, error)

func (*NoneAPI) DeleteAMConfigReceiver

func (n *NoneAPI) DeleteAMConfigReceiver(configFile string, name string) error

DeleteAMConfigReceiver implements Repo.

func (*NoneAPI) DeleteAlertRule

func (n *NoneAPI) DeleteAlertRule(configFile string, group string, alert string) error

func (*NoneAPI) GetAMConfigReceiver

func (n *NoneAPI) GetAMConfigReceiver(configFile string, filter *request.AMConfigReceiverFilter, pageParam *request.PageParam, syncNow bool) ([]amconfig.Receiver, int)

GetAMConfigReceiver implements Repo.

func (*NoneAPI) GetAlertRuleConfigFile

func (n *NoneAPI) GetAlertRuleConfigFile(alertRuleFile string) (map[string]string, error)

GetAlertRuleConfigFile implements Repo.

func (*NoneAPI) GetAlertRules

func (n *NoneAPI) GetAlertRules(configFile string, filter *request.AlertRuleFilter, pageParam *request.PageParam, syncNow bool) ([]*request.AlertRule, int)

func (*NoneAPI) GetNamespaceInfo

func (n *NoneAPI) GetNamespaceInfo(namespace string) (*v1.Namespace, error)

func (*NoneAPI) GetNamespaceList

func (n *NoneAPI) GetNamespaceList() (*v1.NamespaceList, error)

func (*NoneAPI) GetPodInfo

func (n *NoneAPI) GetPodInfo(namespace string, pod string) (*v1.Pod, error)

func (*NoneAPI) GetPodList

func (n *NoneAPI) GetPodList(namespace string) (*v1.PodList, error)

func (*NoneAPI) GetVectorConfigFile

func (n *NoneAPI) GetVectorConfigFile() (map[string]string, error)

GetVectorConfigFile implements Repo.

func (*NoneAPI) SyncNow

func (n *NoneAPI) SyncNow() error

SyncNow implements Repo.

func (*NoneAPI) UpdateAMConfigReceiver

func (n *NoneAPI) UpdateAMConfigReceiver(configFile string, receiver amconfig.Receiver, oldName string) error

UpdateAMConfigReceiver implements Repo.

func (*NoneAPI) UpdateAlertRule

func (n *NoneAPI) UpdateAlertRule(configFile string, alertRule request.AlertRule, oldGroup, oldAlert string) error

func (*NoneAPI) UpdateAlertRuleConfigFile

func (n *NoneAPI) UpdateAlertRuleConfigFile(configFile string, content []byte) error

UpdateAlertRuleConfigFile implements Repo.

func (*NoneAPI) UpdateVectorConfigFile

func (n *NoneAPI) UpdateVectorConfigFile(content []byte) error

UpdateVectorConfigFile implements Repo.

type Repo

type Repo interface {
	// Sync with K8sAPIServer
	SyncNow() error

	GetAlertRuleConfigFile(alertRuleFile string) (map[string]string, error)
	UpdateAlertRuleConfigFile(configFile string, content []byte) error
	GetVectorConfigFile() (map[string]string, error)
	UpdateVectorConfigFile(content []byte) error

	GetAlertRules(configFile string, filter *request.AlertRuleFilter, pageParam *request.PageParam, syncNow bool) ([]*request.AlertRule, int)
	UpdateAlertRule(configFile string, alertRule request.AlertRule, oldGroup, oldAlert string) error
	AddAlertRule(configFile string, alertRule request.AlertRule) error
	DeleteAlertRule(configFile string, group, alert string) error
	CheckAlertRule(configFile, group, alert string) (bool, error)

	GetAMConfigReceiver(configFile string, filter *request.AMConfigReceiverFilter, pageParam *request.PageParam, syncNow bool) ([]amconfig.Receiver, int)
	AddAMConfigReceiver(configFile string, receiver amconfig.Receiver) error
	UpdateAMConfigReceiver(configFile string, receiver amconfig.Receiver, oldName string) error
	DeleteAMConfigReceiver(configFile string, name string) error

	GetNamespaceList() (*v1.NamespaceList, error)
	GetNamespaceInfo(namespace string) (*v1.Namespace, error)
	GetPodList(namespace string) (*v1.PodList, error)
	GetPodInfo(namespace string, pod string) (*v1.Pod, error)
}
var NoneRepo Repo = &NoneAPI{}

func New

func New(logger *zap.Logger, authType, authFilePath string, setting config.MetadataSettings) (Repo, error)

Jump to

Keyboard shortcuts

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