Skip to content

Commit

Permalink
Add some more goldenfile tests (#614)
Browse files Browse the repository at this point in the history
* Add more golden file tests - patch 1

Signed-off-by: Mustafa Abdelrahman <[email protected]>

* remove `resourcesType` field which is unnecessary

Signed-off-by: Mustafa Abdelrahman <[email protected]>

* Fix existing Golden file tests

Signed-off-by: Lucas Thiesen <[email protected]>

* Fix remaining goldenfile tests

Signed-off-by: Lucas Thiesen <[email protected]>

* Fix ingress sharing parameter in test fixtures

Signed-off-by: Lucas Thiesen <[email protected]>

* Add ability to check multiple input/output to golden files tests

Signed-off-by: Lucas Thiesen <[email protected]>

* Sync annotation and improve naming in golden file tests

Signed-off-by: Lucas Thiesen <[email protected]>

* Add issue link to TODO comment in CF mocks

Signed-off-by: Lucas Thiesen <[email protected]>

* Fix identation

Signed-off-by: Lucas Thiesen <[email protected]>

---------

Signed-off-by: Mustafa Abdelrahman <[email protected]>
Signed-off-by: Lucas Thiesen <[email protected]>
Co-authored-by: Lucas Thiesen <[email protected]>
  • Loading branch information
MustafaSaber and lucastt authored Oct 31, 2023
1 parent 152d27c commit dd95fc2
Show file tree
Hide file tree
Showing 36 changed files with 2,157 additions and 53 deletions.
38 changes: 22 additions & 16 deletions aws/fake/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ type CFOutputs struct {

type CFClient struct {
cloudformationiface.CloudFormationAPI
lastStackTemplate string
lastStackParams []*cloudformation.Parameter
lastStackTags []*cloudformation.Tag
Outputs CFOutputs
templateCreationHistory []string
paramCreationHistory [][]*cloudformation.Parameter
tagCreationHistory [][]*cloudformation.Tag
Outputs CFOutputs
}

func (m *CFClient) GetLastStackTemplate() string {
return m.lastStackTemplate
func (m *CFClient) GetTemplateCreationHistory() []string {
return m.templateCreationHistory
}

func (m *CFClient) GetLastStackParams() []*cloudformation.Parameter {
return m.lastStackParams
func (m *CFClient) GetParamCreationHistory() [][]*cloudformation.Parameter {
return m.paramCreationHistory
}

func (m *CFClient) GetLastStackTags() []*cloudformation.Tag {
return m.lastStackTags
func (m *CFClient) GetTagCreationHistory() [][]*cloudformation.Tag {
return m.tagCreationHistory
}

func (m *CFClient) CleanCreationHistory() {
m.paramCreationHistory = [][]*cloudformation.Parameter{}
m.tagCreationHistory = [][]*cloudformation.Tag{}
m.templateCreationHistory = []string{}
}

func (m *CFClient) DescribeStacksPages(in *cloudformation.DescribeStacksInput, fn func(*cloudformation.DescribeStacksOutput, bool) bool) (err error) {
Expand Down Expand Up @@ -62,9 +68,9 @@ func (m *CFClient) DescribeStacks(in *cloudformation.DescribeStacksInput) (*clou
}

func (m *CFClient) CreateStack(params *cloudformation.CreateStackInput) (*cloudformation.CreateStackOutput, error) {
m.lastStackTags = params.Tags
m.lastStackParams = params.Parameters
m.lastStackTemplate = *params.TemplateBody
m.tagCreationHistory = append(m.tagCreationHistory, params.Tags)
m.paramCreationHistory = append(m.paramCreationHistory, params.Parameters)
m.templateCreationHistory = append(m.templateCreationHistory, *params.TemplateBody)

out, ok := m.Outputs.CreateStack.response.(*cloudformation.CreateStackOutput)
if !ok {
Expand All @@ -80,9 +86,9 @@ func MockCSOutput(stackId string) *cloudformation.CreateStackOutput {
}

func (m *CFClient) UpdateStack(params *cloudformation.UpdateStackInput) (*cloudformation.UpdateStackOutput, error) {
m.lastStackTags = params.Tags
m.lastStackParams = params.Parameters
m.lastStackTemplate = *params.TemplateBody
// TODO: https://github.com/zalando-incubator/kube-ingress-aws-controller/issues/653
// Update stack needs to use different variable to register change history,
// so createStack and updateStack mocks don't mess with each other states.

out, ok := m.Outputs.UpdateStack.response.(*cloudformation.UpdateStackOutput)
if !ok {
Expand Down
18 changes: 18 additions & 0 deletions testdata/ing_shared_rg_notshared_alb/input/k8s/01-ing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myingress
annotations:
zalando.org/aws-load-balancer-shared: "true"
spec:
rules:
- host: foo.bar.org
http:
paths:
- backend:
service:
name: foo-bar-service
port:
name: main-port
path: /
pathType: ImplementationSpecific
18 changes: 18 additions & 0 deletions testdata/ing_shared_rg_notshared_alb/input/k8s/02-rg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: zalando.org/v1
kind: RouteGroup
metadata:
name: my-route-group
annotations:
zalando.org/aws-load-balancer-shared: "false"
spec:
hosts:
- foo.bar.org
backends:
- name: my-backend
type: service
serviceName: my-service
servicePort: 80
routes:
- pathSubtree: /
backends:
- backendName: my-backend
File renamed without changes.
54 changes: 54 additions & 0 deletions testdata/ing_shared_rg_notshared_alb/output/params/02-rg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"parameterKey": "LoadBalancerSchemeParameter",
"parameterValue": "internet-facing"
},
{
"parameterKey": "LoadBalancerSecurityGroupParameter",
"parameterValue": "42"
},
{
"parameterKey": "LoadBalancerSubnetsParameter",
"parameterValue": "foo1"
},
{
"parameterKey": "TargetGroupVPCIDParameter",
"parameterValue": "1"
},
{
"parameterKey": "TargetGroupTargetPortParameter",
"parameterValue": "0"
},
{
"parameterKey": "ListenerSslPolicyParameter",
"parameterValue": "ELBSecurityPolicy-2016-08"
},
{
"parameterKey": "IpAddressType",
"parameterValue": "ipv4"
},
{
"parameterKey": "Type",
"parameterValue": "application"
},
{
"parameterKey": "HTTP2",
"parameterValue": "true"
},
{
"parameterKey": "TargetGroupHealthCheckPathParameter",
"parameterValue": ""
},
{
"parameterKey": "TargetGroupHealthCheckPortParameter",
"parameterValue": "0"
},
{
"parameterKey": "TargetGroupHealthCheckIntervalParameter",
"parameterValue": "0"
},
{
"parameterKey": "TargetGroupHealthCheckTimeoutParameter",
"parameterValue": "0"
}
]
File renamed without changes.
15 changes: 15 additions & 0 deletions testdata/ing_shared_rg_notshared_alb/output/tags/02-rg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"key": "kubernetes:application",
"value": ""
},{
"key": "kubernetes.io/cluster/aws:123:eu-central-1:kube-1",
"value": "owned"
},{
"key": "ingress:certificate-arn/DUMMY",
"value": "0001-01-01T00:00:00Z"
},{
"key": "ingress:owner",
"value": "/my-route-group"
}
]
File renamed without changes.
219 changes: 219 additions & 0 deletions testdata/ing_shared_rg_notshared_alb/output/templates/02-rg.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Load Balancer for Kubernetes Ingress",
"Parameters": {
"HTTP2": {
"Type": "String",
"Default": "true",
"Description": "H2 Enabled"
},
"IpAddressType": {
"Type": "String",
"Default": "ipv4",
"Description": "IP Address Type, 'ipv4' or 'dualstack'"
},
"ListenerSslPolicyParameter": {
"Type": "String",
"Default": "ELBSecurityPolicy-2016-08",
"Description": "The HTTPS SSL Security Policy Name"
},
"LoadBalancerSchemeParameter": {
"Type": "String",
"Default": "internet-facing",
"Description": "The Load Balancer scheme - 'internal' or 'internet-facing'"
},
"LoadBalancerSecurityGroupParameter": {
"Type": "List\u003cAWS::EC2::SecurityGroup::Id\u003e",
"Description": "The security group ID for the Load Balancer"
},
"LoadBalancerSubnetsParameter": {
"Type": "List\u003cAWS::EC2::Subnet::Id\u003e",
"Description": "The list of subnets IDs for the Load Balancer"
},
"TargetGroupHealthCheckIntervalParameter": {
"Type": "Number",
"Default": "10",
"Description": "The healthcheck interval"
},
"TargetGroupHealthCheckPathParameter": {
"Type": "String",
"Default": "/kube-system/healthz",
"Description": "The healthcheck path"
},
"TargetGroupHealthCheckPortParameter": {
"Type": "Number",
"Default": "9999",
"Description": "The healthcheck port"
},
"TargetGroupHealthCheckTimeoutParameter": {
"Type": "Number",
"Default": "5",
"Description": "The healthcheck timeout"
},
"TargetGroupTargetPortParameter": {
"Type": "Number",
"Default": "9999",
"Description": "The target port"
},
"TargetGroupVPCIDParameter": {
"Type": "AWS::EC2::VPC::Id",
"Description": "The VPCID for the TargetGroup"
},
"Type": {
"Type": "String",
"Default": "application",
"Description": "Loadbalancer Type, 'application' or 'network'"
}
},
"Resources": {
"HTTPListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"DefaultActions": [
{
"TargetGroupArn": {
"Ref": "TG"
},
"Type": "forward"
}
],
"LoadBalancerArn": {
"Ref": "LB"
},
"Port": 80,
"Protocol": "HTTP"
}
},
"HTTPSListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"Certificates": [
{
"CertificateArn": "DUMMY"
}
],
"DefaultActions": [
{
"TargetGroupArn": {
"Ref": "TG"
},
"Type": "forward"
}
],
"LoadBalancerArn": {
"Ref": "LB"
},
"Port": 443,
"Protocol": "HTTPS",
"SslPolicy": {
"Ref": "ListenerSslPolicyParameter"
}
}
},
"HTTPSListenerCertificatefc48082457b770e278fc0bd3d392d127869993166f76e8df57d19a0e662820ea": {
"Type": "AWS::ElasticLoadBalancingV2::ListenerCertificate",
"Properties": {
"Certificates": [
{
"CertificateArn": "DUMMY"
}
],
"ListenerArn": {
"Ref": "HTTPSListener"
}
}
},
"LB": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"IpAddressType": {
"Ref": "IpAddressType"
},
"LoadBalancerAttributes": [
{
"Key": "idle_timeout.timeout_seconds",
"Value": "0"
},
{
"Key": "routing.http2.enabled",
"Value": "true"
},
{
"Key": "access_logs.s3.enabled",
"Value": "false"
}
],
"Scheme": {
"Ref": "LoadBalancerSchemeParameter"
},
"SecurityGroups": {
"Ref": "LoadBalancerSecurityGroupParameter"
},
"Subnets": {
"Ref": "LoadBalancerSubnetsParameter"
},
"Tags": [
{
"Key": "StackName",
"Value": {
"Ref": "AWS::StackName"
}
}
],
"Type": {
"Ref": "Type"
}
}
},
"TG": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"HealthCheckIntervalSeconds": {
"Ref": "TargetGroupHealthCheckIntervalParameter"
},
"HealthCheckPath": {
"Ref": "TargetGroupHealthCheckPathParameter"
},
"HealthCheckPort": {
"Ref": "TargetGroupHealthCheckPortParameter"
},
"HealthCheckProtocol": "HTTP",
"HealthCheckTimeoutSeconds": {
"Ref": "TargetGroupHealthCheckTimeoutParameter"
},
"HealthyThresholdCount": 0,
"Port": {
"Ref": "TargetGroupTargetPortParameter"
},
"Protocol": "HTTP",
"TargetGroupAttributes": [
{
"Key": "deregistration_delay.timeout_seconds",
"Value": "0"
}
],
"UnhealthyThresholdCount": 0,
"VpcId": {
"Ref": "TargetGroupVPCIDParameter"
}
}
}
},
"Outputs": {
"LoadBalancerDNSName": {
"Description": "DNS name for the LoadBalancer",
"Value": {
"Fn::GetAtt": [
"LB",
"DNSName"
]
}
},
"TargetGroupARN": {
"Description": "The ARN of the TargetGroup",
"Value": {
"Ref": "TG"
}
}
}
}
File renamed without changes.
Loading

0 comments on commit dd95fc2

Please sign in to comment.