// NewResourceManager returns a ResourceManager with the internal maps initialized.
NewResourceManager returns a ResourceManager with the internal maps initialized.
// NewResourceManager returns a ResourceManager with the internal maps initialized .
func NewResourceManager(k8sClient kubernetes.Interface) *ResourceManager {
	rm := ResourceManager{
		pods:         make(map[string]*v1.Pod, 0),
		deletingPods: make(map[string]*v1.Pod, 0),
		configMapRef: make(map[string]int64, 0),
		secretRef:    make(map[string]int64, 0),
		configMaps:   make(map[string]*v1.ConfigMap, 0),
		secrets:      make(map[string]*v1.Secret, 0),
		k8sClient:    k8sClient,
	}
	go rm.watchConfigMaps()
	go rm.watchSecrets()
	tick := time.Tick(5 * time.Minute)
	go func() {
		for range tick {
			rm.Lock()
			for n, c := range rm.secretRef {
				if c <= 0 {
					delete(rm.secretRef, n)
				}
			}
			for n := range rm.secrets {
				if _, ok := rm.secretRef[n]; !ok {
					delete(rm.secrets, n)
				}
			}
			for n, c := range rm.configMapRef {
				if c <= 0 {
					delete(rm.configMapRef, n)
				}
			}
			for n := range rm.configMaps {
				if _, ok := rm.configMapRef[n]; !ok {
					delete(rm.configMaps, n)
				}
			}
			rm.Unlock()
		}
	}()
	return &rm
}
func NewResourceManager ( k8sClient kubernetes . Interface ) * ResourceManager { rm := ResourceManager { pods : make ( map [ string ] * v1 . Pod , 0 ) , deletingPods : make ( map [ string ] * v1 . Pod , 0 ) , configMapRef : make ( map [ string ] int64 , 0 ) , secretRef : make ( map [ string ] int64 , 0 ) , configMaps : make ( map [ string ] * v1 . ConfigMap , 0 ) , secrets : make ( map [ string ] * v1 . Secret , 0 ) , k8sClient : k8sClient , } go rm . watchConfigMaps ( ) go rm . watchSecrets ( ) tick := time . Tick ( 5 * time . Minute ) go func ( ) { for range tick { rm . Lock ( ) for n , c := range rm . secretRef { if c <= 0 { delete ( rm . secretRef , n ) } } for n := range rm . secrets { if _ , ok := rm . secretRef [ n ] ; ! ok { delete ( rm . secrets , n ) } } for n , c := range rm . configMapRef { if c <= 0 { delete ( rm . configMapRef , n ) } } for n := range rm . configMaps { if _ , ok := rm . configMapRef [ n ] ; ! ok { delete ( rm . configMaps , n ) } } rm . Unlock ( ) } } ( ) return & rm }
NewResourceManager returns a ResourceManager with the internal maps initialized.
NewResourceManager returns a ResourceManager with the internal maps initialized .