Merge pull request #1291 from carlisia/c-plugins-III

Split velero plugin client into its own package
This commit is contained in:
Steve Kriss
2019-03-19 17:42:22 -06:00
committed by GitHub
32 changed files with 75 additions and 65 deletions

View File

@@ -61,7 +61,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/podexec"
"github.com/heptio/velero/pkg/restic"
"github.com/heptio/velero/pkg/restore"
@@ -203,8 +203,8 @@ type server struct {
cancelFunc context.CancelFunc
logger logrus.FieldLogger
logLevel logrus.Level
pluginRegistry plugin.Registry
pluginManager plugin.Manager
pluginRegistry clientmgmt.Registry
pluginManager clientmgmt.Manager
resticManager restic.RepositoryManager
metrics *metrics.ServerMetrics
config serverConfig
@@ -235,11 +235,11 @@ func newServer(namespace, baseName string, config serverConfig, logger *logrus.L
return nil, errors.WithStack(err)
}
pluginRegistry := plugin.NewRegistry(config.pluginDir, logger, logger.Level)
pluginRegistry := clientmgmt.NewRegistry(config.pluginDir, logger, logger.Level)
if err := pluginRegistry.DiscoverPlugins(); err != nil {
return nil, err
}
pluginManager := plugin.NewManager(logger, logger.Level, pluginRegistry)
pluginManager := clientmgmt.NewManager(logger, logger.Level, pluginRegistry)
if err != nil {
return nil, err
}
@@ -520,8 +520,8 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
// Initialize manual backup metrics
s.metrics.InitSchedule("")
newPluginManager := func(logger logrus.FieldLogger) plugin.Manager {
return plugin.NewManager(logger, s.logLevel, s.pluginRegistry)
newPluginManager := func(logger logrus.FieldLogger) clientmgmt.Manager {
return clientmgmt.NewManager(logger, s.logLevel, s.pluginRegistry)
}
backupSyncController := controller.NewBackupSyncController(

View File

@@ -44,7 +44,7 @@ import (
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/util/collections"
"github.com/heptio/velero/pkg/util/encode"
kubeutil "github.com/heptio/velero/pkg/util/kube"
@@ -60,7 +60,7 @@ type backupController struct {
client velerov1client.BackupsGetter
clock clock.Clock
backupLogLevel logrus.Level
newPluginManager func(logrus.FieldLogger) plugin.Manager
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
backupTracker BackupTracker
backupLocationLister listers.BackupStorageLocationLister
defaultBackupLocation string
@@ -76,7 +76,7 @@ func NewBackupController(
backupper pkgbackup.Backupper,
logger logrus.FieldLogger,
backupLogLevel logrus.Level,
newPluginManager func(logrus.FieldLogger) plugin.Manager,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
backupTracker BackupTracker,
backupLocationInformer informers.BackupStorageLocationInformer,
defaultBackupLocation string,

View File

@@ -40,7 +40,7 @@ import (
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/plugin/velero"
"github.com/heptio/velero/pkg/util/logging"
@@ -305,7 +305,7 @@ func TestProcessBackupCompletions(t *testing.T) {
backupTracker: NewBackupTracker(),
metrics: metrics.NewServerMetrics(),
clock: clock.NewFakeClock(now),
newPluginManager: func(logrus.FieldLogger) plugin.Manager { return pluginManager },
newPluginManager: func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
newBackupStore: func(*v1.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error) {
return backupStore, nil
},

View File

@@ -38,7 +38,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/plugin/velero"
"github.com/heptio/velero/pkg/restic"
"github.com/heptio/velero/pkg/util/kube"
@@ -61,7 +61,7 @@ type backupDeletionController struct {
snapshotLocationLister listers.VolumeSnapshotLocationLister
processRequestFunc func(*v1.DeleteBackupRequest) error
clock clock.Clock
newPluginManager func(logrus.FieldLogger) plugin.Manager
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
newBackupStore func(*v1.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
@@ -78,7 +78,7 @@ func NewBackupDeletionController(
podvolumeBackupInformer informers.PodVolumeBackupInformer,
backupLocationInformer informers.BackupStorageLocationInformer,
snapshotLocationInformer informers.VolumeSnapshotLocationInformer,
newPluginManager func(logrus.FieldLogger) plugin.Manager,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
) Interface {
c := &backupDeletionController{
genericController: newGenericController("backup-deletion", logger),
@@ -364,7 +364,7 @@ func (c *backupDeletionController) processRequest(req *v1.DeleteBackupRequest) e
func blockStoreForSnapshotLocation(
namespace, snapshotLocationName string,
snapshotLocationLister listers.VolumeSnapshotLocationLister,
pluginManager plugin.Manager,
pluginManager clientmgmt.Manager,
) (velero.BlockStore, error) {
snapshotLocation, err := snapshotLocationLister.VolumeSnapshotLocations(namespace).Get(snapshotLocationName)
if err != nil {
@@ -383,7 +383,7 @@ func blockStoreForSnapshotLocation(
return blockStore, nil
}
func (c *backupDeletionController) backupStoreForBackup(backup *v1.Backup, pluginManager plugin.Manager, log logrus.FieldLogger) (persistence.BackupStore, error) {
func (c *backupDeletionController) backupStoreForBackup(backup *v1.Backup, pluginManager clientmgmt.Manager, log logrus.FieldLogger) (persistence.BackupStore, error) {
backupLocation, err := c.backupLocationLister.BackupStorageLocations(backup.Namespace).Get(backup.Spec.StorageLocation)
if err != nil {
return nil, errors.WithStack(err)

View File

@@ -38,7 +38,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
velerotest "github.com/heptio/velero/pkg/util/test"
"github.com/heptio/velero/pkg/volume"
@@ -146,7 +146,7 @@ func setupBackupDeletionControllerTest(objects ...runtime.Object) *backupDeletio
sharedInformers.Velero().V1().PodVolumeBackups(),
sharedInformers.Velero().V1().BackupStorageLocations(),
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
).(*backupDeletionController),
req: req,
@@ -389,7 +389,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
pluginManager := &pluginmocks.Manager{}
pluginManager.On("GetBlockStore", "provider-1").Return(td.blockStore, nil)
pluginManager.On("CleanupClients")
td.controller.newPluginManager = func(logrus.FieldLogger) plugin.Manager { return pluginManager }
td.controller.newPluginManager = func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager }
td.backupStore.On("DeleteBackup", td.req.Spec.BackupName).Return(nil)
td.backupStore.On("DeleteRestore", "restore-1").Return(nil)
@@ -528,7 +528,7 @@ func TestBackupDeletionControllerProcessRequest(t *testing.T) {
pluginManager := &pluginmocks.Manager{}
pluginManager.On("GetBlockStore", "provider-1").Return(td.blockStore, nil)
pluginManager.On("CleanupClients")
td.controller.newPluginManager = func(logrus.FieldLogger) plugin.Manager { return pluginManager }
td.controller.newPluginManager = func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager }
td.backupStore.On("GetBackupVolumeSnapshots", td.req.Spec.BackupName).Return(snapshots, nil)
td.backupStore.On("DeleteBackup", td.req.Spec.BackupName).Return(nil)

View File

@@ -34,7 +34,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/util/stringslice"
)
@@ -47,7 +47,7 @@ type backupSyncController struct {
backupStorageLocationLister listers.BackupStorageLocationLister
namespace string
defaultBackupLocation string
newPluginManager func(logrus.FieldLogger) plugin.Manager
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
newBackupStore func(*velerov1api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
@@ -59,7 +59,7 @@ func NewBackupSyncController(
syncPeriod time.Duration,
namespace string,
defaultBackupLocation string,
newPluginManager func(logrus.FieldLogger) plugin.Manager,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
logger logrus.FieldLogger,
) Interface {
if syncPeriod < time.Minute {

View File

@@ -35,7 +35,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/util/stringslice"
velerotest "github.com/heptio/velero/pkg/util/test"
@@ -193,7 +193,7 @@ func TestBackupSyncControllerRun(t *testing.T) {
time.Duration(0),
test.namespace,
"",
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
velerotest.NewLogger(),
).(*backupSyncController)

View File

@@ -35,7 +35,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/util/kube"
)
@@ -48,7 +48,7 @@ type downloadRequestController struct {
clock clock.Clock
backupLocationLister listers.BackupStorageLocationLister
backupLister listers.BackupLister
newPluginManager func(logrus.FieldLogger) plugin.Manager
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
newBackupStore func(*v1.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
@@ -59,7 +59,7 @@ func NewDownloadRequestController(
restoreInformer informers.RestoreInformer,
backupLocationInformer informers.BackupStorageLocationInformer,
backupInformer informers.BackupInformer,
newPluginManager func(logrus.FieldLogger) plugin.Manager,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
logger logrus.FieldLogger,
) Interface {
c := &downloadRequestController{

View File

@@ -32,7 +32,7 @@ import (
informers "github.com/heptio/velero/pkg/generated/informers/externalversions"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
kubeutil "github.com/heptio/velero/pkg/util/kube"
velerotest "github.com/heptio/velero/pkg/util/test"
@@ -59,7 +59,7 @@ func newDownloadRequestTestHarness(t *testing.T) *downloadRequestTestHarness {
informerFactory.Velero().V1().Restores(),
informerFactory.Velero().V1().BackupStorageLocations(),
informerFactory.Velero().V1().Backups(),
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
velerotest.NewLogger(),
).(*downloadRequestController)
)

View File

@@ -40,7 +40,7 @@ import (
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
"github.com/heptio/velero/pkg/plugin/velero"
"github.com/heptio/velero/pkg/restore"
"github.com/heptio/velero/pkg/util/collections"
@@ -87,7 +87,7 @@ type restoreController struct {
defaultBackupLocation string
metrics *metrics.ServerMetrics
newPluginManager func(logger logrus.FieldLogger) plugin.Manager
newPluginManager func(logger logrus.FieldLogger) clientmgmt.Manager
newBackupStore func(*api.BackupStorageLocation, persistence.ObjectStoreGetter, logrus.FieldLogger) (persistence.BackupStore, error)
}
@@ -106,7 +106,7 @@ func NewRestoreController(
snapshotLocationInformer informers.VolumeSnapshotLocationInformer,
logger logrus.FieldLogger,
restoreLogLevel logrus.Level,
newPluginManager func(logrus.FieldLogger) plugin.Manager,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
defaultBackupLocation string,
metrics *metrics.ServerMetrics,
) Interface {
@@ -285,7 +285,7 @@ type backupInfo struct {
backupStore persistence.BackupStore
}
func (c *restoreController) validateAndComplete(restore *api.Restore, pluginManager plugin.Manager) backupInfo {
func (c *restoreController) validateAndComplete(restore *api.Restore, pluginManager clientmgmt.Manager) backupInfo {
// add non-restorable resources to restore's excluded resources
excludedResources := sets.NewString(restore.Spec.ExcludedResources...)
for _, nonrestorable := range nonRestorableResources {
@@ -409,7 +409,7 @@ func mostRecentCompletedBackup(backups []*api.Backup) *api.Backup {
// fetchBackupInfo checks the backup lister for a backup that matches the given name. If it doesn't
// find it, it returns an error.
func (c *restoreController) fetchBackupInfo(backupName string, pluginManager plugin.Manager) (backupInfo, error) {
func (c *restoreController) fetchBackupInfo(backupName string, pluginManager clientmgmt.Manager) (backupInfo, error) {
backup, err := c.backupLister.Backups(c.namespace).Get(backupName)
if err != nil {
return backupInfo{}, err
@@ -435,7 +435,7 @@ func (c *restoreController) runRestore(
restore *api.Restore,
actions []velero.RestoreItemAction,
info backupInfo,
pluginManager plugin.Manager,
pluginManager clientmgmt.Manager,
) (restoreResult, error) {
var restoreWarnings, restoreErrors api.RestoreResult
var restoreFailure error

View File

@@ -43,7 +43,7 @@ import (
"github.com/heptio/velero/pkg/metrics"
"github.com/heptio/velero/pkg/persistence"
persistencemocks "github.com/heptio/velero/pkg/persistence/mocks"
"github.com/heptio/velero/pkg/plugin"
"github.com/heptio/velero/pkg/plugin/clientmgmt"
pluginmocks "github.com/heptio/velero/pkg/plugin/mocks"
"github.com/heptio/velero/pkg/plugin/velero"
"github.com/heptio/velero/pkg/restore"
@@ -110,7 +110,7 @@ func TestFetchBackupInfo(t *testing.T) {
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
"default",
metrics.NewServerMetrics(),
).(*restoreController)
@@ -408,7 +408,7 @@ func TestProcessRestore(t *testing.T) {
sharedInformers.Velero().V1().VolumeSnapshotLocations(),
logger,
logrus.InfoLevel,
func(logrus.FieldLogger) plugin.Manager { return pluginManager },
func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
"default",
metrics.NewServerMetrics(),
).(*restoreController)

View File

@@ -13,7 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
// Package clientmgmt contains the plugin client for Velero.
package clientmgmt
import (
"os"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"os"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"fmt"

View File

@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"testing"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"sync"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"fmt"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
plugin "github.com/hashicorp/go-plugin"

View File

@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"testing"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"fmt"

View File

@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"os"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"github.com/pkg/errors"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"testing"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"github.com/pkg/errors"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"testing"

View File

@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"reflect"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"io"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"io/ioutil"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"sync"

View File

@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"github.com/pkg/errors"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package plugin
package clientmgmt
import (
"testing"

View File

@@ -18,7 +18,7 @@ package mocks
import logrus "github.com/sirupsen/logrus"
import mock "github.com/stretchr/testify/mock"
import plugin "github.com/heptio/velero/pkg/plugin"
import "github.com/heptio/velero/pkg/plugin/clientmgmt"
// ProcessFactory is an autogenerated mock type for the ProcessFactory type
type ProcessFactory struct {
@@ -26,15 +26,15 @@ type ProcessFactory struct {
}
// newProcess provides a mock function with given fields: command, logger, logLevel
func (_m *ProcessFactory) newProcess(command string, logger logrus.FieldLogger, logLevel logrus.Level) (plugin.Process, error) {
func (_m *ProcessFactory) newProcess(command string, logger logrus.FieldLogger, logLevel logrus.Level) (clientmgmt.Process, error) {
ret := _m.Called(command, logger, logLevel)
var r0 plugin.Process
if rf, ok := ret.Get(0).(func(string, logrus.FieldLogger, logrus.Level) plugin.Process); ok {
var r0 clientmgmt.Process
if rf, ok := ret.Get(0).(func(string, logrus.FieldLogger, logrus.Level) clientmgmt.Process); ok {
r0 = rf(command, logger, logLevel)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(plugin.Process)
r0 = ret.Get(0).(clientmgmt.Process)
}
}