Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load source plugins #894

Merged
merged 10 commits into from
Dec 9, 2021
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