Skip to content

Commit

Permalink
fix: pod crashed when creating init pod, new pod always fail because …
Browse files Browse the repository at this point in the history
…the init pod already exists (#226)

* fix: pod crashed when creaing init pod, new pod will always fail

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* fix: pod crashed when creaing init pod, new pod will always fail

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* pod crashed when creaing init pod, new pod will always fail

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* pod crashed when creaing init pod, new pod will always fail

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* pod crashed when creaing init pod, new pod will always fail

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* fix: pod crashed when creating init pod, new pod always fail because the init pod already exists

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* fix: pod crashed when creating init pod, new pod always fail because the init pod already exists

Co-authored-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

* fix: pod crashed when creating init pod, new pod always fail because the init pod already exists

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>

---------

Signed-off-by: styshoo <[email protected]>
Signed-off-by: styshoo <[email protected]>
  • Loading branch information
styshoo authored Feb 18, 2025
1 parent 76e68d6 commit d79ace5
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions cmd/provisioner-localpv/app/helper_hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
hostpath "github.com/openebs/maya/pkg/hostpath/v1alpha1"
errors "github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
k8serror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -173,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 @@ -214,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)
if err != nil {
_, 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 @@ -286,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)
if err != nil {
_, 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 @@ -355,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 @@ -366,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 d79ace5

Please sign in to comment.