Skip to content

Commit

Permalink
Fix: source plugin not loaded (#811)
Browse files Browse the repository at this point in the history
* fix: source plugin not loaded

Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma committed Nov 22, 2021
1 parent 0f854ca commit ccde8e8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BUILD_IMAGE=golang:1.16.6-alpine
VERSION=$(git rev-parse --short HEAD)
BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')

CGO_ENABLED=${CGO_ENABLED:-0}
GOPROXY=${GOPROXY:-}
GOTAGS=${GOTAGS:-}
GOGCFLAGS=${GOGCFLAGS:-}
Expand Down Expand Up @@ -75,7 +76,7 @@ build-docker() {
-v "$(pwd)"/.cache:/.cache \
-e GOOS="${GOOS}" \
-e GOARCH="${GOARCH}" \
-e CGO_ENABLED=0 \
-e CGO_ENABLED="${CGO_ENABLED}" \
-e GO111MODULE=on \
-e GOPROXY="${GOPROXY}" \
-e GOTAGS="${GOTAGS}" \
Expand Down
2 changes: 2 additions & 0 deletions hack/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ D7Y_REGISTRY=${D7Y_REGISTRY:-d7yio}
IMAGES_DIR="build/images"
BASE_IMAGE=${BASE_IMAGE:-alpine:3.12}

CGO_ENABLED=${CGO_ENABLED:-0}
GOPROXY=${GOPROXY:-`go env GOPROXY`}
GOTAGS=${GOTAGS:-}
GOGCFLAGS=${GOGCFLAGS:-}
Expand All @@ -26,6 +27,7 @@ fi
docker-build() {
name=$1
docker build \
--build-arg CGO_ENABLED="${CGO_ENABLED}" \
--build-arg GOPROXY="${GOPROXY}" \
--build-arg GOTAGS="${GOTAGS}" \
--build-arg GOGCFLAGS="${GOGCFLAGS}" \
Expand Down
3 changes: 2 additions & 1 deletion hack/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export GO_SOURCE_EXCLUDES=( \

GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)
CGO_ENABLED=${CGO_ENABLED:-0}
export GOOS
export GOARCH
export CGO_ENABLED=0
export CGO_ENABLED
2 changes: 1 addition & 1 deletion internal/dfplugin/dfplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// PluginInitFuncName indicates the function `DragonflyPluginInit` must be implemented in plugin
PluginInitFuncName = "DragonflyPluginInit"

// PluginMetaKeyType indicates the type of a plugin, currently support: resource
// PluginMetaKeyType indicates the type of plugin, currently support: resource
PluginMetaKeyType = "type"

// PluginMetaKeyName indicates the name of a plugin
Expand Down
16 changes: 13 additions & 3 deletions pkg/source/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package source
import (
"errors"

logger "d7y.io/dragonfly/v2/internal/dflog"
"d7y.io/dragonfly/v2/internal/dfplugin"
)

Expand All @@ -28,15 +29,24 @@ const (

func LoadPlugin(schema string) (ResourceClient, error) {
// TODO init option
logger.Debugf("try to load source plugin: %s", schema)
client, meta, err := dfplugin.Load(dfplugin.PluginTypeResource, schema, map[string]string{})
if err != nil {
logger.Errorf("load source plugin error: %s", err)
return nil, err
}

if meta[pluginMetadataSchema] != schema {
logger.Errorf("load source plugin error: support schema not match")
return nil, errors.New("support schema not match")
}
if rc, ok := client.(ResourceClient); ok {
return rc, err

rc, ok := client.(ResourceClient)
if !ok {
logger.Errorf("invalid client, not a ResourceClient")
return nil, errors.New("invalid client, not a ResourceClient")
}
return nil, errors.New("invalid client, not a ResourceClient")

logger.Debugf("loaded source plugin %s", schema)
return rc, nil
}
4 changes: 4 additions & 0 deletions pkg/source/source_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func (m *clientManager) getSourceClient(rawURL string) (ResourceClient, error) {
client, ok := m.clients[strings.ToLower(parsedURL.Scheme)]
m.RUnlock()
if !ok || client == nil {
client, err = m.loadSourcePlugin(strings.ToLower(parsedURL.Scheme))
if err == nil && client != nil {
return client, nil
}
return nil, errors.Errorf("can not find client for supporting url %s, clients:%v", rawURL, m.clients)
}
return client, nil
Expand Down

0 comments on commit ccde8e8

Please sign in to comment.