Skip to content

Commit 2b41b1d

Browse files
authored
Support function reference in EventSourceMappingSQS resource (#57)
Issue #, if available: Description of changes: Adding functionality to the lambda controller to be able to reference a Function from a EventSourceMappingSQS resource using resource references. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0be4250 commit 2b41b1d

File tree

10 files changed

+260
-52
lines changed

10 files changed

+260
-52
lines changed

apis/v1alpha1/event_source_mapping.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ resources:
8080
UUID:
8181
is_primary_key: true
8282
FunctionName:
83+
references:
84+
resource: Function
85+
path: Spec.Name
8386
is_required: true
8487
FilterCriteria:
8588
compare:

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/lambda.services.k8s.aws_eventsourcemappings.yaml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
---
32
apiVersion: apiextensions.k8s.io/v1
43
kind: CustomResourceDefinition
54
metadata:
65
annotations:
7-
controller-gen.kubebuilder.io/version: v0.7.0
6+
controller-gen.kubebuilder.io/version: v0.9.2
87
creationTimestamp: null
98
name: eventsourcemappings.lambda.services.k8s.aws
109
spec:
@@ -42,13 +41,13 @@ spec:
4241
pulls from your stream or queue and sends to your function. Lambda
4342
passes all of the records in the batch to the function in a single
4443
call, up to the payload limit for synchronous invocation (6 MB).
45-
\n * Amazon Kinesis - Default 100. Max 10,000. \n * Amazon
46-
DynamoDB Streams - Default 100. Max 10,000. \n * Amazon Simple
47-
Queue Service - Default 10. For standard queues the max is 10,000.
48-
For FIFO queues the max is 10. \n * Amazon Managed Streaming
49-
for Apache Kafka - Default 100. Max 10,000. \n * Self-Managed
50-
Apache Kafka - Default 100. Max 10,000. \n * Amazon MQ (ActiveMQ
51-
and RabbitMQ) - Default 100. Max 10,000."
44+
\n * Amazon Kinesis - Default 100. Max 10,000. \n * Amazon DynamoDB
45+
Streams - Default 100. Max 10,000. \n * Amazon Simple Queue Service
46+
- Default 10. For standard queues the max is 10,000. For FIFO queues
47+
the max is 10. \n * Amazon Managed Streaming for Apache Kafka -
48+
Default 100. Max 10,000. \n * Self-Managed Apache Kafka - Default
49+
100. Max 10,000. \n * Amazon MQ (ActiveMQ and RabbitMQ) - Default
50+
100. Max 10,000."
5251
format: int64
5352
type: integer
5453
bisectBatchOnFunctionError:
@@ -78,10 +77,10 @@ spec:
7877
type: boolean
7978
eventSourceARN:
8079
description: "The Amazon Resource Name (ARN) of the event source.
81-
\n * Amazon Kinesis - The ARN of the data stream or a stream
82-
consumer. \n * Amazon DynamoDB Streams - The ARN of the stream.
83-
\n * Amazon Simple Queue Service - The ARN of the queue. \n *
84-
Amazon Managed Streaming for Apache Kafka - The ARN of the cluster."
80+
\n * Amazon Kinesis - The ARN of the data stream or a stream consumer.
81+
\n * Amazon DynamoDB Streams - The ARN of the stream. \n * Amazon
82+
Simple Queue Service - The ARN of the queue. \n * Amazon Managed
83+
Streaming for Apache Kafka - The ARN of the cluster."
8584
type: string
8685
filterCriteria:
8786
description: (Streams and Amazon SQS) An object that defines the filter
@@ -100,12 +99,25 @@ spec:
10099
type: object
101100
functionName:
102101
description: "The name of the Lambda function. \n Name formats \n
103-
\ * Function name - MyFunction. \n * Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.
104-
\n * Version or Alias ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.
105-
\n * Partial ARN - 123456789012:function:MyFunction. \n The length
102+
* Function name - MyFunction. \n * Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.
103+
\n * Version or Alias ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.
104+
\n * Partial ARN - 123456789012:function:MyFunction. \n The length
106105
constraint applies only to the full ARN. If you specify only the
107106
function name, it's limited to 64 characters in length."
108107
type: string
108+
functionRef:
109+
description: 'AWSResourceReferenceWrapper provides a wrapper around
110+
*AWSResourceReference type to provide more user friendly syntax
111+
for references using ''from'' field Ex: APIIDRef: from: name: my-api'
112+
properties:
113+
from:
114+
description: AWSResourceReference provides all the values necessary
115+
to reference another k8s resource for finding the identifier(Id/ARN/Name)
116+
properties:
117+
name:
118+
type: string
119+
type: object
120+
type: object
109121
functionResponseTypes:
110122
description: (Streams and Amazon SQS) A list of current response type
111123
enums applied to the event source mapping.
@@ -186,8 +198,6 @@ spec:
186198
window. The range is between 1 second up to 900 seconds.
187199
format: int64
188200
type: integer
189-
required:
190-
- functionName
191201
type: object
192202
status:
193203
description: EventSourceMappingStatus defines the observed state of EventSourceMapping
@@ -282,9 +292,3 @@ spec:
282292
storage: true
283293
subresources:
284294
status: {}
285-
status:
286-
acceptedNames:
287-
kind: ""
288-
plural: ""
289-
conditions: []
290-
storedVersions: []

generator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ resources:
8080
UUID:
8181
is_primary_key: true
8282
FunctionName:
83+
references:
84+
resource: Function
85+
path: Spec.Name
8386
is_required: true
8487
FilterCriteria:
8588
compare:

helm/crds/lambda.services.k8s.aws_eventsourcemappings.yaml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
---
32
apiVersion: apiextensions.k8s.io/v1
43
kind: CustomResourceDefinition
54
metadata:
65
annotations:
7-
controller-gen.kubebuilder.io/version: v0.7.0
6+
controller-gen.kubebuilder.io/version: v0.9.2
87
creationTimestamp: null
98
name: eventsourcemappings.lambda.services.k8s.aws
109
spec:
@@ -42,13 +41,13 @@ spec:
4241
pulls from your stream or queue and sends to your function. Lambda
4342
passes all of the records in the batch to the function in a single
4443
call, up to the payload limit for synchronous invocation (6 MB).
45-
\n * Amazon Kinesis - Default 100. Max 10,000. \n * Amazon
46-
DynamoDB Streams - Default 100. Max 10,000. \n * Amazon Simple
47-
Queue Service - Default 10. For standard queues the max is 10,000.
48-
For FIFO queues the max is 10. \n * Amazon Managed Streaming
49-
for Apache Kafka - Default 100. Max 10,000. \n * Self-Managed
50-
Apache Kafka - Default 100. Max 10,000. \n * Amazon MQ (ActiveMQ
51-
and RabbitMQ) - Default 100. Max 10,000."
44+
\n * Amazon Kinesis - Default 100. Max 10,000. \n * Amazon DynamoDB
45+
Streams - Default 100. Max 10,000. \n * Amazon Simple Queue Service
46+
- Default 10. For standard queues the max is 10,000. For FIFO queues
47+
the max is 10. \n * Amazon Managed Streaming for Apache Kafka -
48+
Default 100. Max 10,000. \n * Self-Managed Apache Kafka - Default
49+
100. Max 10,000. \n * Amazon MQ (ActiveMQ and RabbitMQ) - Default
50+
100. Max 10,000."
5251
format: int64
5352
type: integer
5453
bisectBatchOnFunctionError:
@@ -78,10 +77,10 @@ spec:
7877
type: boolean
7978
eventSourceARN:
8079
description: "The Amazon Resource Name (ARN) of the event source.
81-
\n * Amazon Kinesis - The ARN of the data stream or a stream
82-
consumer. \n * Amazon DynamoDB Streams - The ARN of the stream.
83-
\n * Amazon Simple Queue Service - The ARN of the queue. \n *
84-
Amazon Managed Streaming for Apache Kafka - The ARN of the cluster."
80+
\n * Amazon Kinesis - The ARN of the data stream or a stream consumer.
81+
\n * Amazon DynamoDB Streams - The ARN of the stream. \n * Amazon
82+
Simple Queue Service - The ARN of the queue. \n * Amazon Managed
83+
Streaming for Apache Kafka - The ARN of the cluster."
8584
type: string
8685
filterCriteria:
8786
description: (Streams and Amazon SQS) An object that defines the filter
@@ -100,12 +99,25 @@ spec:
10099
type: object
101100
functionName:
102101
description: "The name of the Lambda function. \n Name formats \n
103-
\ * Function name - MyFunction. \n * Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.
104-
\n * Version or Alias ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.
105-
\n * Partial ARN - 123456789012:function:MyFunction. \n The length
102+
* Function name - MyFunction. \n * Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.
103+
\n * Version or Alias ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.
104+
\n * Partial ARN - 123456789012:function:MyFunction. \n The length
106105
constraint applies only to the full ARN. If you specify only the
107106
function name, it's limited to 64 characters in length."
108107
type: string
108+
functionRef:
109+
description: 'AWSResourceReferenceWrapper provides a wrapper around
110+
*AWSResourceReference type to provide more user friendly syntax
111+
for references using ''from'' field Ex: APIIDRef: from: name: my-api'
112+
properties:
113+
from:
114+
description: AWSResourceReference provides all the values necessary
115+
to reference another k8s resource for finding the identifier(Id/ARN/Name)
116+
properties:
117+
name:
118+
type: string
119+
type: object
120+
type: object
109121
functionResponseTypes:
110122
description: (Streams and Amazon SQS) A list of current response type
111123
enums applied to the event source mapping.
@@ -186,8 +198,6 @@ spec:
186198
window. The range is between 1 second up to 900 seconds.
187199
format: int64
188200
type: integer
189-
required:
190-
- functionName
191201
type: object
192202
status:
193203
description: EventSourceMappingStatus defines the observed state of EventSourceMapping
@@ -282,9 +292,3 @@ spec:
282292
storage: true
283293
subresources:
284294
status: {}
285-
status:
286-
acceptedNames:
287-
kind: ""
288-
plural: ""
289-
conditions: []
290-
storedVersions: []

pkg/resource/event_source_mapping/delta.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/resource/event_source_mapping/references.go

Lines changed: 87 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: lambda.services.k8s.aws/v1alpha1
2+
kind: EventSourceMapping
3+
metadata:
4+
name: $EVENT_SOURCE_MAPPING_NAME
5+
annotations:
6+
services.k8s.aws/region: $AWS_REGION
7+
spec:
8+
functionRef:
9+
from:
10+
name: $FUNCTION_REF_NAME
11+
eventSourceARN: $EVENT_SOURCE_ARN
12+
batchSize: $BATCH_SIZE
13+
maximumBatchingWindowInSeconds: $MAXIMUM_BATCHING_WINDOW_IN_SECONDS
14+
enabled: false

0 commit comments

Comments
 (0)