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

Migrate AzureSqlDatabase controller to async generic controller #525

Closed
wants to merge 6 commits into from
Closed

Migrate AzureSqlDatabase controller to async generic controller #525

wants to merge 6 commits into from

Conversation

jakiefermsft
Copy link
Contributor

This pull request moves all the AzureSqlDatabase controller logic into the generic controller model.

How does this PR make you feel:
gif

closes #465

@frodopwns
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@jakiefermsft jakiefermsft changed the title WIP: Migrate AzureSqlDatabase controller to async generic controller Migrate AzureSqlDatabase controller to async generic controller Dec 18, 2019
@jakiefermsft
Copy link
Contributor Author

Tests pass so removing WIP. 🤷‍♂

Copy link
Contributor

@frodopwns frodopwns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few comments before I start testing

controllers/azuresqldatabase_controller.go Show resolved Hide resolved
controllers/azuresqldatabase_controller.go Outdated Show resolved Hide resolved
if err != nil {
catch := []string{
errhelp.ResourceGroupNotFoundErrorCode,
errhelp.AsyncOpIncompleteError,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if you try to create a database for a server that doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened in the old code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its different now...the old controller relied on instance.Status.Provisioning to gate the interaction with ARM...now there is a reliance on the Ensure and Delete methods being idempotent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another issue here stemming from this change...

after the first reconciliation where the CreateorUpdate is called the reconciliation we start getting these errors:

2019-12-18T14:37:06.457-0700	ERROR	controller-runtime.controller	Reconciler error	{"controller": "azuresqldatabase", "request": "default/azuresqldatabase-sampleh", "error": "1 error occurred:\n\t* AzureSqlDb GetDB error sql.DatabasesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: json: cannot unmarshal array into Go struct field serviceError2.details of type map[string]interface {}\n\n"}

need to catch the error NotFoundErrorCode = "NotFound"

pkg/resourcemanager/sqlclient/azuresqldb_reconcile.go Outdated Show resolved Hide resolved
}
}

return true, fmt.Errorf("AzureSqlDb CreateOrUpdate error %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should set the create error in the instance.Status.Message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I set the error when I am ignoring an error or when it's a real error? I checked out eventhub namespace and it looks like you only set that when it's a caught error. Just want to make sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably want both in the end. I'm thinking that a user might rather check the status of their resource to see what is wrong then tail the logs of the operator.

// Database does not exist
return false, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to update instance.Status.Message here in case the delete error wasn't temporary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error here is that the database is already gone. What should I set instance.Status.Message to in that case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im talking about the errors that are not "already gone"...like "Resource Group does not exist"....most of these things seem to throw special errors for that. What about when the Serverr doesn't exist? What about network timeouts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see what you are saying. You're not saying this logic is incorrect but that I should just put err into instance.Status.Message on line 96?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

// DBEdition - wraps: https://godoc.org/github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql#DatabaseEdition
type DBEdition byte
type DBEdition = v1alpha1.DBEdition
type ReadWriteEndpointFailoverPolicy = v1alpha1.ReadWriteEndpointFailoverPolicy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these seem a bit odd...why not just use v1alpha.whatever?

Copy link
Contributor Author

@jakiefermsft jakiefermsft Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these into v1alpha to avoid an import cycle. I exported them out of this package as to not have to change all the places that reference these. I think there should be a separate ticket that figures out what type of things belong in the v1alpha package and what code belong elsewhere.

return true, fmt.Errorf("AzureSqlDb delete error %v", err)
}

return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be false, nil because the DeleteDb doesn't return an error on first delete and it doesn't return an error when it's gone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think I follow. I wonder if we can write some documentation or make a graphic that could help illustrate the reasoning behind the return values in the ARMClient. I don't think they are super intuitive.

Returning a true here doesn't signal that things were successful, but that we want to be called again, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to add comments to the interface and the async controller and also maybe add it to a dev guide

Copy link
Contributor

@frodopwns frodopwns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like deletion ever finishes on the AureSqlDatabase objects.

@Azure Azure deleted a comment from jakiefermsft Dec 19, 2019
@Azure Azure deleted a comment from jakiefermsft Dec 19, 2019
@Azure Azure deleted a comment from jakiefermsft Dec 19, 2019
@Azure Azure deleted a comment from jakiefermsft Dec 19, 2019
@Azure Azure deleted a comment from jakiefermsft Dec 19, 2019
@frodopwns
Copy link
Contributor

this work is being continued in another branch

@frodopwns frodopwns closed this Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Task: Update Sql database controller to use the generic controller model
2 participants