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

sql: report the error seen during async operation in status directly #88

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions apis/database/v1beta1/sql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ type SQLServerObservation struct {
// LastOperation represents the state of the last operation started by the
// controller.
LastOperation apisv1alpha3.AsyncOperation `json:"lastOperation,omitempty"`

// LastError is the last error encountered during async operations.
LastError string `json:"lastError,omitempty"`
}

// A SQLServerStatus represents the observed state of a SQLServer.
Expand Down
1 change: 0 additions & 1 deletion apis/storage/v1alpha3/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions config/crd/database.azure.crossplane.io_mysqlservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ spec:
id:
description: ID - Resource ID
type: string
lastError:
description: LastError is the last error encountered during async
operations.
type: string
lastOperation:
description: LastOperation represents the state of the last operation
started by the controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ spec:
id:
description: ID - Resource ID
type: string
lastError:
description: LastError is the last error encountered during async
operations.
type: string
lastOperation:
description: LastOperation represents the state of the last operation
started by the controller.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/Azure/go-autorest/autorest/date v0.2.0
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/crossplaneio/crossplane v0.5.0-rc.0.20191211203849-05517d46525d
github.com/crossplaneio/crossplane v0.6.0
github.com/crossplaneio/crossplane-runtime v0.3.0
github.com/crossplaneio/crossplane-tools v0.0.0-20191220202319-9033bd8a02ce
github.com/google/go-cmp v0.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/crossplaneio/crossplane v0.5.0-rc.0.20191211203849-05517d46525d h1:Xie+cgdanhW6PN1mbcMWYs7q//HM1z1O/JgzgQj0R5k=
github.com/crossplaneio/crossplane v0.5.0-rc.0.20191211203849-05517d46525d/go.mod h1:f/e99LDWClmhkvMuvK7UMP1g5b718DGmdnpdrflK0HI=
github.com/crossplaneio/crossplane v0.6.0 h1:mDR0XG+mcwsedSgqLh0kCp+SVtwyPr5cJxYesTDZvsk=
github.com/crossplaneio/crossplane v0.6.0/go.mod h1:f/e99LDWClmhkvMuvK7UMP1g5b718DGmdnpdrflK0HI=
github.com/crossplaneio/crossplane-runtime v0.2.4-0.20191211004842-fa83d075257c h1:Xmv6RSdmFf2WeBpzVaqEBVxmGVAAUxA61eMgrdQ+Vsw=
github.com/crossplaneio/crossplane-runtime v0.2.4-0.20191211004842-fa83d075257c/go.mod h1:aVLQmXiPeb/jhGGQFIxx4Rc1CFC6xq2BA6A3neLZIHA=
github.com/crossplaneio/crossplane-runtime v0.3.0 h1:d3937o6XhVUcm/bqgUPUjTo/OjVlAjh1c7rx4VPJoV8=
Expand Down
13 changes: 10 additions & 3 deletions pkg/clients/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ import (
const (
// UserAgent is the user agent addition that identifies the Crossplane Azure client
UserAgent = "crossplane-azure-client"
// AsyncOperationStatusInProgress is the status value for AsyncOperation type
// that indicates the operation is still ongoing.

// AsyncOperationStatusInProgress is a status value for AsyncOperation.
AsyncOperationStatusInProgress = "InProgress"
asyncOperationPollingMethod = "AsyncOperation"

// AsyncOperationStatusSucceeded is a status value for AsyncOperation.
AsyncOperationStatusSucceeded = "Succeeded"

asyncOperationPollingMethod = "AsyncOperation"
)

// A FieldOption determines how common Go types are translated to the types
Expand Down Expand Up @@ -151,6 +155,9 @@ func FetchAsyncOperation(ctx context.Context, client autorest.Sender, as *v1alph
if err != nil {
as.ErrorMessage = err.Error()
}
if as.Status == AsyncOperationStatusSucceeded {
as.ErrorMessage = ""
}
return nil
}

Expand Down
31 changes: 7 additions & 24 deletions pkg/controller/database/mysqlserver/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (resource.E
if err := azure.FetchAsyncOperation(ctx, e.client.GetRESTClient(), &cr.Status.AtProvider.LastOperation); err != nil {
return resource.ExternalObservation{}, errors.Wrap(err, errFetchLastOperation)
}
cr.Status.AtProvider.LastError = cr.Status.AtProvider.LastOperation.ErrorMessage
switch cr.Status.AtProvider.UserVisibleState {
case v1beta1.StateReady:
cr.SetConditions(runtimev1alpha1.Available())
Expand Down Expand Up @@ -181,17 +182,11 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (resource.Ex
if err != nil {
return resource.ExternalCreation{}, errors.Wrap(err, errGenPassword)
}
if err := e.client.CreateServer(ctx, cr, pw); err != nil {
return resource.ExternalCreation{}, errors.Wrap(err, errCreateMySQLServer)
}

return resource.ExternalCreation{
ConnectionDetails: resource.ConnectionDetails{
runtimev1alpha1.ResourceCredentialsSecretPasswordKey: []byte(pw),
},
}, errors.Wrap(
azure.FetchAsyncOperation(ctx, e.client.GetRESTClient(), &cr.Status.AtProvider.LastOperation),
errFetchLastOperation)
ConnectionDetails: resource.ConnectionDetails{
runtimev1alpha1.ResourceCredentialsSecretPasswordKey: []byte(pw),
},
}, errors.Wrap(e.client.CreateServer(ctx, cr, pw), errCreateMySQLServer)
}

func (e *external) Update(ctx context.Context, mg resource.Managed) (resource.ExternalUpdate, error) {
Expand All @@ -202,13 +197,7 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (resource.Ex
if cr.Status.AtProvider.LastOperation.Status == azure.AsyncOperationStatusInProgress {
return resource.ExternalUpdate{}, nil
}
if err := e.client.UpdateServer(ctx, cr); err != nil {
return resource.ExternalUpdate{}, errors.Wrap(err, errUpdateMySQLServer)
}

return resource.ExternalUpdate{}, errors.Wrap(
azure.FetchAsyncOperation(ctx, e.client.GetRESTClient(), &cr.Status.AtProvider.LastOperation),
errFetchLastOperation)
return resource.ExternalUpdate{}, errors.Wrap(e.client.UpdateServer(ctx, cr), errUpdateMySQLServer)
}

func (e *external) Delete(ctx context.Context, mg resource.Managed) error {
Expand All @@ -220,11 +209,5 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) error {
if cr.Status.AtProvider.UserVisibleState == v1beta1.StateDropping {
return nil
}
if err := e.client.DeleteServer(ctx, cr); resource.Ignore(azure.IsNotFound, err) != nil {
return errors.Wrap(err, errDeleteMySQLServer)
}

return errors.Wrap(
azure.FetchAsyncOperation(ctx, e.client.GetRESTClient(), &cr.Status.AtProvider.LastOperation),
errFetchLastOperation)
return errors.Wrap(resource.Ignore(azure.IsNotFound, e.client.DeleteServer(ctx, cr)), errDeleteMySQLServer)
}
1 change: 1 addition & 0 deletions pkg/controller/database/postgresqlserver/managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (resource.E
if err := azure.FetchAsyncOperation(ctx, e.client.GetRESTClient(), &cr.Status.AtProvider.LastOperation); err != nil {
return resource.ExternalObservation{}, errors.Wrap(err, errFetchLastOperation)
}
cr.Status.AtProvider.LastError = cr.Status.AtProvider.LastOperation.ErrorMessage
switch server.UserVisibleState {
case v1beta1.StateReady:
cr.SetConditions(runtimev1alpha1.Available())
Expand Down