Skip to content

Commit

Permalink
Adds the flag to optionally enable all nodes toleration
Browse files Browse the repository at this point in the history
Adding flag to optionally enabel the wildcard node tolerations. Some cluster configurations
may not admit the the pod spec with wildcard node toleration, hence such scenarios
could prevent korb tool usage.
  • Loading branch information
Hrishi Shinde authored and BeryJu committed Nov 5, 2023
1 parent b3fe8ef commit 9e40c71
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 27 deletions.
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var pvcNewAccessModes []string

var force bool
var skipWaitPVCBind bool
var tolerateAllNodes bool
var Version string

// rootCmd represents the base command when called without any subcommands
Expand All @@ -35,7 +36,7 @@ var rootCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
for _, pvc := range args {
m := migrator.New(kubeConfig, strategy)
m := migrator.New(kubeConfig, strategy, tolerateAllNodes)
m.Force = force
m.WaitForTempDestPVCBind = skipWaitPVCBind

Expand Down Expand Up @@ -92,6 +93,7 @@ func init() {

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().BoolVar(&tolerateAllNodes, "tolerate-any-node", false, "Allow job to tolerating any node node taints.")

rootCmd.Flags().StringVar(&config.ContainerImage, "container-image", config.ContainerImage, "Image to use for moving jobs")
rootCmd.Flags().StringVar(&strategy, "strategy", "", "Strategy to use, by default will try to auto-select")
Expand Down
11 changes: 6 additions & 5 deletions pkg/migrator/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Migrator struct {
DestPVCName string
DestPVCAccessModes []string

Force bool

Force bool
WaitForTempDestPVCBind bool
TolerateAllNodes bool

kConfig *rest.Config
kClient *kubernetes.Clientset
Expand All @@ -30,10 +30,11 @@ type Migrator struct {
strategy string
}

func New(kubeconfigPath string, strategy string) *Migrator {
func New(kubeconfigPath string, strategy string, tolerateAllNode bool) *Migrator {
m := &Migrator{
log: log.WithField("component", "migrator"),
strategy: strategy,
log: log.WithField("component", "migrator"),
TolerateAllNodes: tolerateAllNode,
strategy: strategy,
}
if kubeconfigPath != "" {
m.log.WithField("kubeconfig", kubeconfigPath).Debug("Created client from kubeconfig")
Expand Down
2 changes: 1 addition & 1 deletion pkg/migrator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (m *Migrator) Validate() (*v1.PersistentVolumeClaim, []strategies.Strategy)
if err != nil {
m.log.WithError(err).Panic("Failed to get controllers")
}
baseStrategy := strategies.NewBaseStrategy(m.kConfig, m.kClient)
baseStrategy := strategies.NewBaseStrategy(m.kConfig, m.kClient, m.TolerateAllNodes)
allStrategies := strategies.StrategyInstances(baseStrategy)
compatibleStrategies := make([]strategies.Strategy, 0)
ctx := strategies.MigrationContext{
Expand Down
28 changes: 17 additions & 11 deletions pkg/mover/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ type MoverJob struct {
kJob *batchv1.Job
kClient *kubernetes.Clientset

mode MoverType
log *log.Entry
mode MoverType
log *log.Entry
tolerateAllNodes bool
}

func NewMoverJob(client *kubernetes.Clientset, mode MoverType) *MoverJob {
func NewMoverJob(client *kubernetes.Clientset, mode MoverType, tolerateAllNodes bool) *MoverJob {
return &MoverJob{
kClient: client,
log: log.WithField("component", "mover-job"),
mode: mode,
kClient: client,
log: log.WithField("component", "mover-job"),
tolerateAllNodes: tolerateAllNodes,
mode: mode,
}
}

Expand Down Expand Up @@ -101,11 +103,6 @@ func (m *MoverJob) Start() *MoverJob {
Spec: corev1.PodSpec{
Volumes: volumes,
RestartPolicy: corev1.RestartPolicyOnFailure,
Tolerations: []corev1.Toleration{
{
Operator: corev1.TolerationOpExists,
},
},
Containers: []corev1.Container{
{
Name: ContainerName,
Expand All @@ -121,6 +118,15 @@ func (m *MoverJob) Start() *MoverJob {
},
},
}

if m.tolerateAllNodes {
job.Spec.Template.Spec.Tolerations = []corev1.Toleration{
{
Operator: corev1.TolerationOpExists,
},
}
}

j, err := m.kClient.BatchV1().Jobs(m.Namespace).Create(context.TODO(), job, metav1.CreateOptions{})
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/strategies/copyTwiceName.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemp
}

c.log.WithField("stage", 2).Debug("starting mover job")
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSync)
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSync, c.tolerateAllNodes)
c.tempMover.Namespace = destTemplate.ObjectMeta.Namespace
c.tempMover.SourceVolume = sourcePVC
c.tempMover.DestVolume = c.TempDestPVC
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemp
c.DestPVC = destInst

c.log.WithField("stage", 5).Debug("starting mover job to final PVC")
c.finalMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSync)
c.finalMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSync, c.tolerateAllNodes)
c.finalMover.Namespace = destTemplate.ObjectMeta.Namespace
c.finalMover.SourceVolume = c.TempDestPVC
c.finalMover.DestVolume = c.DestPVC
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategies/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *ExportStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v
c.log.Warning("This strategy assumes you've stopped all pods accessing this data.")

c.log.Debug("starting mover job")
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSleep)
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSleep, c.tolerateAllNodes)
c.tempMover.Namespace = destTemplate.ObjectMeta.Namespace
c.tempMover.SourceVolume = sourcePVC
c.tempMover.Name = fmt.Sprintf("korb-job-%s", sourcePVC.UID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategies/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *ImportStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemplate *v
c.log.Warning("This strategy assumes you've stopped all pods accessing this data.")

c.log.Debug("starting mover job")
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSleep)
c.tempMover = mover.NewMoverJob(c.kClient, mover.MoverTypeSleep, c.tolerateAllNodes)
c.tempMover.Namespace = destTemplate.ObjectMeta.Namespace
c.tempMover.SourceVolume = sourcePVC
c.tempMover.Name = fmt.Sprintf("korb-job-%s", sourcePVC.UID)
Expand Down
12 changes: 7 additions & 5 deletions pkg/strategies/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ type BaseStrategy struct {
kConfig *rest.Config
kClient *kubernetes.Clientset

log *log.Entry
log *log.Entry
tolerateAllNodes bool
}

func NewBaseStrategy(config *rest.Config, client *kubernetes.Clientset) BaseStrategy {
func NewBaseStrategy(config *rest.Config, client *kubernetes.Clientset, tolerateAllNodes bool) BaseStrategy {
return BaseStrategy{
kConfig: config,
kClient: client,
log: log.WithField("component", "strategy"),
kConfig: config,
kClient: client,
tolerateAllNodes: tolerateAllNodes,
log: log.WithField("component", "strategy"),
}
}

Expand Down

0 comments on commit 9e40c71

Please sign in to comment.