Skip to content

Commit

Permalink
Pass args to plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Jul 23, 2024
1 parent 824bebb commit 9fecb62
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
require (
cloud.google.com/go/storage v1.40.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.6.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqb
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH5sE0o6eCJuNDTmH09nDpbc=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 h1:jBQA3cKT4L2rWMpgE7Yt3Hwh2aUj8KXjIGLxjHeYNNo=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.6.0 h1:ui3YNbxfW7J3tTFIZMH6LIGRjCngp+J+nIFlnizfNTE=
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func NewCommand(f client.Factory) *cobra.Command {
}
pluginServer.Serve()
},
FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: true,
},
}
pluginServer.BindFlags(c.Flags())
return c
Expand Down
7 changes: 1 addition & 6 deletions pkg/plugin/clientmgmt/process/client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
hcplugin "github.com/hashicorp/go-plugin"
"github.com/sirupsen/logrus"

"github.com/vmware-tanzu/velero/pkg/features"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
biav2 "github.com/vmware-tanzu/velero/pkg/plugin/framework/backupitemaction/v2"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
Expand All @@ -52,11 +51,7 @@ func newClientBuilder(command string, logger logrus.FieldLogger, logLevel logrus
// For plugins compiled into the velero executable, we need to run "velero run-plugins"
b.commandArgs = []string{"run-plugins"}
}

b.commandArgs = append(b.commandArgs, "--log-level", logLevel.String())
if len(features.All()) > 0 {
b.commandArgs = append(b.commandArgs, "--features", features.Serialize())
}
b.commandArgs = append(b.commandArgs, os.Args[2:]...)

return b
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/plugin/framework/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"

"github.com/vmware-tanzu/velero/pkg/cmd/server/config"

Check failure on line 28 in pkg/plugin/framework/server.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/vmware-tanzu/velero/pkg/cmd/server/config; to add it:
biav2 "github.com/vmware-tanzu/velero/pkg/plugin/framework/backupitemaction/v2"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
riav2 "github.com/vmware-tanzu/velero/pkg/plugin/framework/restoreitemaction/v2"
Expand All @@ -39,7 +40,7 @@ type Server interface {
// flags.
//
// This method must be called prior to calling .Serve().
BindFlags(flags *pflag.FlagSet) Server
BindFlags(flags *pflag.FlagSet, config ...*config.Config) Server

// RegisterBackupItemAction registers a backup item action. Accepted format
// for the plugin name is <DNS subdomain>/<non-empty name>.
Expand Down Expand Up @@ -125,10 +126,15 @@ func NewServer() Server {
}
}

func (s *server) BindFlags(flags *pflag.FlagSet) Server {
flags.Var(s.logLevelFlag, "log-level", fmt.Sprintf("The level at which to log. Valid values are %s.", strings.Join(s.logLevelFlag.AllowedValues(), ", ")))
func (s *server) BindFlags(flags *pflag.FlagSet, config ...*config.Config) Server {
flags.ParseErrorsWhitelist.UnknownFlags = true
s.flagSet = flags
s.flagSet.ParseErrorsWhitelist.UnknownFlags = true // Velero.io word list : ignore
if len(config) > 0 && config[0] != nil {
config[0].BindFlags(flags)
} else {
// keep backward compatibility
flags.Var(s.logLevelFlag, "log-level", fmt.Sprintf("The level at which to log. Valid values are %s.", strings.Join(s.logLevelFlag.AllowedValues(), ", ")))
}

return s
}
Expand Down

0 comments on commit 9fecb62

Please sign in to comment.