Skip to content

Commit

Permalink
fix(function): Fix wrong logic checking ECR image
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schroeder <[email protected]>
  • Loading branch information
schroeder-paul committed Nov 22, 2022
1 parent 095bdea commit 984d15e
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 68 deletions.
4 changes: 2 additions & 2 deletions package/crds/s3.aws.crossplane.io_buckets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ spec:
bucket will be created. It is a required field. Due to AWS API
limitations lacking on a proper response, when this field is
set to a wrong value, or to non-existent region on bucket creation,
it's impossible forwarding a meaning status message to the user
about the problem, producing some errors related to dial
it's impossible forwarding a meaningful status message to the
user about the problem, producing connection errors instead.
type: string
loggingConfiguration:
description: Specifies logging parameters for an Amazon S3 bucket.
Expand Down
70 changes: 17 additions & 53 deletions pkg/controller/lambda/function/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const (

// used in creation
packageTypeImage = string(svcapitypes.PackageType_Image)
// packageTypeZip = string(svcapitypes.PackageType_Zip)
packageTypeZip = string(svcapitypes.PackageType_Zip)

// used in observation
repositoryTypeECR = "ECR"
// repositoryTypeS3 = "S3"
repositoryTypeS3 = "S3"
)

// SetupFunction adds a controller that reconciles Function.
Expand Down Expand Up @@ -224,41 +224,25 @@ func isUpToDateEnvironment(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutp
return cmp.Equal(envVars, awsVars, sortCmp, cmpopts.EquateEmpty())
}

func actualRepositoryType(obj *svcsdk.GetFunctionOutput) *string {
if obj.Code == nil {
return nil
}
return obj.Code.RepositoryType
}

func actualPackageType(obj *svcsdk.GetFunctionOutput) *string {
func equalPackageType(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput) bool {
if obj.Configuration == nil {
return nil
return false
}
return obj.Configuration.PackageType
}

func desiredPackageType(cr *svcapitypes.Function) *string {
return cr.Spec.ForProvider.PackageType
return aws.StringValue(cr.Spec.ForProvider.PackageType) == aws.StringValue(obj.Configuration.PackageType)
}

func desiredImageURI(cr *svcapitypes.Function) *string {
return cr.Spec.ForProvider.CustomFunctionCodeParameters.ImageURI
}

func actualImageURI(obj *svcsdk.GetFunctionOutput) *string {
func isRepositoryType(obj *svcsdk.GetFunctionOutput, repositoryType string) bool {
if obj.Code == nil {
return nil
return false
}
return obj.Code.ImageUri
}

func bothPackageTypesNil(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput) bool {
return desiredPackageType(cr) == nil && actualPackageType(obj) == nil
return aws.StringValue(obj.Code.RepositoryType) == repositoryType
}

func bothImageURI(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput) bool {
return desiredImageURI(cr) == nil && actualImageURI(obj) == nil
func equalImageURI(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput) bool {
if obj.Code == nil {
return false
}
return aws.StringValue(cr.Spec.ForProvider.CustomFunctionCodeParameters.ImageURI) == aws.StringValue(obj.Code.ImageUri)
}

// isUpToDateCodeImage checks if FunctionConfiguration FunctionCodeLocation (Image) is up-to-date
Expand All @@ -267,36 +251,16 @@ func isUpToDateCodeImage(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput
desired := cr
actual := obj

if *desiredPackageType(desired) != packageTypeImage {
// code is not supplied via container image
if aws.StringValue(desired.Spec.ForProvider.PackageType) == packageTypeZip {
return true
}

if bothPackageTypesNil(desired, actual) {
return true
}

if actualPackageType(actual) == nil {
return false
}
if *desiredPackageType(desired) != *actualPackageType(actual) {
return false
}

if actualRepositoryType(actual) == nil {
return false
}
if *actualRepositoryType(actual) != repositoryTypeECR {
if !equalPackageType(desired, actual) {
return false
}

if bothImageURI(desired, actual) {
return true
}
if actualImageURI(actual) == nil {
if !isRepositoryType(actual, repositoryTypeECR) {
return false
}
return *desiredImageURI(desired) != *actualImageURI(actual)
return equalImageURI(desired, actual)
}

func isUpToDateFileSystemConfigs(cr *svcapitypes.Function, obj *svcsdk.GetFunctionOutput) bool {
Expand Down
Loading

0 comments on commit 984d15e

Please sign in to comment.