Skip to content

Commit

Permalink
Allow skipping PVC binding check and update default dockerimage (#107)
Browse files Browse the repository at this point in the history
* Added option to skip pvc binding

* Changed DockerImage default value to use dockerhub

* Update pkg/config/config.go

Co-authored-by: Jens L. <[email protected]>

Co-authored-by: Marco Stuurman <[email protected]>
Co-authored-by: Jens L. <[email protected]>
  • Loading branch information
3 people authored Jun 10, 2022
1 parent 2ccff56 commit bcc3335
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var pvcNewName string
var pvcNewNamespace string

var force bool
var skipWaitPVCBind bool
var Version string

// rootCmd represents the base command when called without any subcommands
Expand All @@ -34,6 +35,7 @@ var rootCmd = &cobra.Command{
for _, pvc := range args {
m := migrator.New(kubeConfig)
m.Force = force
m.WaitForTempDestPVCBind = skipWaitPVCBind

// We can only support operating in a single namespace currently
// Since cross-namespace PVC mounts are not a thing
Expand Down Expand Up @@ -85,6 +87,7 @@ func init() {
rootCmd.Flags().StringVar(&pvcNewNamespace, "new-pvc-namespace", "", "Namespace for the new PVCs to be created in. If empty, the namespace from your kubeconfig file will be used.")

rootCmd.Flags().BoolVar(&force, "force", false, "Ignore warning which would normally halt the tool during validation.")
rootCmd.Flags().BoolVar(&skipWaitPVCBind, "skip-pvc-bind-wait", false, "Skip waiting for PVC to be bound.")

rootCmd.Flags().StringVar(&config.DockerImage, "docker-image", config.DockerImage, "Image to use for moving jobs")
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

var DockerImage = "beryju.org/korb-mover:latest"
var DockerImage = "ghcr.io/beryju/korb-mover:latest"
4 changes: 3 additions & 1 deletion pkg/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Migrator struct {

Force bool

WaitForTempDestPVCBind bool

kConfig *rest.Config
kClient *kubernetes.Clientset

Expand Down Expand Up @@ -73,7 +75,7 @@ func (m *Migrator) Run() {
destTemplate.Name = m.DestPVCName
if len(compatibleStrategies) == 1 {
m.log.Debug("Only one compatible strategy, running")
err := compatibleStrategies[0].Do(sourcePVC, destTemplate)
err := compatibleStrategies[0].Do(sourcePVC, destTemplate, m.WaitForTempDestPVCBind)
if err != nil {
m.log.WithError(err).Warning("Failed to migrate")
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/strategies/copyTwiceName.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type CopyTwiceNameStrategy struct {

MoveTimeout time.Duration

WaitForTempDestPVCBind bool

pvcsToDelete []*v1.PersistentVolumeClaim
}

Expand Down Expand Up @@ -50,7 +52,7 @@ func (c *CopyTwiceNameStrategy) getDeleteOptions() metav1.DeleteOptions {
}
}

func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v1.PersistentVolumeClaim) error {
func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v1.PersistentVolumeClaim, WaitForTempDestPVCBind bool) error {
c.setTimeout(destTemplate)
c.log.Warning("This strategy assumes you've stopped all pods accessing this data.")
suffix := time.Now().Unix()
Expand All @@ -63,10 +65,15 @@ func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemp
if err != nil {
return err
}
err = c.waitForBound(tempDest)
if err != nil {
c.log.WithError(err).Warning("Waiting for PVC to be bound failed")
return c.Cleanup()

if c.WaitForTempDestPVCBind {
err = c.waitForBound(tempDest)
if err != nil {
c.log.WithError(err).Warning("Waiting for PVC to be bound failed")
return c.Cleanup()
}
} else{
c.log.WithField("stage", 2).Debug("skipping waiting for PVC to be bound")
}

c.log.WithField("stage", 2).Debug("starting mover job")
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategies/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewBaseStrategy(config *rest.Config, client *kubernetes.Clientset) BaseStra
type Strategy interface {
CompatibleWithControllers(...interface{}) bool
Description() string
Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v1.PersistentVolumeClaim) error
Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v1.PersistentVolumeClaim, WaitForTempDestPVCBind bool) error
}

func StrategyInstances(b BaseStrategy) []Strategy {
Expand Down

0 comments on commit bcc3335

Please sign in to comment.