Skip to content

Commit

Permalink
Resource templating (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsinger-klotho authored Jul 26, 2023
1 parent e569839 commit 3e1d5a6
Show file tree
Hide file tree
Showing 136 changed files with 1,255 additions and 8,156 deletions.
1 change: 1 addition & 0 deletions pkg/core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type (
OperationalResourceError struct {
Needs []string
Count int
Direction Direction
Resource Resource
Parent Resource
MustCreate bool
Expand Down
18 changes: 8 additions & 10 deletions pkg/core/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type (
// Type refers to the unique type identifier of the resource
Type string `json:"type" yaml:"type"`
// Rules defines a set of rules that must pass checks and actions which must be carried out to make a resource operational
Rules OperationalTempalte `json:"rules" yaml:"rules"`
Rules []OperationalRule `json:"rules" yaml:"rules"`
// Configuration specifies how to act on any intrinsic values of a resource to make it operational
Configuration []Configuration `json:"configuration" yaml:"configuration"`
// SanitizationRules defines a set of rules that are used to ensure the resource's name is valid
Expand All @@ -111,18 +111,12 @@ type (
DeleteContext DeleteContext `json:"delete_context" yaml:"delete_context"`
}

// OperationalTempalte defines a set of rules that must pass checks and actions which must be carried out to make a resource operational
OperationalTempalte struct {
// Downstream defines a set of rules that exist downstream of the resource that must pass checks and actions which must be carried out to make a resource operational
Downstream []OperationalRule `json:"downstream" yaml:"downstream"`
// Upstream defines a set of rules that exist upstream of the resource that must pass checks and actions which must be carried out to make a resource operational
Upstream []OperationalRule `json:"upstream" yaml:"upstream"`
}

// OperationalRule defines a rule that must pass checks and actions which must be carried out to make a resource operational
OperationalRule struct {
// Enforcement defines how the rule should be enforced
Enforcement OperationEnforcement `json:"enforcement" yaml:"enforcement"`
// Direction defines the direction of the rule. The direction options are upstream or downstream
Direction Direction `json:"direction" yaml:"direction"`
// ResourceTypes defines the resource types that the rule should be enforced on. Resource types must be specified if classifications is not specified
ResourceTypes []string `json:"resource_types" yaml:"resource_types"`
// Classifications defines the classifications that the rule should be enforced on. Classifications must be specified if resource types is not specified
Expand Down Expand Up @@ -173,6 +167,8 @@ type (
OperationEnforcement string
// UnsatisfiedActionOperation defines what action should be taken if the rule is not satisfied
UnsatisfiedActionOperation string
// Direction defines the direction of the rule. The direction options are upstream or downstream
Direction string
)

const (
Expand All @@ -187,6 +183,9 @@ const (
CreateUnsatisfiedResource UnsatisfiedActionOperation = "create"
// ErrorUnsatisfiedResource defines that an error should be returned if the rule is not satisfied
ErrorUnsatisfiedResource UnsatisfiedActionOperation = "error"

Upstream Direction = "upstream"
Downstream Direction = "downstream"
)

func (or *OperationalRule) String() string {
Expand All @@ -202,7 +201,6 @@ const (
Compute Functionality = "compute"
Cluster Functionality = "cluster"
Storage Functionality = "storage"
Network Functionality = "network"
Api Functionality = "api"
Unknown Functionality = "Unknown"

Expand Down
2 changes: 0 additions & 2 deletions pkg/engine/classification/classification.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ func (c *ClassificationDocument) GetFunctionality(resource core.Resource) core.F
functionality = core.Cluster
case "storage":
functionality = core.Storage
case "network":
functionality = core.Network
case "api":
functionality = core.Api
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (e *Engine) GenerateCombinations() ([]*SolveContext, error) {
}

func (e *Engine) SolveGraph(context *SolveContext) (*core.ResourceGraph, error) {
NUM_LOOPS := 5
NUM_LOOPS := 10
graph := context.ResourceGraph
configuredEdges := map[core.ResourceId]map[core.ResourceId]bool{}
errorMap := make(map[int][]error)
Expand Down
4 changes: 4 additions & 0 deletions pkg/engine/expand_edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,16 @@ func (e *Engine) determineCorrectPaths(dep graph.Edge[core.Resource], edgeData k
satisfyAttributeData = append(satisfyAttributeData, p)
}
}

for _, p := range satisfyAttributeData {
// Ensure we arent taking unnecessary hops to get to the destination
if !e.containsUnneccessaryHopsInPath(dep, p, edgeData) {
validPaths = append(validPaths, p)
}
}
if len(validPaths) == 0 {
return satisfyAttributeData, nil
}
return validPaths, nil
}

Expand Down
Loading

0 comments on commit 3e1d5a6

Please sign in to comment.