this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(controller): do not prune graph when old revision is not provided

Man I misss Option<T>

Khue Doan eb585903 766e3baf

+83 -13
+19 -13
controller/workflows/infra.go
··· 43 43 }) 44 44 45 45 var graph *activities.Graph 46 - var changedModules []string 47 - 48 - graphFuture := workflow.ExecuteActivity(analysisCtx, activities.TerragruntGraph, path+"/infra/"+input.Stack) 49 - changedFuture := workflow.ExecuteActivity(analysisCtx, activities.ChangedModules, path, input.OldRevision) 46 + var prunedGraph *activities.Graph 50 47 51 - if err := graphFuture.Get(ctx, &graph); err != nil { 52 - return nil, err 53 - } 54 - if err := changedFuture.Get(ctx, &changedModules); err != nil { 48 + // Get the terragrunt graph 49 + if err := workflow.ExecuteActivity(analysisCtx, activities.TerragruntGraph, path+"/infra/"+input.Stack).Get(ctx, &graph); err != nil { 55 50 return nil, err 56 51 } 57 52 58 - var prunedGraph *activities.Graph 59 - if err := workflow.ExecuteActivity(analysisCtx, activities.PruneGraph, graph, changedModules).Get(ctx, &prunedGraph); err != nil { 60 - return nil, err 61 - } 53 + // If oldRevision is not provided, use the full graph (no pruning) 54 + if input.OldRevision == "" { 55 + logger.Info("No oldRevision provided, using full graph", "nodes", len(graph.Nodes)) 56 + prunedGraph = graph 57 + } else { 58 + // Determine changed modules and prune graph 59 + var changedModules []string 60 + if err := workflow.ExecuteActivity(analysisCtx, activities.ChangedModules, path, input.OldRevision).Get(ctx, &changedModules); err != nil { 61 + return nil, err 62 + } 62 63 63 - logger.Info("Graph pruning completed", "nodes", len(prunedGraph.Nodes)) 64 + if err := workflow.ExecuteActivity(analysisCtx, activities.PruneGraph, graph, changedModules).Get(ctx, &prunedGraph); err != nil { 65 + return nil, err 66 + } 67 + 68 + logger.Info("Graph pruning completed", "nodes", len(prunedGraph.Nodes)) 69 + } 64 70 65 71 for levelIndex, level := range prunedGraph.TopologicalSort() { 66 72 logger.Info("Starting terragrunt apply", "level", levelIndex, "modules", level)
+64
controller/workflows/infra_test.go
··· 396 396 s.True(result.Nodes["module1"]) 397 397 } 398 398 399 + func (s *InfraWorkflowTestSuite) TestInfraWorkflow_NoOldRevisionProvided() { 400 + // Test that when oldRevision is not provided, all modules are deployed 401 + input := InfraInputs{ 402 + Url: "https://github.com/example/repo.git", 403 + Revision: "main", 404 + OldRevision: "", // Empty string - no old revision provided 405 + Stack: "dev", 406 + } 407 + repoPath := "/tmp/infra-12345" 408 + 409 + // Full graph with all modules 410 + graph := &activities.Graph{ 411 + Nodes: map[string]bool{ 412 + "vpc": true, 413 + "database": true, 414 + "loadbalancer": true, 415 + "app": true, 416 + "monitoring": true, 417 + }, 418 + Edges: map[string][]string{ 419 + "app": {"database", "loadbalancer"}, 420 + "database": {"vpc"}, 421 + "loadbalancer": {"vpc"}, 422 + "monitoring": {"app"}, 423 + }, 424 + } 425 + 426 + // When oldRevision is empty, the workflow should use the full graph 427 + // without calling ChangedModules or PruneGraph activities 428 + 429 + s.env.OnActivity(activities.Clone, mock.Anything, input.Url, input.Revision).Return(repoPath, nil) 430 + s.env.OnActivity(activities.TerragruntGraph, mock.Anything, repoPath+"/infra/"+input.Stack).Return(graph, nil) 431 + 432 + // Mock TerragruntApply calls in dependency order for all modules 433 + // Level 0: vpc 434 + s.env.OnActivity(activities.TerragruntApply, mock.Anything, input.Url, input.Revision, "vpc", input.Stack).Return(nil) 435 + // Level 1: database, loadbalancer 436 + s.env.OnActivity(activities.TerragruntApply, mock.Anything, input.Url, input.Revision, "database", input.Stack).Return(nil) 437 + s.env.OnActivity(activities.TerragruntApply, mock.Anything, input.Url, input.Revision, "loadbalancer", input.Stack).Return(nil) 438 + // Level 2: app 439 + s.env.OnActivity(activities.TerragruntApply, mock.Anything, input.Url, input.Revision, "app", input.Stack).Return(nil) 440 + // Level 3: monitoring 441 + s.env.OnActivity(activities.TerragruntApply, mock.Anything, input.Url, input.Revision, "monitoring", input.Stack).Return(nil) 442 + 443 + s.env.ExecuteWorkflow(Infra, input) 444 + 445 + s.True(s.env.IsWorkflowCompleted()) 446 + s.NoError(s.env.GetWorkflowError()) 447 + 448 + var result *activities.Graph 449 + s.NoError(s.env.GetWorkflowResult(&result)) 450 + 451 + // Verify that all modules are in the result graph 452 + s.True(result.Nodes["vpc"]) 453 + s.True(result.Nodes["database"]) 454 + s.True(result.Nodes["loadbalancer"]) 455 + s.True(result.Nodes["app"]) 456 + s.True(result.Nodes["monitoring"]) 457 + 458 + // Verify that the result graph has the same structure as the original 459 + s.Equal(len(graph.Nodes), len(result.Nodes)) 460 + s.Equal(len(graph.Edges), len(result.Edges)) 461 + } 462 + 399 463 func TestInfraWorkflowTestSuite(t *testing.T) { 400 464 suite.Run(t, new(InfraWorkflowTestSuite)) 401 465 }