waitRolloutWithoutApproval waits for a rollout to complete without going through the issue approval flow. This is used for test scenarios where issues are not created (e.g., direct rollout creation).
(ctx context.Context, rolloutName string)
| 195 | // waitRolloutWithoutApproval waits for a rollout to complete without going through the issue approval flow. |
| 196 | // This is used for test scenarios where issues are not created (e.g., direct rollout creation). |
| 197 | func (ctl *controller) waitRolloutWithoutApproval(ctx context.Context, rolloutName string) error { |
| 198 | ticker := time.NewTicker(300 * time.Millisecond) |
| 199 | defer ticker.Stop() |
| 200 | |
| 201 | // Add timeout to prevent infinite loops |
| 202 | timeout := time.After(2 * time.Minute) |
| 203 | startTime := time.Now() |
| 204 | |
| 205 | rolloutResp, err := ctl.rolloutServiceClient.GetRollout(ctx, connect.NewRequest(&v1pb.GetRolloutRequest{ |
| 206 | Name: rolloutName, |
| 207 | })) |
| 208 | if err != nil { |
| 209 | return err |
| 210 | } |
| 211 | rollout := rolloutResp.Msg |
| 212 | for _, stage := range rollout.Stages { |
| 213 | var runTasks []string |
| 214 | for _, task := range stage.Tasks { |
| 215 | if task.Status == v1pb.Task_NOT_STARTED { |
| 216 | runTasks = append(runTasks, task.Name) |
| 217 | } |
| 218 | } |
| 219 | if len(runTasks) > 0 { |
| 220 | _, err := ctl.rolloutServiceClient.BatchRunTasks(ctx, connect.NewRequest(&v1pb.BatchRunTasksRequest{ |
| 221 | Parent: fmt.Sprintf("%s/stages/-", rolloutName), |
| 222 | Tasks: runTasks, |
| 223 | })) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | for { |
| 231 | select { |
| 232 | case <-timeout: |
| 233 | // Timeout - fetch current state for debugging |
| 234 | rolloutResp, err := ctl.rolloutServiceClient.GetRollout(ctx, connect.NewRequest(&v1pb.GetRolloutRequest{ |
| 235 | Name: rolloutName, |
| 236 | })) |
| 237 | if err != nil { |
| 238 | return errors.Wrapf(err, "timeout after %v waiting for rollout (failed to fetch rollout state)", time.Since(startTime)) |
| 239 | } |
| 240 | rollout := rolloutResp.Msg |
| 241 | var taskStatuses []string |
| 242 | for _, stage := range rollout.Stages { |
| 243 | for _, task := range stage.Tasks { |
| 244 | taskStatuses = append(taskStatuses, fmt.Sprintf("%s: %s", task.Name, task.Status.String())) |
| 245 | } |
| 246 | } |
| 247 | return errors.Errorf("timeout after %v waiting for rollout to complete, task statuses: %s", |
| 248 | time.Since(startTime), strings.Join(taskStatuses, ", ")) |
| 249 | |
| 250 | case <-ticker.C: |
| 251 | rolloutResp, err := ctl.rolloutServiceClient.GetRollout(ctx, connect.NewRequest(&v1pb.GetRolloutRequest{ |
| 252 | Name: rolloutName, |
| 253 | })) |
| 254 | if err != nil { |