Skip to content

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

Merged

Conversation

Vandita2020
Copy link
Member

@Vandita2020 Vandita2020 commented Jun 2, 2023

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 added EventInvokeConfig as an inline property to alias. Thus the user can directly set configurations for async invocation (EventInvokeConfig) while creating alias. The user can edit the following code to create eventInvokeConfig along with alias.

apiVersion: lambda.services.k8s.aws/v1alpha1
kind: Alias
metadata:
  name: $ALIAS_NAME
  annotations:
    services.k8s.aws/region: $AWS_REGION
spec:
  name: $ALIAS_NAME
  functionName: $FUNCTION_NAME
  functionVersion: $FUNCTION_VERSION
  functionEventInvokeConfig:
    destinationConfig:
      onSuccess:
        destination: $ON_SUCCESS_DESTINATION
      onFailure:
        destination: $ON_FAILURE_DESTINATION
    maximumEventAgeInSeconds: $MAXIMUM_EVENT_AGE_IN_SECONDS
    maximumRetryAttempts: $MAXIMUM_RETRY_ATTEMPTS
  description: alias created by ACK lambda-controller e2e tests

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.

@ack-prow
Copy link

ack-prow bot commented Jun 2, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 2, 2023
@ack-prow ack-prow bot requested review from RedbackThomson and vijtrip2 June 2, 2023 21:12
@Vandita2020 Vandita2020 changed the title Adding EventInvokeConfig support for Alias Adding EventInvokeConfig support for Alias Jun 2, 2023
@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch 21 times, most recently from b5c1f7c to 46e818e Compare June 11, 2023 21:37
@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch 4 times, most recently from c9064be to cc965c1 Compare June 13, 2023 21:00
@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch from cc965c1 to f4d89df Compare June 13, 2023 22:37
@Vandita2020 Vandita2020 marked this pull request as ready for review June 13, 2023 23:17
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 13, 2023
@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch from f4d89df to 2b95175 Compare June 13, 2023 23:56
@a-hilaly
Copy link
Member

/retest

Comment on lines 19 to 21
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svcsdk "github.com/aws/aws-sdk-go/service/lambda"
)

func (rm *resourceManager) customCreate(
Copy link
Member

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

Copy link
Member

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?

@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch 3 times, most recently from a2a8169 to fe01416 Compare June 19, 2023 16:53
Copy link
Member

@a-hilaly a-hilaly left a 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)
Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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)
Copy link
Member

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

Copy link
Member Author

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"`
Copy link
Member

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

Copy link
Member Author

@Vandita2020 Vandita2020 Jun 20, 2023

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(
Copy link
Member

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)

Copy link
Member Author

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.

@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch 2 times, most recently from 65b22fc to f6e5f5c Compare June 20, 2023 22:08
Comment on lines 301 to 311
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 {
Copy link
Member

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?

Copy link
Member Author

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.

@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch 2 times, most recently from 5b8acd1 to dfc1fa0 Compare June 28, 2023 21:59
Copy link
Member

@a-hilaly a-hilaly left a 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

}
}
_, err = rm.sdkapi.PutFunctionEventInvokeConfigWithContext(ctx, input)
rm.metrics.RecordAPICall("SYNC", "SyncEventInvokeConfig", err)
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Vandita2020 Vandita2020 force-pushed the event_invoke_config_alias branch from dfc1fa0 to d9d99a2 Compare June 28, 2023 23:02
Copy link
Member

@a-hilaly a-hilaly left a 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!

@ack-prow ack-prow bot added the approved label Jun 29, 2023
@a-hilaly
Copy link
Member

/cc @RedbackThomson
/cc @jljaco

Copy link
Contributor

@RedbackThomson RedbackThomson left a 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:
Copy link
Contributor

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!

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 29, 2023
@ack-prow
Copy link

ack-prow bot commented Jun 29, 2023

[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:
  • OWNERS [A-Hilaly,RedbackThomson]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot merged commit f18794e into aws-controllers-k8s:main Jun 29, 2023
ack-prow bot pushed a commit that referenced this pull request Aug 23, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants