-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//nolint:all | ||
package v1alpha1 | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider" | ||
) | ||
|
||
type Manager struct { | ||
Region string | ||
// kms multi-account client pool | ||
KmsClientMap sync.Map | ||
// dkms multi-instance client pool | ||
DedicateKmsClientMap sync.Map | ||
// oos multi-account client pool | ||
OosClientMap sync.Map | ||
// ram lock | ||
RamLock *sync.Mutex | ||
// RamProvider pool | ||
RamProvider map[string]provider.Stopper | ||
} | ||
|
||
func RegisterRamProvider(clientName string, stopper provider.Stopper, m *Manager) { | ||
if m == nil || m.RamLock == nil { | ||
klog.Errorf("Manager init error") | ||
return | ||
} | ||
m.RamLock.Lock() | ||
defer m.RamLock.Unlock() | ||
providerIns, ok := m.RamProvider[clientName] | ||
if ok { | ||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) | ||
// cancel is earlier than m.RamLock.Unlock | ||
defer cancel() | ||
providerIns.Stop(timeoutCtx) | ||
} | ||
m.RamProvider[clientName] = stopper | ||
klog.Infof("register provider %v success", clientName) | ||
} | ||
|
||
func StopProvider(clientName string, m *Manager) { | ||
if m == nil || m.RamLock == nil { | ||
klog.Errorf("Manager init error") | ||
return | ||
} | ||
m.RamLock.Lock() | ||
defer m.RamLock.Unlock() | ||
providerIns, ok := m.RamProvider[clientName] | ||
if !ok || providerIns == nil { | ||
return | ||
} | ||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) | ||
// cancel is earlier than m.RamLock.Unlock | ||
defer cancel() | ||
providerIns.Stop(timeoutCtx) | ||
delete(m.RamProvider, clientName) | ||
klog.Infof("stop provider %v success", clientName) | ||
} | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider" | ||
) | ||
|
||
type Manager struct { | ||
Region string | ||
// kms multi-account client pool | ||
KmsClientMap sync.Map | ||
// dkms multi-instance client pool | ||
DedicateKmsClientMap sync.Map | ||
// oos multi-account client pool | ||
OosClientMap sync.Map | ||
// ram lock | ||
RamLock *sync.Mutex | ||
// RamProvider pool | ||
RamProvider map[string]provider.Stopper | ||
} | ||
|
||
func RegisterRamProvider(clientName string, stopper provider.Stopper, m *Manager) { | ||
if m == nil || m.RamLock == nil { | ||
klog.Errorf("Manager init error") //nolint | ||
return | ||
} | ||
m.RamLock.Lock() | ||
defer m.RamLock.Unlock() | ||
providerIns, ok := m.RamProvider[clientName] | ||
if ok { | ||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) | ||
// cancel is earlier than m.RamLock.Unlock | ||
defer cancel() | ||
providerIns.Stop(timeoutCtx) | ||
} | ||
m.RamProvider[clientName] = stopper | ||
klog.Infof("register provider %v success", clientName) //nolint | ||
} | ||
|
||
func StopProvider(clientName string, m *Manager) { | ||
if m == nil || m.RamLock == nil { | ||
klog.Errorf("Manager init error") | ||
return | ||
} | ||
m.RamLock.Lock() | ||
defer m.RamLock.Unlock() | ||
providerIns, ok := m.RamProvider[clientName] | ||
if !ok || providerIns == nil { | ||
return | ||
} | ||
timeoutCtx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) | ||
// cancel is earlier than m.RamLock.Unlock | ||
defer cancel() | ||
providerIns.Stop(timeoutCtx) | ||
delete(m.RamProvider, clientName) | ||
klog.Infof("stop provider %v success", clientName) | ||
} |