Skip to content

Source image error handling #98

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/resource/function/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package function
import (
"context"
"errors"
"strings"
"time"

ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
Expand All @@ -29,15 +30,20 @@ import (
)

var (
ErrFunctionPending = errors.New("Function in 'Pending' state, cannot be modified or deleted")
ErrCannotSetFunctionCSC = errors.New("cannot set function code signing config when package type is Image")
ErrFunctionPending = errors.New("function in 'Pending' state, cannot be modified or deleted")
ErrSourceImageDoesNotExist = errors.New("source image does not exist")
ErrCannotSetFunctionCSC = errors.New("cannot set function code signing config when package type is Image")
)

var (
requeueWaitWhilePending = ackrequeue.NeededAfter(
ErrFunctionPending,
5*time.Second,
)
requeueWaitWhileSourceImageDoesNotExist = ackrequeue.NeededAfter(
ErrSourceImageDoesNotExist,
1*time.Minute,
)
)

// isFunctionPending returns true if the supplied Lambda Function is in a pending
Expand Down Expand Up @@ -105,7 +111,15 @@ func (rm *resourceManager) customUpdateFunction(
case delta.DifferentAt("Spec.Code"):
err = rm.updateFunctionCode(ctx, desired, delta)
if err != nil {
return nil, err
// If the source image is not available, we get an error like this:
// "InvalidParameterValueException: Source image 1234567890.dkr.ecr.us-east-2.amazonaws.com/my-lambda:my-tag does not exist. Provide a valid source image."
// Because this may be recoverable (i.e. the image may be pushed once a build completes),
// we requeue the function for reconciliation after one minute.
if strings.Contains(err.Error(), "Provide a valid source image.") {
return nil, requeueWaitWhileSourceImageDoesNotExist
} else {
return nil, err
}
}
case delta.DifferentExcept(
"Spec.Code",
Expand Down