Skip to content

Commit

Permalink
support imported edges
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Singer committed Mar 7, 2024
1 parent 9bd926f commit 47600c5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pkg/engine/operational_eval/vertex_path_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func (v *pathExpandVertex) Key() Key {
}

func (v *pathExpandVertex) Evaluate(eval *Evaluator) error {
// if both the source and target are imported resources we can skip the evaluation since its just for context
// we will ensure the edge remains
sourceRes, err := eval.Solution.RawView().Vertex(v.SatisfactionEdge.Source)
if err != nil {
return fmt.Errorf("could not find source resource %s: %w", v.SatisfactionEdge.Source, err)
}
targetRes, err := eval.Solution.RawView().Vertex(v.SatisfactionEdge.Target)
if err != nil {
return fmt.Errorf("could not find target resource %s: %w", v.SatisfactionEdge.Target, err)
}
if sourceRes.Imported && targetRes.Imported {
eval.Solution.RawView().AddEdge(v.SatisfactionEdge.Source, v.SatisfactionEdge.Target)

Check failure on line 61 in pkg/engine/operational_eval/vertex_path_expand.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `(github.com/dominikbraun/graph.Graph[github.com/klothoplatform/klotho/pkg/construct.ResourceId, *github.com/klothoplatform/klotho/pkg/construct.Resource]).AddEdge` is not checked (errcheck)
return nil
}

runner := &pathExpandVertexRunner{Eval: eval}
edgeExpander := &path_selection.EdgeExpand{Ctx: eval.Solution}
return v.runEvaluation(eval, runner, edgeExpander)
Expand Down
14 changes: 14 additions & 0 deletions pkg/engine/solution_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ func (ctx solutionContext) LoadGraph(graph construct.Graph) error {
}
for _, edge := range edges {
edgeTemplate := ctx.KB.GetEdgeTemplate(edge.Source, edge.Target)
src, err := graph.Vertex(edge.Source)
if err != nil {
return err
}
dst, err := graph.Vertex(edge.Target)
if err != nil {
return err
}
if src.Imported && dst.Imported {
if err := raw.AddEdge(edge.Source, edge.Target); err != nil {
return err
}
continue
}
if edgeTemplate == nil {
return fmt.Errorf("edge template %s -> %s not found", edge.Source, edge.Target)
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/engine/solution_context/view_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ func (view RawAccessView) RemoveVertex(hash construct.ResourceId) error {
func (view RawAccessView) AddEdge(source, target construct.ResourceId, options ...func(*graph.EdgeProperties)) error {
dfErr := view.inner.DataflowGraph().AddEdge(source, target, options...)

// check to see if both resources are imported and if so allow the edge
src, err := view.inner.DataflowGraph().Vertex(source)
if err != nil {
return err
}
dst, err := view.inner.DataflowGraph().Vertex(target)
if err != nil {
return err
}
if src.Imported && dst.Imported {
return nil
}

var deplErr error
et := view.inner.KnowledgeBase().GetEdgeTemplate(source, target)
srcRt, terr := view.inner.KnowledgeBase().GetResourceTemplate(source)
Expand All @@ -122,7 +135,6 @@ func (view RawAccessView) AddEdge(source, target construct.ResourceId, options .
}
}

var err error
if dfErr != nil && !errors.Is(dfErr, graph.ErrEdgeAlreadyExists) {
err = errors.Join(err, dfErr)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/infra/iac/templates/aws/memorydb_cluster/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,11 @@ function properties(object: aws.memorydb.Cluster, args: Args) {
}
return endpointStrings.join(',')
})}`,
PrimaryAddress: pulumi.interpolate`${object.clusterEndpoints.apply(
(endpoint) => endpoint[0].address
)}`,
PrimaryPort: pulumi.interpolate`${object.clusterEndpoints.apply(
(endpoint) => endpoint[0].port
)}`,
}
}
10 changes: 10 additions & 0 deletions pkg/templates/aws/resources/memorydb_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ properties:
description: The endpoints of the cluster as a string.
configuration_disabled: true
deploy_time: true
PrimaryAddress:
type: string
description: The address of the primary node.
configuration_disabled: true
deploy_time: true
PrimaryPort:
type: int
description: The port number of the primary node.
configuration_disabled: true
deploy_time: true

consumption:
emitted:
Expand Down

0 comments on commit 47600c5

Please sign in to comment.