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

Messages to Azure Sql Firewall Rule #356

Merged
merged 13 commits into from
Oct 16, 2019
Merged

Messages to Azure Sql Firewall Rule #356

merged 13 commits into from
Oct 16, 2019

Conversation

melonrush13
Copy link
Contributor

@melonrush13 melonrush13 commented Oct 14, 2019

Address #326

What this PR does / why we need it:
Adding messages to the AzureSqlFirewall controller

Special notes for your reviewer:
Create an azure sql firewall instance
Run k get azuresqlfirewallrule -o yaml to see current message status of instance.

Should see a message field like:

➜  azure-service-operator git:(sqlfirewallmsg) ✗ k get azuresqlfirewallrule -o yaml
apiVersion: v1
items:
- apiVersion: azure.microsoft.com/v1alpha1
  kind: AzureSqlFirewallRule
  metadata:
    creationTimestamp: "2019-10-14T21:25:37Z"
    finalizers:
    - azuresqlfirewallrule.finalizers.azure.com
    generation: 1
    name: sqlf-allowazuresvcaccess
    namespace: default
    resourceVersion: "2069869"
    selfLink: /apis/azure.microsoft.com/v1alpha1/namespaces/default/azuresqlfirewallrules/sqlf-allowazuresvcaccess
    uid: 2a03a1c0-eec9-11e9-b1dc-5a2bc381628e
  spec:
    endipaddress: 0.0.0.0
    resourcegroup: resourcegroup-azure-operators-rush
    server: sqlserver-sample-777
    startipaddress: 0.0.0.0
  status:
    message: AzureSqlFirewallrulesqlf-allowazuresvcaccess successfully provisioned
    provisioned: true
kind: List
metadata:
  resourceVersion: ""

error

If applicable:

  • this PR contains documentation
  • this PR contains tests

Copy link
Contributor

@WilliamMortlMicrosoft WilliamMortlMicrosoft left a comment

Choose a reason for hiding this comment

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

Requesting at least one change... make sure Messages that occur need logging statements are passed to the logging call... this ensures things are aligned. Also, I'm confused by new updateerr conditions you added. I may be 100% wrong, but if you can explain them to me, that would be great. :-) Thanks Mel (sorry for so many comments)

@@ -67,6 +67,10 @@ func (r *AzureSqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Resul
if helpers.HasFinalizer(&instance, azureSQLFirewallRuleFinalizerName) {
if err := r.deleteExternal(&instance); err != nil {
log.Info("Delete AzureSqlFirewallRule failed with ", "error", err.Error())
instance.Status.Message = fmt.Sprintf("Delete AzureSqlFirewallRule failed with %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

move this above the log.Info and then send this exact message to log.Info... this will ensure everything is unified :-)

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 this is good practice for the future - I'm going to leave it as is for now since it is consistent across the other controllers. I think it would be good to handle these all together as a new task 👍

Copy link
Contributor Author

@melonrush13 melonrush13 Oct 15, 2019

Choose a reason for hiding this comment

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

Decided to fix it @WilliamMortlMicrosoft :) Good idea! I think this looks a lot cleaner, too!! Except, I still have the log in the same spot. I didn't think that mattered!

@@ -81,6 +85,10 @@ func (r *AzureSqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Resul
if !helpers.HasFinalizer(&instance, azureSQLFirewallRuleFinalizerName) {
if err := r.addFinalizer(&instance); err != nil {
log.Info("Adding AzureSqlFirewallRule finalizer failed with ", "error", err.Error())
instance.Status.Message = fmt.Sprintf("Adding AzureSqlFirewallRule finalizer failed with error %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

(same as above) use with log.Info

@@ -98,6 +106,10 @@ func (r *AzureSqlFirewallRuleReconciler) Reconcile(req ctrl.Request) (ctrl.Resul
if azerr, ok := err.(*errhelp.AzureError); ok {
if helpers.ContainsString(catch, azerr.Type) {
log.Info("Got ignorable error", "type", azerr.Type)
instance.Status.Message = fmt.Sprintf("Got ignorable error of type %s", azerr.Type)
Copy link
Contributor

Choose a reason for hiding this comment

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

(same as above) use with log.Info

Comment on lines 123 to 124
if updateerr := r.Status().Update(ctx, &instance); updateerr != nil {
r.Recorder.Event(&instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this new error trap... please double check... also, the message should reflect the warning, no? (I may be 100% wrong on this)

Comment on lines 161 to 162
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
Copy link
Contributor

Choose a reason for hiding this comment

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

same as earlier, confused by the error trap and why message isnt being set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is needed because we need to set the message variable which is done through r.Status().

But the error check is if it is somehow unable to update that variable (which shouldn't happen). Have this across the controllers as well

Comment on lines 180 to 181
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
Copy link
Contributor

Choose a reason for hiding this comment

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

same as earlier, confused by the error trap and why message isnt being set

controllers/azuresqlfirewallrule_controller.go Outdated Show resolved Hide resolved
Comment on lines 242 to 244
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as earlier, confused by the error trap and why message isnt being set

Comment on lines 249 to 251
if updateerr := r.Status().Update(ctx, instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as earlier, confused by the error trap and why message isnt being set

Comment on lines 260 to 262
if updateerr := r.Status().Update(context.Background(), instance); updateerr != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", "Unable to update instance")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same as earlier, confused by the error trap and why message isnt being set

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.

lgtm

@melonrush13 melonrush13 merged commit b740950 into Azure:master Oct 16, 2019
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.

3 participants