Skip to content
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

Update reference resolution interface types #121

Merged
Merged
Show file tree
Hide file tree
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
33 changes: 28 additions & 5 deletions mocks/pkg/types/aws_resource_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions mocks/pkg/types/resolved_reference_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ var (
NotManagedReason = "This resource already exists but is not managed by ACK. " +
"To bring the resource under ACK management, you should explicitly adopt " +
"the resource by creating a services.k8s.aws/AdoptedResource"
UnknownSyncedMessage = "Unable to determine if desired resource state matches latest observed state"
NotSyncedMessage = "Resource not synced"
SyncedMessage = "Resource synced successfully"
UnknownSyncedMessage = "Unable to determine if desired resource state matches latest observed state"
NotSyncedMessage = "Resource not synced"
SyncedMessage = "Resource synced successfully"
FailedReferenceResolutionMessage = "Reference resolution failed"
)

// Synced returns the Condition in the resource's Conditions collection that is
Expand Down Expand Up @@ -235,23 +236,25 @@ func RemoveReferencesResolved(
}
}

// WithReferencesResolvedCondition sets the ConditionTypeReferencesResolved in
// AWSResource based on the err parameter and returns (AWSResource,error)
// WithReferencesResolvedCondition returns a new AWSResource with the
// ConditionTypeReferencesResolved set based on the err parameter
func WithReferencesResolvedCondition(
resource acktypes.AWSResource,
err error,
) (acktypes.AWSResource, error) {
) acktypes.AWSResource {
ko := resource.DeepCopy()

if err != nil {
errString := err.Error()
conditionStatus := corev1.ConditionUnknown
if strings.Contains(errString, ackerr.ResourceReferenceTerminal.Error()) {
conditionStatus = corev1.ConditionFalse
}
SetReferencesResolved(resource, conditionStatus, &errString, nil)
SetReferencesResolved(ko, conditionStatus, &FailedReferenceResolutionMessage, &errString)
} else {
SetReferencesResolved(resource, corev1.ConditionTrue, nil, nil)
SetReferencesResolved(ko, corev1.ConditionTrue, nil, nil)
}
return resource, err
return ko
}

// LateInitializationInProgress return true if ConditionTypeLateInitialized has "False" status
Expand Down
9 changes: 7 additions & 2 deletions pkg/condition/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestConditionGetters(t *testing.T) {
conds := []*ackv1alpha1.Condition{}

r := &ackmocks.AWSResource{}
r.On("DeepCopy").Return(r)
r.On("Conditions").Return(conds)

got := ackcond.Synced(r)
Expand Down Expand Up @@ -245,6 +246,7 @@ func TestConditionSetters(t *testing.T) {
//WithReferencesResolvedCondition
// Without Error
r = &ackmocks.AWSResource{}
r.On("DeepCopy").Return(r)
r.On("Conditions").Return([]*ackv1alpha1.Condition{})
r.On(
"ReplaceConditions",
Expand All @@ -261,6 +263,7 @@ func TestConditionSetters(t *testing.T) {
errorMsg := "error message"
err := errors.New(errorMsg)
r = &ackmocks.AWSResource{}
r.On("DeepCopy").Return(r)
r.On("Conditions").Return([]*ackv1alpha1.Condition{})
r.On(
"ReplaceConditions",
Expand All @@ -270,13 +273,14 @@ func TestConditionSetters(t *testing.T) {
}
return (subject[0].Type == ackv1alpha1.ConditionTypeReferencesResolved &&
subject[0].Status == corev1.ConditionUnknown &&
*subject[0].Message == errorMsg)
*subject[0].Message == ackcond.FailedReferenceResolutionMessage)
}),
)
ackcond.WithReferencesResolvedCondition(r, err)
// With Terminal Error
terminalError := ackerr.ResourceReferenceTerminal
r = &ackmocks.AWSResource{}
r.On("DeepCopy").Return(r)
r.On("Conditions").Return([]*ackv1alpha1.Condition{})
r.On(
"ReplaceConditions",
Expand All @@ -286,7 +290,8 @@ func TestConditionSetters(t *testing.T) {
}
return (subject[0].Type == ackv1alpha1.ConditionTypeReferencesResolved &&
subject[0].Status == corev1.ConditionFalse &&
*subject[0].Message == terminalError.Error())
*subject[0].Message == ackcond.FailedReferenceResolutionMessage &&
*subject[0].Reason == terminalError.Error())
}),
)
ackcond.WithReferencesResolvedCondition(r, terminalError)
Expand Down
Loading