Skip to content

Commit

Permalink
render helm charts with correct dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Singer committed Nov 16, 2023
1 parent 971d52f commit 14504e5
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 23 deletions.
4 changes: 4 additions & 0 deletions pkg/engine2/operational_eval/vertex_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func (v *propertyVertex) evaluateConstraints(sol solution_context.SolutionContex
}

func (v *propertyVertex) evaluateResourceOperational(sol solution_context.SolutionContext, res *construct.Resource) error {
if v.Ref.Property == "RequestParameters" {
fmt.Println("s")
}

if v.Template == nil || v.Template.OperationalRule == nil {
return nil
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/infra/iac3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (tc *TemplatesCompiler) convertArg(arg any, templateArg *Arg) (any, error)
case reflect.Map:
TsMap := &TsMap{m: make(map[string]any)}
for _, key := range val.MapKeys() {
if !val.MapIndex(key).IsValid() || val.MapIndex(key).IsNil() {
if !val.MapIndex(key).IsValid() || val.MapIndex(key).IsZero() {
continue
}
keyStr, found := key.Interface().(string)
Expand All @@ -126,10 +126,6 @@ func (tc *TemplatesCompiler) convertArg(arg any, templateArg *Arg) (any, error)
keyResult = fmt.Sprintf(`"%s"`, keyStr)
}
}
if keyResult == "TEST_DYNAMODB_TABLE_NAME" {
a := 1
a++
}
output, err := tc.convertArg(val.MapIndex(key).Interface(), templateArg)
if err != nil {
return "", err
Expand Down
6 changes: 6 additions & 0 deletions pkg/infra/iac3/templates/aws/iam_role/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ function create(args: Args): aws.iam.Role {
//TMPL {{- end }}
})
}

function properties(object: aws.iam.Role, args: Args) {
return {
Arn: object.arn,
}
}
14 changes: 5 additions & 9 deletions pkg/infra/kubernetes/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,7 @@ func (p *Plugin) placeResourceInChart(ctx solution_context.SolutionContext, reso

err = ctx.DeploymentGraph().RemoveVertex(resource.ID)
if err != nil {
edges, _ := ctx.DeploymentGraph().Edges()
errString := ""
for _, e := range edges {
if e.Source == resource.ID || e.Target == resource.ID {
errString += fmt.Sprintf("%s -> %s\n", e.Source, e.Target)
}
}
return false, fmt.Errorf("could not remove vertex %s from graph: %s", resource.ID, errString)
return false, fmt.Errorf("could not remove vertex %s from graph: %s", resource.ID, err)
}
chartDir, err := chart.GetProperty("Directory")
if err != nil {
Expand All @@ -163,12 +156,15 @@ func (p *Plugin) placeResourceInChart(ctx solution_context.SolutionContext, reso
if output == nil {
return false, err
}

p.resourcesInChart[chart.ID] = append(p.resourcesInChart[chart.ID], resource.ID)
p.files = append(p.files, &kio.RawFile{
FPath: fmt.Sprintf("%s/templates/%s_%s.yaml", chartDir, resource.ID.Type, resource.ID.Name),
Content: output.Content,
})
err = chart.AppendProperty("Values", output.Values)
if err != nil {
return true, err
}
return true, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/knowledge_base2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func updateModels(property *Property, properties Properties, models map[string]*
// since properties are pointers and models can be reused, we need to clone the property from the model itself
newProp := prop.Clone()
newProp.Path = fmt.Sprintf("%s.%s", name, prop.Path)

// we also need to check if the current property has a default and propagate it lower
if p.DefaultValue != nil {
defaultMap, ok := p.DefaultValue.(map[string]any)
if !ok {
return fmt.Errorf("default value for %s is not a map", p.Path)
}
newProp.DefaultValue = defaultMap[name]
}
properties[name] = newProp
}
if property != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/templates/aws/resources/iam_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ properties:
type: map(string,string)
Null:
type: map(string,string)
Arn:
type: string
configuration_disabled: true
deploy_time: true

classification:
is:
- role
Expand Down
2 changes: 1 addition & 1 deletion pkg/templates/kubernetes/resources/config_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ properties:
kubernetes:TypeMeta:
type: model
default_value:
ApiVersion: about.k8s.io/v1alpha1
ApiVersion: v1
Kind: ConfigMap
Metadata:
type: model(kubernetes:ObjectMeta)
Expand Down
4 changes: 2 additions & 2 deletions pkg/templates/kubernetes/resources/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ properties:
kubernetes:TypeMeta:
type: model
default_value:
apiVersion: apps/v1
kind: Deployment
ApiVersion: apps/v1
Kind: Deployment
Metadata:
type: model(kubernetes:ObjectMeta)
Spec:
Expand Down
4 changes: 2 additions & 2 deletions pkg/templates/kubernetes/resources/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ properties:
kubernetes:TypeMeta:
type: model
default_value:
apiVersion: v1
kind: Service
ApiVersion: v1
Kind: Service
Metadata:
type: model(kubernetes:ObjectMeta)
Spec:
Expand Down
4 changes: 2 additions & 2 deletions pkg/templates/kubernetes/resources/storage_class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ properties:
kubernetes:TypeMeta:
type: model
default_value:
apiVersion: storage.k8s.io/v1
kind: StorageClass
ApiVersion: storage.k8s.io/v1
Kind: StorageClass
Metadata:
type: model(kubernetes:ObjectMeta)
Provisioner:
Expand Down
4 changes: 2 additions & 2 deletions pkg/templates/kubernetes/resources/target_group_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ properties:
kubernetes:TypeMeta:
type: model
default_value:
apiVersion: v1
kind: ObjectMeta
ApiVersion: v1
Kind: ObjectMeta
Metadata:
type: model(kubernetes:ObjectMeta)
Spec:
Expand Down

0 comments on commit 14504e5

Please sign in to comment.