Skip to content

Commit

Permalink
Pass Velero server command args to the plugins
Browse files Browse the repository at this point in the history
Pass Velero server command args to the plugins

Fixes vmware-tanzu#7806

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Aug 30, 2024
1 parent 981f30c commit b75dcfb
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 489 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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ cloud.google.com/go/storage v1.40.0/go.mod h1:Rrj7/hKlG87BLqDJYtwR0fbPld8uJPbQ2u
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM=
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: 2 additions & 1 deletion pkg/cmd/cli/nodeagent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/buildinfo"
"github.com/vmware-tanzu/velero/pkg/client"
"github.com/vmware-tanzu/velero/pkg/cmd"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
"github.com/vmware-tanzu/velero/pkg/cmd/util/signals"
"github.com/vmware-tanzu/velero/pkg/controller"
"github.com/vmware-tanzu/velero/pkg/datapath"
Expand Down Expand Up @@ -285,7 +286,7 @@ func (s *nodeAgentServer) run() {
credentialGetter, s.nodeName, s.mgr.GetScheme(), s.metrics, s.logger)

if err := pvbReconciler.SetupWithManager(s.mgr); err != nil {
s.logger.Fatal(err, "unable to create controller", "controller", controller.PodVolumeBackup)
s.logger.Fatal(err, "unable to create controller", "controller", config.ControllerPodVolumeBackup)
}

