Skip to content

Commit

Permalink
Load source plugins (#894)
Browse files Browse the repository at this point in the history
* unit test

Signed-off-by: sunwp <[email protected]>
  • Loading branch information
244372610 authored and gaius-qi committed Jun 28, 2023
1 parent ca2f196 commit eaca95d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/source/source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,36 @@ func WithPluginDir(dir string) Option {
}

func (m *clientManager) Register(scheme string, resourceClient ResourceClient, adaptor requestAdapter, hooks ...Hook) error {
scheme = strings.ToLower(scheme)
m.mu.Lock()
defer m.mu.Unlock()
if client, ok := m.clients[strings.ToLower(scheme)]; ok {
if client, ok := m.clients[scheme]; ok {
if client.(*clientWrapper).rc != resourceClient {
return errors.Errorf("client with scheme %s already exist, current client: %#v", scheme, client)
}
logger.Warnf("client with scheme %s already exist, no need register again", scheme)
return nil
}
m.clients[strings.ToLower(scheme)] = &clientWrapper{
m.doRegister(scheme, &clientWrapper{
adapter: adaptor,
hooks: hooks,
rc: resourceClient,
}
})
return nil
}

func (m *clientManager) doRegister(scheme string, resourceClient ResourceClient) {
m.clients[strings.ToLower(scheme)] = resourceClient
}

func (m *clientManager) UnRegister(scheme string) {
m.mu.Lock()
defer m.mu.Unlock()
if client, ok := m.clients[strings.ToLower(scheme)]; ok {
scheme = strings.ToLower(scheme)
if client, ok := m.clients[scheme]; ok {
logger.Infof("remove client %#v for scheme %s", client, scheme)
}
delete(m.clients, strings.ToLower(scheme))
delete(m.clients, scheme)
}

func (m *clientManager) GetClient(scheme string, options ...Option) (ResourceClient, bool) {
Expand Down Expand Up @@ -198,7 +206,7 @@ func (m *clientManager) GetClient(scheme string, options ...Option) (ResourceCli
m.mu.Unlock()
return nil, false
}
m.clients[scheme] = client
m.doRegister(scheme, client)
m.mu.Unlock()
return client, true
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var _ = BeforeSuite(func() {
rawDfgetVersion, err := pod.Command("dfget", "version").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
dfgetGitCommit := strings.Fields(string(rawDfgetVersion))[7]
fmt.Printf("raw dfget version: %s\n", rawDfgetVersion)
fmt.Printf("dfget merge commit: %s\n", dfgetGitCommit)

if mode == dfdaemonCompatibilityTestMode {
Expand Down

0 comments on commit eaca95d

Please sign in to comment.