( ctx context.Context, deps commandDeps, client DaemonClient, operationID string, )
| 184 | } |
| 185 | |
| 186 | func waitForSupportBundle( |
| 187 | ctx context.Context, |
| 188 | deps commandDeps, |
| 189 | client DaemonClient, |
| 190 | operationID string, |
| 191 | ) (SupportBundleOperationRecord, error) { |
| 192 | operationID = strings.TrimSpace(operationID) |
| 193 | if operationID == "" { |
| 194 | return SupportBundleOperationRecord{}, errors.New("cli: support bundle operation id is required") |
| 195 | } |
| 196 | waitCtx := ctx |
| 197 | if waitCtx == nil { |
| 198 | waitCtx = context.Background() |
| 199 | } |
| 200 | if _, hasDeadline := waitCtx.Deadline(); !hasDeadline { |
| 201 | var cancel context.CancelFunc |
| 202 | waitCtx, cancel = context.WithTimeout(waitCtx, defaultSupportBundleTimeout) |
| 203 | defer cancel() |
| 204 | } |
| 205 | |
| 206 | ticker := time.NewTicker(deps.pollInterval) |
| 207 | defer ticker.Stop() |
| 208 | |
| 209 | for { |
| 210 | select { |
| 211 | case <-waitCtx.Done(): |
| 212 | return SupportBundleOperationRecord{}, fmt.Errorf( |
| 213 | "cli: support bundle did not complete before timeout: %w", |
| 214 | waitCtx.Err(), |
| 215 | ) |
| 216 | case <-ticker.C: |
| 217 | operation, err := client.GetSupportBundle(waitCtx, operationID) |
| 218 | if err != nil { |
| 219 | continue |
| 220 | } |
| 221 | switch strings.TrimSpace(operation.Status) { |
| 222 | case supportStatusCompleted: |
| 223 | return operation, nil |
| 224 | case supportStatusFailed: |
| 225 | reason := strings.TrimSpace(operation.FailureReason) |
| 226 | if reason == "" { |
| 227 | reason = "support bundle creation failed" |
| 228 | } |
| 229 | return operation, errors.New("cli: " + reason) |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | func resolveSupportBundleOutputPath( |
| 236 | deps commandDeps, |
no test coverage detected