From 04d8e4280ff7fe2044bf03e2c3f6c88547a6f8e0 Mon Sep 17 00:00:00 2001 From: Jordan Singer Date: Wed, 20 Dec 2023 11:16:11 -0600 Subject: [PATCH] fix eks bugs --- pkg/engine2/testdata/k8s_api.expect.yaml | 1 - pkg/infra/iac3/plugin.go | 2 +- pkg/knowledge_base2/emitter.go | 19 +++++++++---------- .../properties/list_property.go | 2 +- pkg/templates/aws/edges/eks_cluster-vpc.yaml | 7 ++++++- pkg/templates/aws/resources/eks_cluster.yaml | 10 ---------- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/pkg/engine2/testdata/k8s_api.expect.yaml b/pkg/engine2/testdata/k8s_api.expect.yaml index eb4a2c7a6..224983cf9 100755 --- a/pkg/engine2/testdata/k8s_api.expect.yaml +++ b/pkg/engine2/testdata/k8s_api.expect.yaml @@ -452,7 +452,6 @@ resources: Region: aws:region:region-0 aws:eks_cluster:eks_cluster-0: ClusterRole: aws:iam_role:ClusterRole-eks_cluster-0 - KubeConfig: kubernetes:kube_config:eks_cluster-0-kube_config SecurityGroups: - aws:security_group:vpc-0:eks_cluster-0-security_group Subnets: diff --git a/pkg/infra/iac3/plugin.go b/pkg/infra/iac3/plugin.go index b438347ec..b249039a2 100644 --- a/pkg/infra/iac3/plugin.go +++ b/pkg/infra/iac3/plugin.go @@ -145,7 +145,7 @@ func (p Plugin) Translate(ctx solution_context.SolutionContext) ([]kio.File, err func (p *Plugin) sanitizeConfig() error { reg, err := regexp.Compile("[^a-zA-Z0-9-_]+") if err != nil { - return fmt.Errorf("Error compiling regex: %v", err) + return fmt.Errorf("error compiling regex: %v", err) } p.Config.AppName = reg.ReplaceAllString(p.Config.AppName, "") return nil diff --git a/pkg/knowledge_base2/emitter.go b/pkg/knowledge_base2/emitter.go index 211633003..581ae7a42 100644 --- a/pkg/knowledge_base2/emitter.go +++ b/pkg/knowledge_base2/emitter.go @@ -90,24 +90,24 @@ func ConsumeFromResource(consumer, emitter *construct.Resource, ctx DynamicConte addErr(consume, emit, err) continue } - val, err = sanitizeForConsumption(ctx, resource, consumeTmpl.GetProperty(consume.PropertyPath), val) + pval, err := resource.GetProperty(consume.PropertyPath) if err != nil { addErr(consume, emit, err) continue } - pval, err := resource.GetProperty(consume.PropertyPath) + if consume.Converter != "" { + val, err = consume.Convert(val, id, ctx) + if err != nil { + addErr(consume, emit, err) + continue + } + } + val, err = sanitizeForConsumption(ctx, resource, consumeTmpl.GetProperty(consume.PropertyPath), val) if err != nil { addErr(consume, emit, err) continue } if pval == nil { - if consume.Converter != "" { - val, err = consume.Convert(val, id, ctx) - if err != nil { - addErr(consume, emit, err) - continue - } - } delays = append(delays, DelayedConsumption{ Value: val, Resource: id, @@ -115,7 +115,6 @@ func ConsumeFromResource(consumer, emitter *construct.Resource, ctx DynamicConte }) continue } - err = consume.Consume(val, ctx, resource) if err != nil { addErr(consume, emit, err) diff --git a/pkg/knowledge_base2/properties/list_property.go b/pkg/knowledge_base2/properties/list_property.go index 40c045c1a..d56e9ac68 100644 --- a/pkg/knowledge_base2/properties/list_property.go +++ b/pkg/knowledge_base2/properties/list_property.go @@ -177,7 +177,7 @@ func (l *ListProperty) Validate(resource *construct.Resource, value any, ctx kno listVal, ok := value.([]any) if !ok { - return fmt.Errorf("invalid map value %v", value) + return fmt.Errorf("invalid list value %v", value) } if l.MinLength != nil { if len(listVal) < *l.MinLength { diff --git a/pkg/templates/aws/edges/eks_cluster-vpc.yaml b/pkg/templates/aws/edges/eks_cluster-vpc.yaml index 153e504cb..a0d582945 100644 --- a/pkg/templates/aws/edges/eks_cluster-vpc.yaml +++ b/pkg/templates/aws/edges/eks_cluster-vpc.yaml @@ -25,4 +25,9 @@ operational_rules: - selector: aws:security_group_rule properties: SecurityGroupId: '{{ fieldRef "ClusterSecurityGroup" .Source }}' - Type: ingress \ No newline at end of file + Type: ingress + - resource: '{{ .Source }}' # Temporarily generate the kube_config for the cluster + direction: upstream + resources: + - kubernetes:kube_config + unique: true diff --git a/pkg/templates/aws/resources/eks_cluster.yaml b/pkg/templates/aws/resources/eks_cluster.yaml index faa958063..227e4f55f 100644 --- a/pkg/templates/aws/resources/eks_cluster.yaml +++ b/pkg/templates/aws/resources/eks_cluster.yaml @@ -39,16 +39,6 @@ properties: - aws:security_group unique: true description: Lists the security groups associated with the EKS cluster nodes - KubeConfig: - type: resource(kubernetes:kube_config) - operational_rule: - step: - direction: upstream - resources: - - kubernetes:kube_config - unique: true - description: Points to a Kubernetes kubeconfig file containing cluster access - information Name: type: string configuration_disabled: true