Skip to content

Commit

Permalink
Merge pull request #303 from crossplane/backport-302-to-release-0.17
Browse files Browse the repository at this point in the history
[Backport release-0.17] Fix panic when returning error with provider reference name
  • Loading branch information
hasheddan committed Nov 11, 2021
2 parents 33f728d + ae15135 commit 5954830
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apis/storage/v1alpha3/test/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func (tc *MockContainer) WithSpecProviderRef(name string) *MockContainer {
return tc
}

// WithSpecProviderConfigRef sets spec account reference value
func (tc *MockContainer) WithSpecProviderConfigRef(name string) *MockContainer {
tc.Container.Spec.ProviderConfigReference = &xpv1.Reference{Name: name}
return tc
}

// WithSpecDeletionPolicy sets spec deletion policy value
func (tc *MockContainer) WithSpecDeletionPolicy(p xpv1.DeletionPolicy) *MockContainer {
tc.Container.Spec.DeletionPolicy = p
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/storage/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (m *containerSyncdeleterMaker) newSyncdeleter(ctx context.Context, c *v1alp
return nil, errors.Wrapf(err, "failed to update after removing finalizer")
}
}
return nil, errors.Wrapf(err, "failed to retrieve storage account: %s", c.Spec.ProviderReference.Name)
return nil, errors.Wrapf(err, "failed to retrieve storage account: %s", nn.Name)
}

if acct.GetWriteConnectionSecretToReference() == nil {
Expand Down
20 changes: 19 additions & 1 deletion pkg/controller/storage/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func Test_containerSyncdeleterMaker_newSyncdeleter(t *testing.T) {
want want
}{
{
name: "FailedToGetAccountNotFoundNoDelete",
name: "FailedToGetAccountNotFoundNoDeleteProviderRef",
fields: fields{
Client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
Expand All @@ -331,6 +331,24 @@ func Test_containerSyncdeleterMaker_newSyncdeleter(t *testing.T) {
"failed to retrieve storage account: %s", testAccountName),
},
},
{
name: "FailedToGetAccountNotFoundNoDeleteProviderConfigRef",
fields: fields{
Client: &test.MockClient{
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
return newAccountNotFoundError(testAccountName)
},
},
},
args: args{
ctx: ctx,
c: newCont().WithSpecProviderConfigRef(testAccountName).WithFinalizer(finalizer).Container,
},
want: want{
err: errors.Wrapf(newAccountNotFoundError(testAccountName),
"failed to retrieve storage account: %s", testAccountName),
},
},
{
name: "FailedToGetAccountNotFoundYesDelete",
fields: fields{
Expand Down

0 comments on commit 5954830

Please sign in to comment.