Skip to content

Commit 4500a6c

Browse files
authored
Source image error handling (#98)
**Issue #, if available:** aws-controllers-k8s/community#1842 **Description of changes:** Requeues the function reconciliation if it errors due to an image not existing. It will attempt reconciliation again after 1 minute. This allows for handling common GitOps conditions that may occur, where the function manifest is updated to use a new image URI, but the image hasn't finished pushing yet. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f6ee249 commit 4500a6c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pkg/resource/function/hooks.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package function
1616
import (
1717
"context"
1818
"errors"
19+
"strings"
1920
"time"
2021

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

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

3638
var (
3739
requeueWaitWhilePending = ackrequeue.NeededAfter(
3840
ErrFunctionPending,
3941
5*time.Second,
4042
)
43+
requeueWaitWhileSourceImageDoesNotExist = ackrequeue.NeededAfter(
44+
ErrSourceImageDoesNotExist,
45+
1*time.Minute,
46+
)
4147
)
4248

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

0 commit comments

Comments
 (0)