-
Notifications
You must be signed in to change notification settings - Fork 23
Adding ProvisionedConcurrency Support for Alias #97
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 ProvisionedConcurrency Support for Alias #97
Conversation
Skipping CI for Draft Pull Request. |
c596c26
to
02f3de0
Compare
/test all |
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.
Very good! Thank you @Vandita2020 !
I left few comments inline
pkg/resource/alias/hooks.go
Outdated
if desired.ko.Spec.ProvisionedConcurrencyConfig != nil { | ||
if desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions != nil { | ||
input.ProvisionedConcurrentExecutions = aws.Int64(*desired.ko.Spec.ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions) | ||
} else { | ||
input.ProvisionedConcurrentExecutions = aws.Int64(0) | ||
} | ||
} |
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 the user sets spec.provisionedConcurrencyConfig
to nil? we want to input.ProvisionedConcurrentExecutions = aws.Int64(0)
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.
I have added the else condition to assign ProvisionedConcurrency value to 0 if user doesn't pass any value.
pkg/resource/alias/hooks.go
Outdated
if err != nil { | ||
ko.Spec.ProvisionedConcurrencyConfig = nil | ||
} else { |
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.
We should return an error instead of ignore it
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 thing for L137 below
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 error is ignored intentionally, the error is returned by the API as there is no existing provisionedConcurrency
set for the alias, and when it checks the current value in the Console, it doesn't find the configuration, as they are yet not created. So we wanted to ignore that error and instead assign the variable to nil on ACK side before we create it. To make the delta function know that there is a difference in state.
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 reason for FunctionEventInvokeConfig
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.
In this case, can we ignore specifically NotFound
errors? i'm thinking about cases where API returns something different than resource doesn't exist
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.
Can you please share what is the exact error returned by the API?
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
@@ -44,7 +44,7 @@ def lambda_function(): | |||
replacements["BUCKET_NAME"] = resources.FunctionsBucket.name | |||
replacements["LAMBDA_ROLE"] = resources.EICRole.arn | |||
replacements["LAMBDA_FILE_NAME"] = LAMBDA_FUNCTION_FILE_ZIP | |||
replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "0" | |||
replacements["RESERVED_CONCURRENT_EXECUTIONS"] = "3" |
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.
Why is this needed?
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.
If we allocate both reserved concurrency and provisioned concurrency for the same function. Then, the amount of provisioned concurrency cannot exceed the amount of reserved concurrency.
assert deleted | ||
|
||
time.sleep(DELETE_WAIT_AFTER_SECONDS) | ||
|
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.
It would be nice to add another update to try to delete the provisionedConcurency
field and check if the controller sets it to 0
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.
The min value of provisionedConcurrentExecution
needs to be 1, as mentioned here in the provisionedConcurrencyConfigInput type
pkg/resource/alias/hooks.go
Outdated
@@ -78,6 +109,21 @@ func (rm *resourceManager) setResourceAdditionalFields( | |||
exit := rlog.Trace("rm.setResourceAdditionalFields") |
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.
setResourceAdditionalFields
is getting huge, can you make shorter by putting some of it's logic into different functions? for example
func (rm *resourceManager) setResourceAdditionalFields(...) error {
// ...
ko.Spec.ProvisionnedConcurencyConfig, err = rm.getProvisionedConcurencyConfig(...)
if err ! = nil {
return nil
}
ko.Spec.FunctionEventInvokeConfig, err = rm.getFunctionInvokeConfig(...)
if err ! = nil {
return nil
}
// etc....
}
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
@@ -63,7 +63,8 @@ type AliasSpec struct { | |||
FunctionVersion *string `json:"functionVersion"` | |||
// The name of the alias. | |||
// +kubebuilder:validation:Required | |||
Name *string `json:"name"` | |||
Name *string `json:"name"` | |||
ProvisionedConcurrencyConfig *PutProvisionedConcurrencyConfigInput `json:"provisionedConcurrencyConfig,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.
Can we inject some documentation here?
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
02f3de0
to
1814ecf
Compare
if err != nil { | ||
return nil | ||
} | ||
|
||
return 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.
👍
305ba44
to
e751f64
Compare
if !delta.DifferentExcept("Spec.ProvisionedConcurrencyConfig"){ | ||
return desired, 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.
I think this should be come if !delta.DifferentExcept("Spec.ProvisionedConcurrencyConfig", "Spec.FunctionEventInvokeConfig")
and L7-9 should be removed. Thoughts?
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.
Writing them together makes sense. We just need an if condition to check the changes if any before executing the rest of the Update function.
e751f64
to
d090b9e
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.
Great work on this @Vandita2020 ! 🚀
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: a-hilaly, 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: #97 **Summary** Fixing deletion part for `ProvisionedConcurrency` field. **Description:** This PR is related to bug fixes in [previous PR](#97) related to `ProvisionedConcurrency` implementation. When the user deleted the set configurations for 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 `ProvisionedConcurrency` in Alias resource is given below: ``` if desired.ko.Spec.ProvisionedConcurrencyConfig == nil { input_delete := &svcsdk.DeleteProvisionedConcurrencyConfigInput{ FunctionName: aws.String(*desired.ko.Spec.FunctionName), Qualifier: aws.String(*desired.ko.Spec.Name), } _, err = rm.sdkapi.DeleteProvisionedConcurrencyConfigWithContext(ctx, input_delete) rm.metrics.RecordAPICall("DELETE", "DeleteProvisionedConcurrency", err) if err != nil { return err } return 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: 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
ProvisionedConcurrency
for alias in ACK.Description
This PR adds support to configure
ProvisionedConcurrency
for Lambda function's alias using ACK. To implement this functionality I addedProvisionedConcurrencyConfig
as an inline property to alias resource. Thus the user can directly set configurations for Provisioned Concurrency while creating alias. The user can edit the following code to set Provisioned Concurrency along with alias.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.