cache

package
v0.0.0-...-10d5974 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const (
	POD_PHASE_RUNNING = "Running"
	POD_PHASE_PENDING = "Pending"
)

Variables

View Source
var Querier = &Query{
	CacheMap: NonCache,
}

Functions

func NewNodeList

func NewNodeList(_ resource.ResType, resList []*resource.Resource) resource.ResHandler

func NewPodList

func NewPodList(_ resource.ResType, resList []*resource.Resource) resource.ResHandler

func NewServiceList

func NewServiceList(_ resource.ResType, resList []*resource.Resource) resource.ResHandler

func SetupCacheMap

func SetupCacheMap(cacheMap CacheMap)

Types

type CacheMap

type CacheMap interface {
	AddResHandler(clusterId string, resType resource.ResType, handler resource.ResHandler)
	AddResHandlers(clusterId string, handlers *HandlerMap)

	GetCache(clusterId string, resType resource.ResType) (resource.ResHandler, bool)
	GetCaches(resType resource.ResType) ([]resource.ResHandler, bool)
}
var NonCache CacheMap = &NonCacheMap{}

type ClusterCacheMap

type ClusterCacheMap struct {
	// ClusterID -> handlersMap
	Caches sync.Map
}

func NewClusterCacheList

func NewClusterCacheList() *ClusterCacheMap

func (*ClusterCacheMap) AddResHandler

func (b *ClusterCacheMap) AddResHandler(clusterId string, resType resource.ResType, handler resource.ResHandler)

AddResHandler implements Querier.

func (*ClusterCacheMap) AddResHandlers

func (b *ClusterCacheMap) AddResHandlers(clusterId string, handlers *HandlerMap)

AddResHandlers implements Querier.

func (*ClusterCacheMap) GetCache

func (b *ClusterCacheMap) GetCache(clusterId string, resType resource.ResType) (resource.ResHandler, bool)

func (*ClusterCacheMap) GetCaches

func (b *ClusterCacheMap) GetCaches(resType resource.ResType) ([]resource.ResHandler, bool)

GetCaches implements CacheMap.

type HandlerMap

type HandlerMap struct {
	Handlers map[resource.ResType]resource.ResHandler

	sync.RWMutex
}

func (*HandlerMap) AddHandler

func (m *HandlerMap) AddHandler(resType resource.ResType, handler resource.ResHandler)

func (*HandlerMap) GetHandler

func (m *HandlerMap) GetHandler(resType resource.ResType) (resource.ResHandler, bool)

type IQuery

type IQuery interface {
	SetCacheMap(cacheMap CacheMap)
	QueryResource(w http.ResponseWriter, r *http.Request)
}
var QueryInterface IQuery = Querier

type Node

type Node struct {
	*resource.Resource
}

func (*Node) ExternalIP

func (node *Node) ExternalIP() string

func (*Node) InternalIP

func (node *Node) InternalIP() string

func (*Node) NodeHostName

func (node *Node) NodeHostName() string

func (*Node) NodeIP

func (node *Node) NodeIP() string

type NodeList

type NodeList struct {
	*resource.Resources

	UIDMap  sync.Map
	IP2Node sync.Map
}

func (*NodeList) AddResource

func (nl *NodeList) AddResource(res *resource.Resource)

func (*NodeList) DeleteResource

func (nl *NodeList) DeleteResource(res *resource.Resource)

func (*NodeList) GetNodeByIP

func (nl *NodeList) GetNodeByIP(nodeIP string) *Node

func (*NodeList) Reset

func (nl *NodeList) Reset(resList []*resource.Resource)

func (*NodeList) UpdateResource

func (nl *NodeList) UpdateResource(res *resource.Resource)

type NonCacheMap

type NonCacheMap struct{}

func (*NonCacheMap) AddResHandler

func (n *NonCacheMap) AddResHandler(clusterId string, resType resource.ResType, handler resource.ResHandler)

AddResHandler implements CacheMap.

func (*NonCacheMap) AddResHandlers

func (n *NonCacheMap) AddResHandlers(clusterId string, handlers *HandlerMap)

AddResHandlers implements CacheMap.

func (*NonCacheMap) GetCache

func (n *NonCacheMap) GetCache(clusterId string, resType resource.ResType) (resource.ResHandler, bool)

GetCache implements CacheMap.

func (*NonCacheMap) GetCaches

func (n *NonCacheMap) GetCaches(resType resource.ResType) ([]resource.ResHandler, bool)

GetCaches implements CacheMap.

type OwnerReferences

type OwnerReferences struct {
	UID  string
	Kind string
	Name string
}

type Pod

type Pod struct {
	*resource.Resource
}

func (*Pod) ContainerIDs

func (p *Pod) ContainerIDs() []string

func (*Pod) GetOwnerReferences

func (p *Pod) GetOwnerReferences(guessDeployment bool) []OwnerReferences

func (*Pod) HostIP

func (p *Pod) HostIP() string

func (*Pod) IsHostNetWork

func (p *Pod) IsHostNetWork() bool

func (*Pod) Labels

func (p *Pod) Labels() map[string]string

func (*Pod) NS

func (p *Pod) NS() string

func (*Pod) NodeName

func (p *Pod) NodeName() string

func (*Pod) Phase

func (p *Pod) Phase() string

func (*Pod) PodIP

func (p *Pod) PodIP() string

type PodList

