From 14504e5db901ad507519c272de1eb87c57eabdbb Mon Sep 17 00:00:00 2001 From: Jordan Singer Date: Thu, 16 Nov 2023 08:13:35 -0600 Subject: [PATCH] render helm charts with correct dependencies --- pkg/engine2/operational_eval/vertex_property.go | 4 ++++ pkg/infra/iac3/resource.go | 6 +----- pkg/infra/iac3/templates/aws/iam_role/factory.ts | 6 ++++++ pkg/infra/kubernetes/plugin.go | 14 +++++--------- pkg/knowledge_base2/model.go | 9 +++++++++ pkg/templates/aws/resources/iam_role.yaml | 5 +++++ pkg/templates/kubernetes/resources/config_map.yaml | 2 +- pkg/templates/kubernetes/resources/deployment.yaml | 4 ++-- pkg/templates/kubernetes/resources/service.yaml | 4 ++-- .../kubernetes/resources/storage_class.yaml | 4 ++-- .../kubernetes/resources/target_group_binding.yaml | 4 ++-- 11 files changed, 39 insertions(+), 23 deletions(-) diff --git a/pkg/engine2/operational_eval/vertex_property.go b/pkg/engine2/operational_eval/vertex_property.go index 323d927f2..e6895709c 100644 --- a/pkg/engine2/operational_eval/vertex_property.go +++ b/pkg/engine2/operational_eval/vertex_property.go @@ -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 } diff --git a/pkg/infra/iac3/resource.go b/pkg/infra/iac3/resource.go index 33b55f656..214af667e 100644 --- a/pkg/infra/iac3/resource.go +++ b/pkg/infra/iac3/resource.go @@ -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) @@ -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 diff --git a/pkg/infra/iac3/templates/aws/iam_role/factory.ts b/pkg/infra/iac3/templates/aws/iam_role/factory.ts index d9f5728a4..8c0c479b0 100644 --- a/pkg/infra/iac3/templates/aws/iam_role/factory.ts +++ b/pkg/infra/iac3/templates/aws/iam_role/factory.ts @@ -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, + } +} \ No newline at end of file diff --git a/pkg/infra/kubernetes/plugin.go b/pkg/infra/kubernetes/plugin.go index 50d2e5e99..e427042ed 100644 --- a/pkg/infra/kubernetes/plugin.go +++ b/pkg/infra/kubernetes/plugin.go @@ -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 { @@ -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 } diff --git a/pkg/knowledge_base2/model.go b/pkg/knowledge_base2/model.go index ef0575458..b71db2557 100644 --- a/pkg/knowledge_base2/model.go +++ b/pkg/knowledge_base2/model.go @@ -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 { diff --git a/pkg/templates/aws/resources/iam_role.yaml b/pkg/templates/aws/resources/iam_role.yaml index f04f8c461..7a00572f2 100644 --- a/pkg/templates/aws/resources/iam_role.yaml +++ b/pkg/templates/aws/resources/iam_role.yaml @@ -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 diff --git a/pkg/templates/kubernetes/resources/config_map.yaml b/pkg/templates/kubernetes/resources/config_map.yaml index 55d2d247e..f2569559c 100644 --- a/pkg/templates/kubernetes/resources/config_map.yaml +++ b/pkg/templates/kubernetes/resources/config_map.yaml @@ -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) diff --git a/pkg/templates/kubernetes/resources/deployment.yaml b/pkg/templates/kubernetes/resources/deployment.yaml index 5205dd55f..3f232b383 100644 --- a/pkg/templates/kubernetes/resources/deployment.yaml +++ b/pkg/templates/kubernetes/resources/deployment.yaml @@ -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: diff --git a/pkg/templates/kubernetes/resources/service.yaml b/pkg/templates/kubernetes/resources/service.yaml index 4bac7580a..6c05b3a22 100644 --- a/pkg/templates/kubernetes/resources/service.yaml +++ b/pkg/templates/kubernetes/resources/service.yaml @@ -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: diff --git a/pkg/templates/kubernetes/resources/storage_class.yaml b/pkg/templates/kubernetes/resources/storage_class.yaml index a8211b3fe..1fb3f53a8 100644 --- a/pkg/templates/kubernetes/resources/storage_class.yaml +++ b/pkg/templates/kubernetes/resources/storage_class.yaml @@ -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: diff --git a/pkg/templates/kubernetes/resources/target_group_binding.yaml b/pkg/templates/kubernetes/resources/target_group_binding.yaml index 0cf090654..270379a21 100644 --- a/pkg/templates/kubernetes/resources/target_group_binding.yaml +++ b/pkg/templates/kubernetes/resources/target_group_binding.yaml @@ -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: