Skip to content

Commit

Permalink
fix a bunch of deprecated things
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed May 22, 2024
1 parent 2169d52 commit de54f41
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 46 deletions.
22 changes: 0 additions & 22 deletions pkg/migrator/validateDeployments.go

This file was deleted.

8 changes: 6 additions & 2 deletions pkg/mover/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mover

import (
"bytes"
"context"
"io"
"os"

Expand Down Expand Up @@ -33,13 +34,16 @@ func (m *MoverJob) Exec(pod v1.Pod, config *rest.Config, cmd []string, input io.
done := false
go func() {
for {
io.Copy(os.Stdout, prefixReader)
_, err := io.Copy(os.Stdout, prefixReader)
if err != nil {
m.log.WithError(err).Warning("failed to copy")
}
if done {
return
}
}
}()
err = exec.Stream(remotecommand.StreamOptions{
err = exec.StreamWithContext(context.Background(), remotecommand.StreamOptions{
Stdin: input,
Stdout: output,
Stderr: os.Stdout,
Expand Down
23 changes: 14 additions & 9 deletions pkg/mover/mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -107,7 +106,7 @@ func (m *MoverJob) Start() *MoverJob {
{
Name: ContainerName,
Image: config.ContainerImage,
ImagePullPolicy: v1.PullAlways,
ImagePullPolicy: corev1.PullAlways,
Args: []string{string(m.mode)},
VolumeMounts: mounts,
TTY: true,
Expand All @@ -127,15 +126,15 @@ func (m *MoverJob) Start() *MoverJob {
}
}

j, err := m.kClient.BatchV1().Jobs(m.Namespace).Create(context.TODO(), job, metav1.CreateOptions{})
j, err := m.kClient.BatchV1().Jobs(m.Namespace).Create(context.Background(), job, metav1.CreateOptions{})
if err != nil {
panic(err)
}
m.kJob = j
return m
}

func (m *MoverJob) followLogs(pod v1.Pod) {
func (m *MoverJob) followLogs(pod corev1.Pod) {
req := m.kClient.CoreV1().Pods(m.Namespace).GetLogs(pod.Name, &corev1.PodLogOptions{
Follow: true,
Container: ContainerName,
Expand All @@ -149,7 +148,10 @@ func (m *MoverJob) followLogs(pod v1.Pod) {
prefixReader := prefixer.New(podLogs, "[mover logs]: ")

for {
io.Copy(os.Stdout, prefixReader)
_, err := io.Copy(os.Stdout, prefixReader)
if err != nil {
m.log.WithError(err).Warning("failed to copy")
}
}
}

Expand All @@ -161,14 +163,17 @@ func (m *MoverJob) getDeleteOptions() metav1.DeleteOptions {
}

func (m *MoverJob) Cleanup() error {
err := m.kClient.BatchV1().Jobs(m.Namespace).Delete(context.TODO(), m.Name, m.getDeleteOptions())
err := m.kClient.BatchV1().Jobs(m.Namespace).Delete(context.Background(), m.Name, m.getDeleteOptions())
if err != nil {
m.log.WithError(err).Debug("Failed to delete job")
m.log.WithError(err).WithField("name", m.Name).Debug("Failed to delete job")
return err
}
pods := m.getPods()
pods := m.getPods(context.Background())
for _, pod := range pods {
m.kClient.CoreV1().Pods(m.Namespace).Delete(context.TODO(), pod.Name, m.getDeleteOptions())
err := m.kClient.CoreV1().Pods(m.Namespace).Delete(context.Background(), pod.Name, m.getDeleteOptions())
if err != nil {
m.log.WithError(err).WithField("name", pod.Name).Warning("failed to delete pod")
}
}
return nil
}
22 changes: 15 additions & 7 deletions pkg/strategies/copyTwiceName.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemp
c.log.WithError(err).Warning("Failed to delete source pvc")
return c.Cleanup()
}
c.waitForPVCDeletion(sourcePVC)
err = c.waitForPVCDeletion(sourcePVC)
if err != nil {
c.log.WithError(err).Warning("failed to delete source pvc")
return c.Cleanup()
}

c.log.WithField("stage", 4).Debug("creating final destination PVC")
destInst, err := c.kClient.CoreV1().PersistentVolumeClaims(destTemplate.ObjectMeta.Namespace).Create(context.TODO(), destTemplate, metav1.CreateOptions{})
Expand All @@ -128,10 +132,14 @@ func (c *CopyTwiceNameStrategy) Do(sourcePVC *v1.PersistentVolumeClaim, destTemp
c.log.WithField("stage", 6).Debug("deleting temporary PVC")
err = c.kClient.CoreV1().PersistentVolumeClaims(destTemplate.ObjectMeta.Namespace).Delete(context.TODO(), c.TempDestPVC.Name, c.getDeleteOptions())
if err != nil {
c.log.WithError(err).Warning("Failed to delete temporary destination pvc")
c.log.WithError(err).Warning("failed to delete temporary destination pvc")
return c.Cleanup()
}
err = c.waitForPVCDeletion(c.TempDestPVC)
if err != nil {
c.log.WithError(err).Warning("failed to delete temporary destination pvc")
return c.Cleanup()
}
c.waitForPVCDeletion(c.TempDestPVC)

c.log.Info("And we're done")

Expand All @@ -157,8 +165,8 @@ func (c *CopyTwiceNameStrategy) setTimeout(pvc *v1.PersistentVolumeClaim) {
}

func (c *CopyTwiceNameStrategy) waitForPVCDeletion(pvc *v1.PersistentVolumeClaim) error {
return wait.Poll(2*time.Second, c.timeout, func() (bool, error) {
_, err := c.kClient.CoreV1().PersistentVolumeClaims(pvc.ObjectMeta.Namespace).Get(context.TODO(), pvc.ObjectMeta.Name, metav1.GetOptions{})
return wait.PollUntilContextTimeout(context.Background(), 2*time.Second, c.timeout, true, func(ctx context.Context) (bool, error) {
_, err := c.kClient.CoreV1().PersistentVolumeClaims(pvc.ObjectMeta.Namespace).Get(ctx, pvc.ObjectMeta.Name, metav1.GetOptions{})
if errors.IsNotFound(err) {
return true, nil
}
Expand All @@ -168,8 +176,8 @@ func (c *CopyTwiceNameStrategy) waitForPVCDeletion(pvc *v1.PersistentVolumeClaim
}

func (c *CopyTwiceNameStrategy) waitForBound(pvc *v1.PersistentVolumeClaim) error {
return wait.Poll(2*time.Second, c.timeout, func() (bool, error) {
pvc, err := c.kClient.CoreV1().PersistentVolumeClaims(pvc.ObjectMeta.Namespace).Get(context.TODO(), pvc.ObjectMeta.Name, metav1.GetOptions{})
return wait.PollUntilContextTimeout(context.Background(), 2*time.Second, c.timeout, true, func(ctx context.Context) (bool, error) {
pvc, err := c.kClient.CoreV1().PersistentVolumeClaims(pvc.ObjectMeta.Namespace).Get(ctx, pvc.ObjectMeta.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategies/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *ExportStrategy) CopyOut(pod v1.Pod, config *rest.Config, name string) (
func (c *ExportStrategy) Cleanup() error {
c.log.Info("Cleaning up...")
if c.tempMover != nil {
c.tempMover.Cleanup()
return c.tempMover.Cleanup()
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/strategies/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *ImportStrategy) CopyInto(pod v1.Pod, config *rest.Config, localPath str
func (c *ImportStrategy) Cleanup() error {
c.log.Info("Cleaning up...")
if c.tempMover != nil {
c.tempMover.Cleanup()
return c.tempMover.Cleanup()
}
return nil
}
4 changes: 0 additions & 4 deletions pkg/strategies/scaleDownCreateUpdate.go

This file was deleted.

0 comments on commit de54f41

Please sign in to comment.