-
Notifications
You must be signed in to change notification settings - Fork 23
Adding EventInvokeConfig
support for Alias
#93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding EventInvokeConfig
support for Alias
#93
Conversation
Skipping CI for Draft Pull Request. |
EventInvokeConfig
support for AliasEventInvokeConfig
support for Alias
b5c1f7c
to
46e818e
Compare
c9064be
to
cc965c1
Compare
cc965c1
to
f4d89df
Compare
f4d89df
to
2b95175
Compare
/retest |
pkg/resource/alias/hooks.go
Outdated
svcapitypes "github.com/aws-controllers-k8s/lambda-controller/apis/v1alpha1" | ||
// svcresource "github.com/aws-controllers-k8s/lambda-controller/pkg/resource" | ||
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
"github.com/aws/aws-sdk-go/aws" | ||
svcsdk "github.com/aws/aws-sdk-go/service/lambda" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reorder https://github.com/golang/go/wiki/CodeReviewComments#imports
pkg/resource/alias/hooks.go
Outdated
svcsdk "github.com/aws/aws-sdk-go/service/lambda" | ||
) | ||
|
||
func (rm *resourceManager) customCreate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name this function customCreateEventInvokeConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also customCreate
and update...
are calling the same API PutFunctionEventInvokeConfigWithContext
can't we just use one function for both?
a2a8169
to
fe01416
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Very close!
@@ -0,0 +1 @@ | |||
rm.customUpdateEventInvokeConfig(ctx,desired,delta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a user only modified to EventInvokeConfig
? We should avoid calling an update for the other fields. And vice versa, if a user only modifies the description for example, we need to avoid calling customUpdateEventInvokeConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also error handling is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Have added the error handling part and inserted an if condition that will execute only when there's difference in state for EventInvokeConfig.
@@ -0,0 +1,3 @@ | |||
if ko.Spec.FunctionEventInvokeConfig != nil { | |||
rm.customCreateEventInvokeConfig(ctx,desired) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same error handling is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -26,7 +26,8 @@ import ( | |||
type AliasSpec struct { | |||
|
|||
// A description of the alias. | |||
Description *string `json:"description,omitempty"` | |||
Description *string `json:"description,omitempty"` | |||
FunctionEventInvokeConfig *PutFunctionEventInvokeConfigInput `json:"functionEventInvokeConfig,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we have a new code-generator feature that allows you to set some documentation for custom fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added documentation for FunctionEventInvokeConfig
for both function
and alias
in documentation.yaml
file
return input, nil | ||
} | ||
|
||
func (rm *resourceManager) syncEventInvokeConfig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customCreateEventInvokeConfig
and customUpdateEventInvokeConfig
are very similar, we could just use syncEventInvokeConfig
in both sdkCreate
and sdkUpdate
(for update you'll have to handle the delta differences in the hook)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created one single function syncEventInvokeConfig
for update and create part.
65b22fc
to
f6e5f5c
Compare
pkg/resource/alias/sdk.go
Outdated
if delta.DifferentAt("Spec.FunctionEventInvokeConfig") { | ||
_, err = rm.syncEventInvokeConfig(ctx, desired) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
input, err := rm.newUpdateRequestPayload(ctx, desired, delta) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the if delta.DifferentAt
gets exectued the code starting from line 307 will get executed as well (even if user only changed FunctionEventInvokeConfig
. How can you prevent that from happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have added !delta.DifferentExcept("Spec.FunctionEventInvokeConfig")
condition in sdkUpdate
to prevent execution of rest of the update part, when only EventInvokeConfig
fields are changed.
5b8acd1
to
dfc1fa0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I have more comment. Let's merge this right after it's fixed
pkg/resource/alias/hooks.go
Outdated
} | ||
} | ||
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input) | ||
rm.metrics.RecordAPICall("SYNC", "SyncEventInvokeConfig", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an UPDATE
record
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
dfc1fa0
to
d9d99a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on this!
/cc @RedbackThomson |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
@@ -0,0 +1,41 @@ | |||
resources: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent attention to detail!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, RedbackThomson, Vandita2020 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Issue #, if available: Related PR: #92 #93 **Summary** Fixing deletion part for `EventInvokeConfig` field. **Description:** This PR is related to bug fixes in [previous PR](#97) related to `EventInvokeConfig` implementation. When the user deleted the set configurations for Function/Alias resource, the configurations were not deleted from the Console side, instead it used to throw an error. Fixed the bug by introducing a new condition to check if the desired configurations are nil or not, if yes then call the delete API. Example of changes for `EventInvokeConfig` in Alias resource is given below: ``` if r.ko.Spec.FunctionEventInvokeConfig == nil { input_delete := &svcsdk.DeleteFunctionEventInvokeConfigInput{ FunctionName: aws.String(*r.ko.Spec.FunctionName), Qualifier: aws.String(*r.ko.Spec.Name), } _, err = rm.sdkapi.DeleteFunctionEventInvokeConfigWithContext(ctx, input_delete) rm.metrics.RecordAPICall("DELETE", "DeleteFunctionEventInvokeConfig", err) if err != nil { return nil, err } return r, nil } ``` This PR contains implementation code and E2E test to validate the changes. **Acknowledgment** By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issue #, if available:
Summary
Adding support to configure EventInvokeConfig for alias in ACK.
Description
This PR adds support for
EventInvokeConfig
permitted by Lambda API operations in ACK. To implement this functionality I addedEventInvokeConfig
as an inline property toalias
. Thus the user can directly set configurations for async invocation (EventInvokeConfig) while creating alias. The user can edit the following code to createeventInvokeConfig
along withalias
.This PR includes both implementation code and e2e tests.
Acknowledgement
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.