Documentation ¶
Overview ¶
Package kubernetes contains all related files with filling metadata of kubernetes
Index ¶
- Constants
- Variables
- func AddNode(obj interface{})
- func AddPod(obj interface{})
- func AddReplicaSet(obj interface{})
- func AddService(obj interface{})
- func CompleteGVK(apiVersion string, kind string) string
- func DeleteNode(obj interface{})
- func DeletePod(obj interface{})
- func DeleteReplicaSet(obj interface{})
- func DeleteService(obj interface{})
- func GetWorkloadDataGroup() []*model.DataGroup
- func InitK8sHandler(options ...Option) error
- func LockMetadataCache()
- func NodeWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
- func PodWatch(clientSet *kubernetes.Clientset, graceDeletePeriod time.Duration, ...)
- func RLockMetadataCache()
- func RUnlockMetadataCache()
- func RsWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
- func SelectorsMatchLabels(selectors map[string]string, labels map[string]string) bool
- func ServiceWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
- func SetupCache(cache *K8sMetaDataCache, nodeMap *NodeMap, serviceMap *ServiceMap, ...)
- func TruncateContainerId(containerId string) string
- func UnlockMetadataCache()
- func UpdateNode(objOld interface{}, objNew interface{})
- func UpdatePod(objOld interface{}, objNew interface{})
- func UpdateReplicaSet(objOld interface{}, objNew interface{})
- func UpdateService(objOld interface{}, objNew interface{})
- type APIConfig
- type AuthType
- type BuiltInScheme
- type Controller
- type HostPortMap
- type IpPortKey
- type K8sContainerInfo
- type K8sMetaDataCache
- func (c *K8sMetaDataCache) AddByContainerId(containerId string, resource *K8sContainerInfo)
- func (c *K8sMetaDataCache) AddContainerByHostIpPort(hostIp string, hostPort uint32, containerInfo *K8sContainerInfo)
- func (c *K8sMetaDataCache) AddContainerByIpPort(ip string, port uint32, resource *K8sContainerInfo)
- func (c *K8sMetaDataCache) AddServiceByIpPort(ip string, port uint32, resource *K8sServiceInfo)
- func (c *K8sMetaDataCache) ClearAll()
- func (c *K8sMetaDataCache) DeleteByContainerId(containerId string)
- func (c *K8sMetaDataCache) DeleteContainerByHostIpPort(hostIp string, hostPort uint32)
- func (c *K8sMetaDataCache) DeleteContainerByIpPort(ip string, port uint32)
- func (c *K8sMetaDataCache) DeleteServiceByIpPort(ip string, port uint32)
- func (c *K8sMetaDataCache) GetByContainerId(containerId string) (*K8sContainerInfo, bool)
- func (c *K8sMetaDataCache) GetCacheContainerIdInfoSize() int
- func (c *K8sMetaDataCache) GetContainerByHostIpPort(hostIp string, hostPort uint32) (*K8sContainerInfo, bool)
- func (c *K8sMetaDataCache) GetContainerByIpPort(ip string, port uint32) (*K8sContainerInfo, bool)
- func (c *K8sMetaDataCache) GetNodeNameByIp(ip string) (string, bool)
- func (c *K8sMetaDataCache) GetPodByContainerId(containerId string) (*K8sPodInfo, bool)
- func (c *K8sMetaDataCache) GetPodByIp(ip string) (*K8sPodInfo, bool)
- func (c *K8sMetaDataCache) GetPodByIpPort(ip string, port uint32) (*K8sPodInfo, bool)
- func (c *K8sMetaDataCache) GetServiceByIpPort(ip string, port uint32) (*K8sServiceInfo, bool)
- func (c *K8sMetaDataCache) String() string
- type K8sPodInfo
- type K8sServiceInfo
- type MetaDataProviderConfig
- type NodeInfo
- type NodeMap
- type Option
- func WithAuthType(authType AuthType) Option
- func WithFetchReplicaSet(fetch bool) Option
- func WithGraceDeletePeriod(interval int) Option
- func WithKubeConfigDir(dir string) Option
- func WithMetaDataProviderConfig(mpCfg *MetaDataProviderConfig, ...) Option
- func WithNodeEventHander(handler cache.ResourceEventHandler) Option
- func WithPodEventHander(handler cache.ResourceEventHandler) Option
- func WithReplicaSetEventHander(handler cache.ResourceEventHandler) Option
- func WithServiceEventHander(handler cache.ResourceEventHandler) Option
- type ReplicaSetMap
- type ServiceMap
- type SetPreprocessingMetaDataCache
Constants ¶
const ( // AuthTypeNone means no auth is required AuthTypeNone AuthType = "none" // AuthTypeServiceAccount means to use the built-in service account that // K8s automatically provisions for each pod. AuthTypeServiceAccount AuthType = "serviceAccount" // AuthTypeKubeConfig uses local credentials like those used by kubectl. AuthTypeKubeConfig AuthType = "kubeConfig" // DefaultKubeConfigPath Default kubeconfig path DefaultKubeConfigPath string = "~/.kube/config" // DefaultGraceDeletePeriod is 60 seconds DefaultGraceDeletePeriod = time.Second * 60 )
const DeploymentKind = "deployment"
const ReplicaSetKind = "ReplicaSet"
Variables ¶
var ( MetaDataCache = New() MyNodeName string IsInitSuccess = false )
var GlobalNodeInfo = newNodeMap()
var GlobalPodInfo = newPodMap()
var GlobalRsInfo = newReplicaSetMap()
var GlobalServiceInfo = newServiceMap()
Functions ¶
func AddReplicaSet ¶
func AddReplicaSet(obj interface{})
func AddService ¶
func AddService(obj interface{})
func CompleteGVK ¶
CompleteGVK returns the complete string of the workload kind. If apiVersion is not one of the built-in groupVersion(see scheme.go), return {apiVersion}-{kind}; return {kind}, otherwise.
func DeleteNode ¶
func DeleteNode(obj interface{})
func DeleteReplicaSet ¶
func DeleteReplicaSet(obj interface{})
func DeleteService ¶
func DeleteService(obj interface{})
func GetWorkloadDataGroup ¶
func InitK8sHandler ¶
func LockMetadataCache ¶
func LockMetadataCache()
func NodeWatch ¶
func NodeWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
func PodWatch ¶
func PodWatch(clientSet *kubernetes.Clientset, graceDeletePeriod time.Duration, handler cache.ResourceEventHandler)
func RLockMetadataCache ¶
func RLockMetadataCache()
Huge Lock, only used when setup and check the reentrant lock before you call
func RUnlockMetadataCache ¶
func RUnlockMetadataCache()
func RsWatch ¶
func RsWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
func SelectorsMatchLabels ¶
SelectorsMatchLabels return true only if labels match all [keys:values] with selectors
func ServiceWatch ¶
func ServiceWatch(clientSet *kubernetes.Clientset, handler cache.ResourceEventHandler)
func SetupCache ¶
func SetupCache(cache *K8sMetaDataCache, nodeMap *NodeMap, serviceMap *ServiceMap, rsMap *ReplicaSetMap)
func TruncateContainerId ¶
TruncateContainerId slices the input containerId into two parts separated by "://", and return the first 12 bytes at most of the second part.
If no second part found, return empty string.
func UnlockMetadataCache ¶
func UnlockMetadataCache()
func UpdateNode ¶
func UpdateNode(objOld interface{}, objNew interface{})
func UpdateReplicaSet ¶
func UpdateReplicaSet(objOld interface{}, objNew interface{})
func UpdateService ¶
func UpdateService(objOld interface{}, objNew interface{})
Types ¶
type APIConfig ¶
type APIConfig struct { // How to authenticate to the K8s API server. This can be one of `none` // (for no auth), `serviceAccount` (to use the standard service account // token provided to the agent pod), or `kubeConfig` to use credentials // from user-defined file AuthType AuthType `mapstructure:"auth_type"` AuthFilePath string }
APIConfig contains options relevant to connecting to the K8s API
type AuthType ¶
type AuthType string
AuthType describes the type of authentication to use for the K8s API
type BuiltInScheme ¶
type BuiltInScheme struct {
// contains filtered or unexported fields
}
func NewKnownScheme ¶
func NewKnownScheme() *BuiltInScheme
func (*BuiltInScheme) IsBuiltInGV ¶
func (s *BuiltInScheme) IsBuiltInGV(groupVersion string) bool
type Controller ¶
type HostPortMap ¶
type HostPortMap struct { HostPortInfo map[string]*K8sContainerInfo // contains filtered or unexported fields }
func NewHostPortMap ¶
func NewHostPortMap() *HostPortMap
type K8sContainerInfo ¶
type K8sContainerInfo struct { ContainerId string Name string HostPortMap map[int32]int32 RefPodInfo *K8sPodInfo }
type K8sMetaDataCache ¶
type K8sMetaDataCache struct { ContainerIdInfo map[string]*K8sContainerInfo IpContainerInfo map[string]map[uint32]*K8sContainerInfo IpServiceInfo map[string]map[uint32]*K8sServiceInfo HostPortInfo *HostPortMap // contains filtered or unexported fields }
func New ¶
func New() *K8sMetaDataCache
func (*K8sMetaDataCache) AddByContainerId ¶
func (c *K8sMetaDataCache) AddByContainerId(containerId string, resource *K8sContainerInfo)
func (*K8sMetaDataCache) AddContainerByHostIpPort ¶
func (c *K8sMetaDataCache) AddContainerByHostIpPort(hostIp string, hostPort uint32, containerInfo *K8sContainerInfo)
func (*K8sMetaDataCache) AddContainerByIpPort ¶
func (c *K8sMetaDataCache) AddContainerByIpPort(ip string, port uint32, resource *K8sContainerInfo)
func (*K8sMetaDataCache) AddServiceByIpPort ¶
func (c *K8sMetaDataCache) AddServiceByIpPort(ip string, port uint32, resource *K8sServiceInfo)
func (*K8sMetaDataCache) ClearAll ¶
func (c *K8sMetaDataCache) ClearAll()
func (*K8sMetaDataCache) DeleteByContainerId ¶
func (c *K8sMetaDataCache) DeleteByContainerId(containerId string)
func (*K8sMetaDataCache) DeleteContainerByHostIpPort ¶
func (c *K8sMetaDataCache) DeleteContainerByHostIpPort(hostIp string, hostPort uint32)
func (*K8sMetaDataCache) DeleteContainerByIpPort ¶
func (c *K8sMetaDataCache) DeleteContainerByIpPort(ip string, port uint32)
func (*K8sMetaDataCache) DeleteServiceByIpPort ¶
func (c *K8sMetaDataCache) DeleteServiceByIpPort(ip string, port uint32)
func (*K8sMetaDataCache) GetByContainerId ¶
func (c *K8sMetaDataCache) GetByContainerId(containerId string) (*K8sContainerInfo, bool)
func (*K8sMetaDataCache) GetCacheContainerIdInfoSize ¶
func (c *K8sMetaDataCache) GetCacheContainerIdInfoSize() int
func (*K8sMetaDataCache) GetContainerByHostIpPort ¶
func (c *K8sMetaDataCache) GetContainerByHostIpPort(hostIp string, hostPort uint32) (*K8sContainerInfo, bool)
func (*K8sMetaDataCache) GetContainerByIpPort ¶
func (c *K8sMetaDataCache) GetContainerByIpPort(ip string, port uint32) (*K8sContainerInfo, bool)
func (*K8sMetaDataCache) GetNodeNameByIp ¶
func (c *K8sMetaDataCache) GetNodeNameByIp(ip string) (string, bool)
func (*K8sMetaDataCache) GetPodByContainerId ¶
func (c *K8sMetaDataCache) GetPodByContainerId(containerId string) (*K8sPodInfo, bool)
func (*K8sMetaDataCache) GetPodByIp ¶
func (c *K8sMetaDataCache) GetPodByIp(ip string) (*K8sPodInfo, bool)
func (*K8sMetaDataCache) GetPodByIpPort ¶
func (c *K8sMetaDataCache) GetPodByIpPort(ip string, port uint32) (*K8sPodInfo, bool)
func (*K8sMetaDataCache) GetServiceByIpPort ¶
func (c *K8sMetaDataCache) GetServiceByIpPort(ip string, port uint32) (*K8sServiceInfo, bool)
func (*K8sMetaDataCache) String ¶
func (c *K8sMetaDataCache) String() string
type K8sPodInfo ¶
type K8sPodInfo struct { UID string Ip string PodName string Ports []int32 HostPorts []int32 ContainerIds []string Labels map[string]string // TODO: There may be multiple kinds of workload or services for the same pod WorkloadKind string WorkloadName string Namespace string NodeName string NodeAddress string ServiceInfo *K8sServiceInfo // contains filtered or unexported fields }
type K8sServiceInfo ¶
type MetaDataProviderConfig ¶
type MetaDataProviderConfig struct { Enable bool `mapstructure:"enable"` // print every K8s Metadata received from mp, used for debug EnableTrace bool `mapstructure:"enable_trace"` // Endpoint is where metadata-provider deloyed and provide service // e.g "http://localhost:9504" Endpoint string `mapstructure:"endpoint"` }
type Option ¶
type Option func(cfg *config)
func WithAuthType ¶
WithAuthType sets way of authenticating kubernetes api-server Supported AuthTypeNone, AuthTypeServiceAccount, AuthTypeKubeConfig
func WithFetchReplicaSet ¶
WithFetchReplicaSet sets whether to fetch ReplicaSet information.
func WithGraceDeletePeriod ¶
WithGraceDeletePeriod sets the graceful period of deleting Pod's metadata after receiving "delete" event from client-go.
func WithKubeConfigDir ¶
WithKubeConfigDir sets the directory where the file "kubeconfig" is stored
func WithMetaDataProviderConfig ¶
func WithMetaDataProviderConfig(mpCfg *MetaDataProviderConfig, listAndWatch func(SetPreprocessingMetaDataCache) error) Option
func WithNodeEventHander ¶
func WithNodeEventHander(handler cache.ResourceEventHandler) Option
func WithPodEventHander ¶
func WithPodEventHander(handler cache.ResourceEventHandler) Option
func WithReplicaSetEventHander ¶
func WithReplicaSetEventHander(handler cache.ResourceEventHandler) Option
func WithServiceEventHander ¶
func WithServiceEventHander(handler cache.ResourceEventHandler) Option
type ReplicaSetMap ¶
type ReplicaSetMap struct { // Key is ${namespace}/${name} Info map[string]Controller // contains filtered or unexported fields }
func (*ReplicaSetMap) GetOwnerReference ¶
func (rs *ReplicaSetMap) GetOwnerReference(key string) (Controller, bool)
func (*ReplicaSetMap) GetSize ¶
func (rs *ReplicaSetMap) GetSize() int
type ServiceMap ¶
type ServiceMap struct { // Service name could be duplicated in different namespace, so here // service name must not be the key of map. Therefore, a map with the // following structure is constructed. // // namespace1: // servicename1: ServiceInfo{} // servicename2: ServiceInfo{} // namespace2: // servicename1: ServiceInfo{} ServiceMap map[string]map[string]*K8sServiceInfo // contains filtered or unexported fields }
func (*ServiceMap) GetServiceMatchLabels ¶
func (s *ServiceMap) GetServiceMatchLabels(namespace string, labels map[string]string) []*K8sServiceInfo
GetServiceMatchLabels gets K8sServiceInfos which match labels in such namespace. Return empty slice if not found. Note there may be multiple matches.
type SetPreprocessingMetaDataCache ¶
type SetPreprocessingMetaDataCache func(cache *K8sMetaDataCache, nodeMap *NodeMap, serviceMap *ServiceMap, rsMap *ReplicaSetMap)