Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow skipping PVC binding check and update default dockerimage #107

Merged
merged 3 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "korb-mover:latest"
fe-ax marked this conversation as resolved.
Show resolved Hide resolved
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