Skip to content

Commit 2861425

Browse files
feat(run-pod): allow image pull retries in run pod collector (#1811)
* allow image pull retries in run pod collector * fix formatting
1 parent 18515b4 commit 2861425

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

config/crds/troubleshoot.sh_collectors.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8947,6 +8947,8 @@ spec:
89478947
type: object
89488948
runPod:
89498949
properties:
8950+
allowImagePullRetries:
8951+
type: boolean
89508952
annotations:
89518953
additionalProperties:
89528954
type: string

config/crds/troubleshoot.sh_preflights.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10767,6 +10767,8 @@ spec:
1076710767
type: object
1076810768
runPod:
1076910769
properties:
10770+
allowImagePullRetries:
10771+
type: boolean
1077010772
annotations:
1077110773
additionalProperties:
1077210774
type: string

config/crds/troubleshoot.sh_supportbundles.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10798,6 +10798,8 @@ spec:
1079810798
type: object
1079910799
runPod:
1080010800
properties:
10801+
allowImagePullRetries:
10802+
type: boolean
1080110803
annotations:
1080210804
additionalProperties:
1080310805
type: string

pkg/apis/troubleshoot/v1beta2/collector_shared.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ type Run struct {
107107
}
108108

109109
type RunPod struct {
110-
CollectorMeta `json:",inline" yaml:",inline"`
111-
Name string `json:"name,omitempty" yaml:"name,omitempty"`
112-
Namespace string `json:"namespace" yaml:"namespace"`
113-
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
114-
ImagePullSecret *ImagePullSecrets `json:"imagePullSecret,omitempty" yaml:"imagePullSecret,omitempty"`
115-
PodSpec corev1.PodSpec `json:"podSpec,omitempty" yaml:"podSpec,omitempty"`
116-
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
110+
CollectorMeta `json:",inline" yaml:",inline"`
111+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
112+
Namespace string `json:"namespace" yaml:"namespace"`
113+
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
114+
ImagePullSecret *ImagePullSecrets `json:"imagePullSecret,omitempty" yaml:"imagePullSecret,omitempty"`
115+
PodSpec corev1.PodSpec `json:"podSpec,omitempty" yaml:"podSpec,omitempty"`
116+
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
117+
AllowImagePullRetries bool `json:"allowImagePullRetries,omitempty" yaml:"allowImagePullRetries,omitempty"`
117118
}
118119

119120
type RunDaemonSet struct {

pkg/collect/run_pod.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func runWithoutTimeout(ctx context.Context, bundlePath string, clientConfig *res
171171
}
172172
if status.Status.Phase == corev1.PodPending {
173173
for _, v := range status.Status.ContainerStatuses {
174-
if v.State.Waiting != nil && v.State.Waiting.Reason == "ImagePullBackOff" {
174+
if v.State.Waiting != nil && v.State.Waiting.Reason == "ImagePullBackOff" && !runPodCollector.AllowImagePullRetries {
175175
return nil, errors.Errorf("run pod aborted after getting pod status 'ImagePullBackOff'")
176176
}
177177

@@ -355,6 +355,11 @@ func RunPodsReadyNodes(ctx context.Context, client v1.CoreV1Interface, opts RunP
355355

356356
// RunPodLogs runs a pod to completion on a node and returns its logs
357357
func RunPodLogs(ctx context.Context, client v1.CoreV1Interface, podSpec *corev1.Pod) ([]byte, error) {
358+
return RunPodLogsWithOptions(ctx, client, podSpec, false)
359+
}
360+
361+
// RunPodLogsWithOptions runs a pod to completion on a node and returns its logs with configurable options
362+
func RunPodLogsWithOptions(ctx context.Context, client v1.CoreV1Interface, podSpec *corev1.Pod, allowImagePullRetries bool) ([]byte, error) {
358363
// 1. Create
359364
pod, err := client.Pods(podSpec.Namespace).Create(ctx, podSpec, metav1.CreateOptions{})
360365
if err != nil {
@@ -380,7 +385,7 @@ func RunPodLogs(ctx context.Context, client v1.CoreV1Interface, podSpec *corev1.
380385

381386
if pod.Status.Phase == corev1.PodPending {
382387
for _, v := range pod.Status.ContainerStatuses {
383-
if v.State.Waiting != nil && v.State.Waiting.Reason == "ImagePullBackOff" {
388+
if v.State.Waiting != nil && v.State.Waiting.Reason == "ImagePullBackOff" && !allowImagePullRetries {
384389
return nil, errors.New("wait for pod aborted after getting pod status 'ImagePullBackOff'")
385390
}
386391
}

schemas/collector-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7856,6 +7856,9 @@
78567856
"namespace"
78577857
],
78587858
"properties": {
7859+
"allowImagePullRetries": {
7860+
"type": "boolean"
7861+
},
78597862
"annotations": {
78607863
"type": "object",
78617864
"additionalProperties": {

schemas/preflight-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10642,6 +10642,9 @@
1064210642
"namespace"
1064310643
],
1064410644
"properties": {
10645+
"allowImagePullRetries": {
10646+
"type": "boolean"
10647+
},
1064510648
"annotations": {
1064610649
"type": "object",
1064710650
"additionalProperties": {

schemas/supportbundle-troubleshoot-v1beta2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10688,6 +10688,9 @@
1068810688
"namespace"
1068910689
],
1069010690
"properties": {
10691+
"allowImagePullRetries": {
10692+
"type": "boolean"
10693+
},
1069110694
"annotations": {
1069210695
"type": "object",
1069310696
"additionalProperties": {

0 commit comments

Comments
 (0)