if err = controller.NewPodVolumeRestoreReconciler(s.mgr.GetClient(), s.dataPathMgr, repoEnsurer, credentialGetter, s.logger).SetupWithManager(s.mgr); err != nil {
Expand Down
263 changes: 263 additions & 0 deletions pkg/cmd/server/config/config.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package restore
package config

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package restore
package config

import (
"testing"
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func NewCommand(f client.Factory) *cobra.Command {
Hidden: true,
Short: "INTERNAL COMMAND ONLY - not intended to be run directly by users",
Run: func(c *cobra.Command, args []string) {
config := pluginServer.GetConfig()
f.SetClientQPS(config.ClientQPS)
f.SetClientBurst(config.ClientBurst)
pluginServer = pluginServer.
RegisterBackupItemAction(
"velero.io/pv",
Expand Down Expand Up @@ -197,6 +200,9 @@ func NewCommand(f client.Factory) *cobra.Command {
}
pluginServer.Serve()
},
FParseErrWhitelist: cobra.FParseErrWhitelist{
UnknownFlags: true,
},
}
pluginServer.BindFlags(c.Flags())
return c
Expand Down
415 changes: 108 additions & 307 deletions pkg/cmd/server/server.go

Large diffs are not rendered by default.

92 changes: 46 additions & 46 deletions pkg/cmd/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
velerov2alpha1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v2alpha1"
"github.com/vmware-tanzu/velero/pkg/client/mocks"
"github.com/vmware-tanzu/velero/pkg/controller"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
discovery_mocks "github.com/vmware-tanzu/velero/pkg/discovery/mocks"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
"github.com/vmware-tanzu/velero/pkg/uploader"
Expand Down Expand Up @@ -112,31 +112,31 @@ func TestRemoveControllers(t *testing.T) {
{
name: "Remove one disable controller",
disabledControllers: []string{
controller.Backup,
config.ControllerBackup,
},
errorExpected: false,
},
{
name: "Remove all disable controllers",
disabledControllers: []string{
controller.BackupOperations,
controller.Backup,
controller.BackupDeletion,
controller.BackupSync,
controller.DownloadRequest,
controller.GarbageCollection,
controller.BackupRepo,
controller.Restore,
controller.Schedule,
controller.ServerStatusRequest,
config.ControllerBackupOperations,
config.ControllerBackup,
config.ControllerBackupDeletion,
config.ControllerBackupSync,
config.ControllerDownloadRequest,
config.ControllerGarbageCollection,
config.ControllerBackupRepo,
config.ControllerRestore,
config.ControllerSchedule,
config.ControllerServerStatusRequest,
},
errorExpected: false,
},
{
name: "Remove with a non-disable controller included",
disabledControllers: []string{
controller.Backup,
controller.BackupStorageLocation,
config.ControllerBackup,
config.ControllerBackupStorageLocation,
},
errorExpected: true,
},
Expand All @@ -151,16 +151,16 @@ func TestRemoveControllers(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
enabledRuntimeControllers := map[string]struct{}{
controller.BackupSync: {},
controller.Backup: {},
controller.GarbageCollection: {},
controller.Restore: {},
controller.ServerStatusRequest: {},
controller.Schedule: {},
controller.BackupDeletion: {},
controller.BackupRepo: {},
controller.DownloadRequest: {},
controller.BackupOperations: {},
config.ControllerBackupSync: {},
config.ControllerBackup: {},
config.ControllerGarbageCollection: {},
config.ControllerRestore: {},
config.ControllerServerStatusRequest: {},
config.ControllerSchedule: {},
config.ControllerBackupDeletion: {},
config.ControllerBackupRepo: {},
config.ControllerDownloadRequest: {},
config.ControllerBackupOperations: {},
}

totalNumOriginalControllers := len(enabledRuntimeControllers)
Expand Down Expand Up @@ -191,42 +191,42 @@ func Test_newServer(t *testing.T) {
logger := logrus.New()

// invalid uploader type
_, err := newServer(factory, serverConfig{
uploaderType: "invalid",
_, err := newServer(factory, &config.Config{
UploaderType: "invalid",
}, logger)
assert.Error(t, err)

// invalid clientQPS
_, err = newServer(factory, serverConfig{
uploaderType: uploader.KopiaType,
clientQPS: -1,
_, err = newServer(factory, &config.Config{
UploaderType: uploader.KopiaType,
ClientQPS: -1,
}, logger)
assert.Error(t, err)

// invalid clientQPS Restic uploader
_, err = newServer(factory, serverConfig{
uploaderType: uploader.ResticType,
clientQPS: -1,
_, err = newServer(factory, &config.Config{
UploaderType: uploader.ResticType,
ClientQPS: -1,
}, logger)
assert.Error(t, err)

// invalid clientBurst
factory.On("SetClientQPS", mock.Anything).Return()
_, err = newServer(factory, serverConfig{
uploaderType: uploader.KopiaType,
clientQPS: 1,
clientBurst: -1,
_, err = newServer(factory, &config.Config{
UploaderType: uploader.KopiaType,
ClientQPS: 1,
ClientBurst: -1,
}, logger)
assert.Error(t, err)

// invalid clientBclientPageSizeurst
factory.On("SetClientQPS", mock.Anything).Return().
On("SetClientBurst", mock.Anything).Return()
_, err = newServer(factory, serverConfig{
uploaderType: uploader.KopiaType,
clientQPS: 1,
clientBurst: 1,
clientPageSize: -1,
_, err = newServer(factory, &config.Config{
UploaderType: uploader.KopiaType,
ClientQPS: 1,
ClientBurst: 1,
ClientPageSize: -1,
}, logger)
assert.Error(t, err)

Expand All @@ -236,11 +236,11 @@ func Test_newServer(t *testing.T) {
On("KubeClient").Return(nil, nil).
On("Client").Return(nil, nil).
On("DynamicClient").Return(nil, errors.New("error"))
_, err = newServer(factory, serverConfig{
uploaderType: uploader.KopiaType,
clientQPS: 1,
clientBurst: 1,
clientPageSize: 100,
_, err = newServer(factory, &config.Config{
UploaderType: uploader.KopiaType,
ClientQPS: 1,
ClientBurst: 1,
ClientPageSize: 100,
}, logger)
assert.Error(t, err)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/vmware-tanzu/velero/internal/volume"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/features"
"github.com/vmware-tanzu/velero/pkg/label"
Expand Down Expand Up @@ -201,7 +202,7 @@ func getLastSuccessBySchedule(backups []velerov1api.Backup) map[string]time.Time

func (b *backupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := b.logger.WithFields(logrus.Fields{
"controller": Backup,
"controller": config.ControllerBackup,
"backuprequest": req.String(),
})

Expand Down Expand Up @@ -591,16 +592,16 @@ func (b *backupReconciler) validateAndGetSnapshotLocations(backup *velerov1api.B
// field is checked to see if the backup was a partial failure.

func (b *backupReconciler) runBackup(backup *pkgbackup.Request) error {
b.logger.WithField(Backup, kubeutil.NamespaceAndName(backup)).Info("Setting up backup log")
b.logger.WithField(config.ControllerBackup, kubeutil.NamespaceAndName(backup)).Info("Setting up backup log")

// Log the backup to both a backup log file and to stdout. This will help see what happened if the upload of the
// backup log failed for whatever reason.
logCounter := logging.NewLogHook()
backupLog, err := logging.NewTempFileLogger(b.backupLogLevel, b.formatFlag, logCounter, logrus.Fields{Backup: kubeutil.NamespaceAndName(backup)})
backupLog, err := logging.NewTempFileLogger(b.backupLogLevel, b.formatFlag, logCounter, logrus.Fields{config.ControllerBackup: kubeutil.NamespaceAndName(backup)})
if err != nil {
return errors.Wrap(err, "error creating dual mode logger for backup")
}
defer backupLog.Dispose(b.logger.WithField(Backup, kubeutil.NamespaceAndName(backup)))
defer backupLog.Dispose(b.logger.WithField(config.ControllerBackup, kubeutil.NamespaceAndName(backup)))

backupLog.Info("Setting up backup temp file")
backupFile, err := os.CreateTemp("", "")
Expand Down Expand Up @@ -678,7 +679,7 @@ func (b *backupReconciler) runBackup(backup *pkgbackup.Request) error {
"errors": backupErrors,
}

backupLog.DoneForPersist(b.logger.WithField(Backup, kubeutil.NamespaceAndName(backup)))
backupLog.DoneForPersist(b.logger.WithField(config.ControllerBackup, kubeutil.NamespaceAndName(backup)))

// Assign finalize phase as close to end as possible so that any errors
// logged to backupLog are captured. This is done before uploading the
Expand Down Expand Up @@ -725,7 +726,7 @@ func (b *backupReconciler) runBackup(backup *pkgbackup.Request) error {
}
}

b.logger.WithField(Backup, kubeutil.NamespaceAndName(backup)).Infof("Initial backup processing complete, moving to %s", backup.Status.Phase)
b.logger.WithField(config.ControllerBackup, kubeutil.NamespaceAndName(backup)).Infof("Initial backup processing complete, moving to %s", backup.Status.Phase)

// if we return a non-nil error, the calling function will update
// the backup's phase to Failed.
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/vmware-tanzu/velero/internal/volume"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
velerov2alpha1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v2alpha1"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/label"
"github.com/vmware-tanzu/velero/pkg/metrics"
Expand Down Expand Up @@ -114,7 +115,7 @@ func (r *backupDeletionReconciler) SetupWithManager(mgr ctrl.Manager) error {

func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.logger.WithFields(logrus.Fields{
"controller": BackupDeletion,
"controller": config.ControllerBackupDeletion,
"deletebackuprequest": req.String(),
})
log.Debug("Getting deletebackuprequest")
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/backup_storage_location_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/vmware-tanzu/velero/internal/storage"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
"github.com/vmware-tanzu/velero/pkg/persistence"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
"github.com/vmware-tanzu/velero/pkg/util/kube"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (r *backupStorageLocationReconciler) Reconcile(ctx context.Context, req ctr
var unavailableErrors []string
var location velerov1api.BackupStorageLocation

log := r.log.WithField("controller", BackupStorageLocation).WithField(BackupStorageLocation, req.NamespacedName.String())
log := r.log.WithField("controller", config.ControllerBackupStorageLocation).WithField(config.ControllerBackupStorageLocation, req.NamespacedName.String())
log.Debug("Validating availability of BackupStorageLocation")

locationList, err := storage.ListBackupStorageLocations(r.ctx, r.client, req.Namespace)
Expand Down Expand Up @@ -155,7 +156,7 @@ func (r *backupStorageLocationReconciler) logReconciledPhase(defaultFound bool,
var availableBSLs []*velerov1api.BackupStorageLocation
var unAvailableBSLs []*velerov1api.BackupStorageLocation
var unknownBSLs []*velerov1api.BackupStorageLocation
log := r.log.WithField("controller", BackupStorageLocation)
log := r.log.WithField("controller", config.ControllerBackupStorageLocation)

for i, location := range locationList.Items {
phase := location.Status.Phase
Expand Down Expand Up @@ -198,7 +199,7 @@ func (r *backupStorageLocationReconciler) SetupWithManager(mgr ctrl.Manager) err
)
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
location := object.(*velerov1api.BackupStorageLocation)
return storage.IsReadyToValidate(location.Spec.ValidationFrequency, location.Status.LastValidationTime, r.defaultBackupLocationInfo.ServerValidationFrequency, r.log.WithField("controller", BackupStorageLocation))
return storage.IsReadyToValidate(location.Spec.ValidationFrequency, location.Status.LastValidationTime, r.defaultBackupLocationInfo.ServerValidationFrequency, r.log.WithField("controller", config.ControllerBackupStorageLocation))
})
return ctrl.NewControllerManagedBy(mgr).
// As the "status.LastValidationTime" field is always updated, this triggers new reconciling process, skip the update event that include no spec change to avoid the reconcile loop
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/builder"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/cmd/server/config"
"github.com/vmware-tanzu/velero/pkg/features"
"github.com/vmware-tanzu/velero/pkg/label"
"github.com/vmware-tanzu/velero/pkg/persistence"
Expand Down Expand Up @@ -78,7 +79,7 @@ func NewBackupSyncReconciler(

// Reconcile syncs between the backups in cluster and backups metadata in object store.
func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := b.logger.WithField("controller", BackupSync)
log := b.logger.WithField("controller", config.ControllerBackupSync)
log = log.WithField("backupLocation", req.String())
log.Debug("Begin to sync between backups' metadata in BSL object storage and cluster's existing backups.")

Expand Down
Loading

0 comments on commit b75dcfb

Please sign in to comment.