Pass Velero server command args to the plugins

Pass Velero server command args to the plugins

Fixes #7806

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
This commit is contained in:
Wenkai Yin(尹文开)
2024-09-04 13:43:27 +08:00
parent 981f30cb25
commit dc6eeafe98
22 changed files with 500 additions and 483 deletions
@@ -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"
@@ -53,11 +52,8 @@ 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())
}
// exclude "velero" and "server" from "velero server --flags ..."
b.commandArgs = append(b.commandArgs, os.Args[2:]...)
return b
}
@@ -25,7 +25,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"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"
@@ -39,19 +38,11 @@ func TestNewClientBuilder(t *testing.T) {
logLevel := logrus.InfoLevel
cb := newClientBuilder("velero", logger, logLevel)
assert.Equal(t, "velero", cb.commandName)
assert.Equal(t, []string{"--log-level", "info"}, cb.commandArgs)
assert.Equal(t, newLogrusAdapter(logger, logLevel), cb.pluginLogger)
cb = newClientBuilder(os.Args[0], logger, logLevel)
assert.Equal(t, cb.commandName, os.Args[0])
assert.Equal(t, []string{"run-plugins", "--log-level", "info"}, cb.commandArgs)
assert.Equal(t, newLogrusAdapter(logger, logLevel), cb.pluginLogger)
features.NewFeatureFlagSet("feature1", "feature2")
cb = newClientBuilder(os.Args[0], logger, logLevel)
assert.Equal(t, []string{"run-plugins", "--log-level", "info", "--features", "feature1,feature2"}, cb.commandArgs)
// Clear the features list in case other tests run in the same process.
features.NewFeatureFlagSet()
}
func TestClientConfig(t *testing.T) {
+1 -28
View File
@@ -17,8 +17,6 @@ limitations under the License.
package process
import (
"strings"
plugin "github.com/hashicorp/go-plugin"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -61,32 +59,7 @@ func newProcess(command string, logger logrus.FieldLogger, logLevel logrus.Level
// This launches the plugin process.
protocolClient, err := client.Client()
if err != nil {
if !strings.Contains(err.Error(), "unknown flag: --features") {
return nil, err
}
// Velero started passing the --features flag to plugins in v1.2, however existing plugins
// may not support that flag and may not silently ignore unknown flags. The plugin server
// code that we make available to plugin authors has since been updated to ignore unknown
// flags, but to avoid breaking plugins that haven't updated to that code and don't support
// the --features flag, we specifically handle not passing the flag if we can detect that
// it's not supported.
logger.Debug("Plugin process does not support the --features flag, removing it and trying again")
builder.commandArgs = removeFeaturesFlag(builder.commandArgs)
logger.Debugf("Updated command args after removing --features flag: %v", builder.commandArgs)
// re-get the client and protocol client now that --features has been removed
// from the command args.
client = builder.client()
protocolClient, err = client.Client()
if err != nil {
return nil, err
}
logger.Debug("Plugin process successfully started without the --features flag")
return nil, err
}
p := &process{