Skip to content

Commit

Permalink
now properly waits for cfgmaps/secrets
Browse files Browse the repository at this point in the history
Signed-off-by: Surax98 <[email protected]>
  • Loading branch information
Surax98 committed May 21, 2024
1 parent 243676f commit ada504a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
54 changes: 26 additions & 28 deletions pkg/virtualkubelet/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,18 @@ func RemoteExecution(ctx context.Context, config VirtualKubeletConfig, p *Virtua
req.Pod = *pod
startTime := time.Now()

for {
timeNow := time.Now()
if timeNow.Sub(startTime).Seconds() < time.Hour.Minutes()*5 {

_, err := p.clientSet.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})
if err != nil {
log.G(ctx).Warning("Deleted Pod before actual creation")
return nil
}

var failed bool
timeNow := time.Now()
_, err := p.clientSet.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})
if err != nil {
log.G(ctx).Warning("Deleted Pod before actual creation")
return nil
}

for _, volume := range pod.Spec.Volumes {
var failed bool

for _, volume := range pod.Spec.Volumes {
for {
if timeNow.Sub(startTime).Seconds() < time.Hour.Minutes()*5 {
if volume.ConfigMap != nil {
cfgmap, err := p.clientSet.CoreV1().ConfigMaps(pod.Namespace).Get(ctx, volume.ConfigMap.Name, metav1.GetOptions{})
if err != nil {
Expand All @@ -292,8 +290,8 @@ func RemoteExecution(ctx context.Context, config VirtualKubeletConfig, p *Virtua
pod.Status.Phase = "Initializing"
p.UpdatePod(ctx, pod)
}
break
} else {
failed = false
req.ConfigMaps = append(req.ConfigMaps, *cfgmap)
}
} else if volume.Secret != nil {
Expand All @@ -305,29 +303,29 @@ func RemoteExecution(ctx context.Context, config VirtualKubeletConfig, p *Virtua
pod.Status.Phase = "Initializing"
p.UpdatePod(ctx, pod)
}
break
} else {
failed = false
req.Secrets = append(req.Secrets, *scrt)
}
}
}

if failed {
time.Sleep(time.Second)
continue
if failed {
time.Sleep(time.Second)
continue
} else {
pod.Status.Phase = v1.PodPending
p.UpdatePod(ctx, pod)
break
}
} else {
pod.Status.Phase = v1.PodPending
pod.Status.Phase = v1.PodFailed
pod.Status.Reason = "CFGMaps/Secrets not found"
for i, _ := range pod.Status.ContainerStatuses {
pod.Status.ContainerStatuses[i].Ready = false
}
p.UpdatePod(ctx, pod)
break
}
} else {
pod.Status.Phase = v1.PodFailed
pod.Status.Reason = "CFGMaps/Secrets not found"
for i, _ := range pod.Status.ContainerStatuses {
pod.Status.ContainerStatuses[i].Ready = false
return errors.New("unable to retrieve ConfigMaps or Secrets. Check logs")
}
p.UpdatePod(ctx, pod)
return errors.New("unable to retrieve ConfigMaps or Secrets. Check logs")
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/virtualkubelet/virtualkubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ func (p *VirtualKubeletProvider) statusLoop(ctx context.Context) {

var podsList []*v1.Pod
for _, pod := range p.pods {
podsList = append(podsList, pod)
if pod.Status.Phase != "Initializing" {
podsList = append(podsList, pod)
}
}

if podsList != nil {
Expand Down

0 comments on commit ada504a

Please sign in to comment.