Skip to content

Commit

Permalink
fix: pod crashed when creaing init pod, new pod will always fail
Browse files Browse the repository at this point in the history
  • Loading branch information
styshoo committed Dec 25, 2024
1 parent 65a30a6 commit 4a57daf
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/provisioner-localpv/app/helper_hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ func (p *Provisioner) createInitPod(ctx context.Context, pOpts *HelperPodOptions

config.pOpts.cmdsForPath = append(config.pOpts.cmdsForPath, filepath.Join("/data/", config.volumeDir))

iPod, err := p.launchPod(ctx, config)
if err != nil {
_, err := p.launchPod(ctx, config)
if err != nil && !k8serror.IsAlreadyExists(err) {
return err
}

if err := p.exitPod(ctx, iPod); err != nil {
if err := p.exitPod(ctx, config.podName+"-"+config.pOpts.name); err != nil {
return err
}

Expand Down Expand Up @@ -215,12 +215,12 @@ func (p *Provisioner) createCleanupPod(ctx context.Context, pOpts *HelperPodOpti

config.pOpts.cmdsForPath = append(config.pOpts.cmdsForPath, filepath.Join("/data/", config.volumeDir))

cPod, err := p.launchPod(ctx, config)
_, err := p.launchPod(ctx, config)
if err != nil && !k8serror.IsAlreadyExists(err) {
return err
}

if err := p.exitPod(ctx, cPod); err != nil {
if err := p.exitPod(ctx, config.podName+"-"+config.pOpts.name); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -287,12 +287,12 @@ func (p *Provisioner) createQuotaPod(ctx context.Context, pOpts *HelperPodOption
" rm -rf " + filepath.Join("/data/", config.volumeDir) + " ; exit 1; fi"
config.pOpts.cmdsForPath = []string{"sh", "-c", fs + checkQuota}

qPod, err := p.launchPod(ctx, config)
_, err := p.launchPod(ctx, config)
if err != nil && !k8serror.IsAlreadyExists(err) {
return err
}

if err := p.exitPod(ctx, qPod); err != nil {
if err := p.exitPod(ctx, config.podName+"-"+config.pOpts.name); err != nil {
return err
}

Expand Down Expand Up @@ -356,9 +356,9 @@ func (p *Provisioner) launchPod(ctx context.Context, config podConfig) (*corev1.
return hPod, err
}

func (p *Provisioner) exitPod(ctx context.Context, hPod *corev1.Pod) error {
func (p *Provisioner) exitPod(ctx context.Context, hPodName string) error {
defer func() {
e := p.kubeClient.CoreV1().Pods(p.namespace).Delete(ctx, hPod.Name, metav1.DeleteOptions{})
e := p.kubeClient.CoreV1().Pods(p.namespace).Delete(ctx, hPodName, metav1.DeleteOptions{})
if e != nil {
klog.Errorf("unable to delete the helper pod: %v", e)
}
Expand All @@ -367,7 +367,7 @@ func (p *Provisioner) exitPod(ctx context.Context, hPod *corev1.Pod) error {
//Wait for the helper pod to complete it job and exit
completed := false
for i := 0; i < CmdTimeoutCounts; i++ {
checkPod, err := p.kubeClient.CoreV1().Pods(p.namespace).Get(ctx, hPod.Name, metav1.GetOptions{})
checkPod, err := p.kubeClient.CoreV1().Pods(p.namespace).Get(ctx, hPodName, metav1.GetOptions{})
if err != nil {
return err
} else if checkPod.Status.Phase == corev1.PodSucceeded {
Expand Down

0 comments on commit 4a57daf

Please sign in to comment.