Skip to content

Adding support for Function version #113

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
merged 9 commits into from
Jan 10, 2024

Conversation

Vandita2020
Copy link
Member

@Vandita2020 Vandita2020 commented Oct 12, 2023

Summary:
Adding support to publish Version for a Function.

Description:
This PR adds implementation of AWS Lambda’s Function Version feature in the ACK. Function versions allow developers to publish new versions of their Lambda functions while maintaining older versions for backward compatibility or testing purposes. This will allow developers to publish new versions of their lambda functions and manage function updates seamlessly using ACK.

Version resource for a Function can be created using following manifest:

apiVersion: lambda.services.k8s.aws/v1alpha1
kind: Version
metadata:
  name: $VERSION_NAME
  annotations:
    services.k8s.aws/region: $AWS_REGION
spec:
  functionName: $FUNCTION_NAME
  codeSHA256: $HASH
  revisionID: $REVISION_ID
  description: version created by ACK lambda-controller e2e tests

The PR supports creation and deletion of Version resource. It also includes E2E tests to verify the functionality.

Acknowledgment:
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 Oct 12, 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 Oct 12, 2023
@ack-prow ack-prow bot requested review from jljaco and RedbackThomson October 12, 2023 22:56
@ack-prow ack-prow bot added the approved label Oct 12, 2023
@Vandita2020 Vandita2020 force-pushed the functionVersion branch 2 times, most recently from 06873ce to e6c9b38 Compare October 19, 2023 23:36
@Vandita2020 Vandita2020 marked this pull request as ready for review October 23, 2023 20:26
@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 Oct 23, 2023
@ack-prow ack-prow bot requested review from a-hilaly and vijtrip2 October 23, 2023 20:26
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.

Since we already have a LayerVersion resource, and to avoid UX confusions, should we name this resource FunctionVersion instead?

@valerena
Copy link
Member

Since we already have a LayerVersion resource, and to avoid UX confusions, should we name this resource FunctionVersion instead?

It's a good call, but the resource is called just Version in other places, like the API is just called PublishVersion, and there's an AWS::Lambda::Version resource in CFN and a Version construct in CDK.

I don't know what would create more confusion really

generator.yaml Outdated
@@ -7,11 +7,28 @@ ignore:
# FunctionUrlConfig
# LayerVersion
operations:
PublishLayerVersion:
PublishLayerVersion: #opID
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment needed or relevant? (can we remove it?)

Copy link
Member Author

Choose a reason for hiding this comment

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

My mistake, have removed it now. Thanks!

if err != nil {
return nil, err
}
bigList := list.Versions
Copy link
Member

Choose a reason for hiding this comment

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

Maybe bigList should be called something more specific, like versionsList or previousVersions (Or something that makes more sense, for when it's used in the sdk_create_pre_set_output.go.tpl file)

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, I went with versionList. We're getting list of Versions for LayerVersion resource and assigned it to variable named versionList only, made sense to use the same naming for this case too. Let me know if we should keep the naming different.

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.

Ty @Vandita2020 - left two comments inline.

Comment on lines 441 to 457
res := &svcsdk.ListVersionsByFunctionInput{}
res.FunctionName = desired.ko.Spec.FunctionName
var list *svcsdk.ListVersionsByFunctionOutput
list, err = rm.sdkapi.ListVersionsByFunctionWithContext(ctx, res)
if err != nil {
return nil, err
}
versionList := list.Versions

for ok := list.NextMarker != nil; ok; ok = (list.NextMarker != nil) {
res.Marker = list.NextMarker
list, err = rm.sdkapi.ListVersionsByFunctionWithContext(ctx, res)
if err != nil {
return nil, err
}
versionList = append(versionList, list.Versions...)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
res := &svcsdk.ListVersionsByFunctionInput{}
res.FunctionName = desired.ko.Spec.FunctionName
var list *svcsdk.ListVersionsByFunctionOutput
list, err = rm.sdkapi.ListVersionsByFunctionWithContext(ctx, res)
if err != nil {
return nil, err
}
versionList := list.Versions
for ok := list.NextMarker != nil; ok; ok = (list.NextMarker != nil) {
res.Marker = list.NextMarker
list, err = rm.sdkapi.ListVersionsByFunctionWithContext(ctx, res)
if err != nil {
return nil, err
}
versionList = append(versionList, list.Versions...)
}
marker := nil
versionsList := []svcsdk.Version
for {
listVersionsInput := &svcsdk.ListVersionsByFunctionInput{
FunctionName: desired.ko.Spec.FunctionName,
Marker: marker
}
listVersionResponse, err := rm.sdkapi.ListVersionsByFunctionWithContext(ctx, listVersionsInput)
if err != nil {
return nil, err
}
versionsList = append(versionLists, listVersionResponse.Versions...)
if listVersionResponse.NextMarker == nil {
break
}
marker = listVersionResponse.NextMarker
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Made the suggested changes. Thanks!

services.k8s.aws/region: $AWS_REGION
spec:
functionName: $FUNCTION_NAME
codeSHA256: $HASH
Copy link
Member

Choose a reason for hiding this comment

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

How is the $HASH set

Copy link
Member Author

Choose a reason for hiding this comment

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

codeSHA256 and RevisionId fields are optional and are used to check whether the Version is published only when there is some change in the code or its configuration. I have added new E2E test to verify the code by setting $HASH to publish the Version.

@Vandita2020
Copy link
Member Author

/test all

Copy link
Member

Choose a reason for hiding this comment

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

Can we name this file function_version.yaml , to keep the same style used for the files in the same directory?

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is similar to version_with_check.yaml file, so I deleted it. Don't remember how it got here.

# Check function version doesn't exist
assert not lambda_validator.version_exists(lambda_function_name, version_number)

def test_version_with_check(self, lambda_client, lambda_function):
Copy link
Member

Choose a reason for hiding this comment

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

What does check here means?

Copy link
Member Author

Choose a reason for hiding this comment

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

To check that the version we created above got deleted. We call getFunction API and pass the Version number along with Function name as we are only deleting a version and not the whole function.

Comment on lines +73 to +79
Architectures []*string `json:"architectures,omitempty"`
// The size of the function's deployment package, in bytes.
// +kubebuilder:validation:Optional
CodeSize *int64 `json:"codeSize,omitempty"`
// The function's dead letter queue.
// +kubebuilder:validation:Optional
DeadLetterConfig *DeadLetterConfig `json:"deadLetterConfig,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Most of the fields in here are not really relevant to a function, should we get rid of them?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're using PublishVersion API to set the status and its response has all these fields. So we cannot do anything with the extra fields.

@a-hilaly
Copy link
Member

/test all

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.

Thank you very much for your contribution @Vandita2020 ! rock on!
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2024
Copy link

ack-prow bot commented Jan 10, 2024

[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:
  • OWNERS [Vandita2020,a-hilaly]

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 4a72b7b into aws-controllers-k8s:main Jan 10, 2024
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