type PodList struct {
	*resource.Resources
	// POD UID -> *Pod
	UIDMap sync.Map
	// Namespace/Name -> *Pod
	PodMap sync.Map
	// ContainerID -> *Pod
	ContainerID2Pod sync.Map
	// IP -> *Pod only store not hostNetwork IP
	// TODO 重写sync.Map的store方法,丢弃key为空的记录
	IP2PodMap sync.Map
}

func (*PodList) AddResource

func (pl *PodList) AddResource(res *resource.Resource)

func (*PodList) DeleteResource

func (pl *PodList) DeleteResource(res *resource.Resource)

func (*PodList) Reset

func (pl *PodList) Reset(resList []*resource.Resource)

func (*PodList) UpdateResource

func (pl *PodList) UpdateResource(res *resource.Resource)

type PodServiceMap

type PodServiceMap struct {
	Namespace     string
	PodUIDMap     sync.Map
	ServiceUIDMap sync.Map
}

type Query

type Query struct {
	CacheMap
}

func (*Query) GetNodeByIP

func (q *Query) GetNodeByIP(clusterID string, IP string) (*Node, bool)

func (*Query) GetPodByContainerId

func (q *Query) GetPodByContainerId(clusterID string, containerId string) (*Pod, bool)

func (*Query) GetPodByIP

func (q *Query) GetPodByIP(clusterID string, podIP string) (*Pod, bool)

func (*Query) GetPodByNSAndName

func (q *Query) GetPodByNSAndName(clusterID string, namespace string, name string) (*Pod, bool)

func (*Query) GetPodByUID

func (q *Query) GetPodByUID(clusterID string, UID resource.ResUID) (*Pod, bool)

func (*Query) GetServiceByIP

func (q *Query) GetServiceByIP(clusterID string, serviceIP string) (*Service, bool)

func (*Query) ListPod

func (q *Query) ListPod(clusterID string) (pods []*Pod)

func (*Query) ListService

func (q *Query) ListService(clusterID string) (services []*Service)

func (*Query) QueryResource

func (q *Query) QueryResource(w http.ResponseWriter, r *http.Request)

func (*Query) SetCacheMap

func (q *Query) SetCacheMap(cacheMap CacheMap)

type QueryResRequest

type QueryResRequest struct {
	ClusterID    string
	ResType      resource.ResType
	ResName      string
	ResNamespace string
	IP           string
	ListAll      bool
}

type ResInfo

type ResInfo struct {
	IsFind bool
	Object any
}

type Service

type Service struct {
	*resource.Resource
	// contains filtered or unexported fields
}

func (*Service) AddEndpoint

func (s *Service) AddEndpoint(pod *Pod)

func (*Service) DeleteEndpoint

func (s *Service) DeleteEndpoint(oldPod *Pod)

func (*Service) EndPoints

func (s *Service) EndPoints() []string

func (*Service) IP

func (s *Service) IP() string

func (*Service) MatchPod

func (s *Service) MatchPod(pod *Pod) bool

func (*Service) MatchedPods

func (s *Service) MatchedPods() []*resource.ResUID

func (*Service) NS

func (s *Service) NS() string

func (*Service) Selectors

func (s *Service) Selectors() map[string]string

func (*Service) SvcPorts

func (s *Service) SvcPorts() map[uint16]uint16

func (*Service) UID

func (s *Service) UID() resource.ResUID

type ServiceList

type ServiceList struct {
	*resource.Resources
	// Service UID -> *Service
	UIDMap sync.Map
	// Namespace/Name -> *Service
	ServiceMap sync.Map
	// IP -> *Service
	IP2ServiceMap sync.Map

	IsPodWatch bool
	// contains filtered or unexported fields
}

ServiceList可以同时处理Service资源和Pod资源 如果同时处理Pod资源,会维护Service和Pod的关系

func (*ServiceList) AddResource

func (sl *ServiceList) AddResource(res *resource.Resource)

func (*ServiceList) DeleteResource

func (sl *ServiceList) DeleteResource(res *resource.Resource)

func (*ServiceList) EnablePodMatch

func (sl *ServiceList) EnablePodMatch()

func (*ServiceList) Reset

func (sl *ServiceList) Reset(resList []*resource.Resource)

func (*ServiceList) UpdateResource

func (sl *ServiceList) UpdateResource(res *resource.Resource)

type SingleClusterCacheMap

type SingleClusterCacheMap struct {
	Handlers *HandlerMap
}

func NewSingleClusterCacheList

func NewSingleClusterCacheList() *SingleClusterCacheMap

func (*SingleClusterCacheMap) AddResHandler

func (b *SingleClusterCacheMap) AddResHandler(_ string, resType resource.ResType, handler resource.ResHandler)

AddResHandler implements Querier.z

func (*SingleClusterCacheMap) AddResHandlers

func (b *SingleClusterCacheMap) AddResHandlers(_ string, handlers *HandlerMap)

AddResHandlers implements Querier.

func (*SingleClusterCacheMap) GetCache

func (b *SingleClusterCacheMap) GetCache(clusterId string, resType resource.ResType) (resource.ResHandler, bool)

GetCache implements Querier.

func (*SingleClusterCacheMap) GetCaches

func (b *SingleClusterCacheMap) GetCaches(resType resource.ResType) ([]resource.ResHandler, bool)

GetCaches implements CacheMap.

Jump to

Keyboard shortcuts

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