Skip to content

Commit

Permalink
clean up logic and fix message for failed poll (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibbles-n-bytes authored and pmorie committed Oct 23, 2017
1 parent 40926cd commit 3fddf27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
60 changes: 23 additions & 37 deletions pkg/controller/controller_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,65 +1496,54 @@ func (c *controller) pollServiceInstance(instance *v1beta1.ServiceInstance) erro
return err
}
case osb.StateFailed:
description := ""
description := "(no description provided)"
if response.Description != nil {
description = *response.Description
}
actionText := ""
switch {
case mitigatingOrphan:
actionText = "mitigating orphan"
case deleting:
actionText = "deprovisioning"
case provisioning:
actionText = "provisioning"
default:
actionText = "updating"
}
s := fmt.Sprintf(`Error %s: %q`, actionText, description)
c.recorder.Event(instance, corev1.EventTypeWarning, errorDeprovisionCalledReason, s)
glog.V(5).Infof(
`%s "%s/%s": %s`,
typeSI, instance.Namespace, instance.Name, s,
)

clone, err := api.Scheme.DeepCopy(instance)
if err != nil {
return err
}
toUpdate := clone.(*v1beta1.ServiceInstance)
c.clearServiceInstanceCurrentOperation(toUpdate)

var (
readyCond v1beta1.ConditionStatus
reason string
msg string
message string
)
switch {
case mitigatingOrphan:
readyCond = v1beta1.ConditionUnknown
reason = errorOrphanMitigationFailedReason
msg = "Orphan mitigation failed: " + s
message = "Orphan mitigation failed: " + description
case deleting:
readyCond = v1beta1.ConditionUnknown
reason = errorDeprovisionCalledReason
msg = "Deprovision call failed: " + s
message = "Deprovision call failed: " + description
case provisioning:
readyCond = v1beta1.ConditionFalse
reason = errorProvisionCallFailedReason
msg = "Provision call failed: " + s
message = "Provision call failed: " + description
default:
readyCond = v1beta1.ConditionFalse
reason = errorUpdateInstanceCallFailedReason
msg = "Update call failed: " + s
message = "Update call failed: " + description
}

c.recorder.Event(instance, corev1.EventTypeWarning, reason, message)
glog.V(5).Infof(
`%s "%s/%s": %s`,
typeSI, instance.Namespace, instance.Name, message,
)

clone, err := api.Scheme.DeepCopy(instance)
if err != nil {
return err
}
toUpdate := clone.(*v1beta1.ServiceInstance)

c.clearServiceInstanceCurrentOperation(toUpdate)

setServiceInstanceCondition(
toUpdate,
v1beta1.ServiceInstanceConditionReady,
readyCond,
reason,
msg,
message,
)

if !mitigatingOrphan {
Expand All @@ -1563,18 +1552,15 @@ func (c *controller) pollServiceInstance(instance *v1beta1.ServiceInstance) erro
v1beta1.ServiceInstanceConditionFailed,
v1beta1.ConditionTrue,
reason,
msg,
message,
)
}

if _, err := c.updateServiceInstanceStatus(toUpdate); err != nil {
return err
}

err = c.finishPollingServiceInstance(instance)
if err != nil {
return err
}
return c.finishPollingServiceInstance(instance)
default:
glog.Warningf(
`%s "%s/%s": Got invalid state in LastOperationResponse: %q`,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ func TestPollServiceInstanceFailureDeprovisioningWithOperation(t *testing.T) {

events := getRecordedEvents(testController)
assertNumEvents(t, events, 1)
expectedEvent := corev1.EventTypeWarning + " " + errorDeprovisionCalledReason + " " + "Error deprovisioning: \"\""
expectedEvent := corev1.EventTypeWarning + " " + errorDeprovisionCalledReason + " " + "Deprovision call failed: (no description provided)"
if e, a := expectedEvent, events[0]; e != a {
t.Fatalf("Received unexpected event: %v\nExpected: %v", a, e)
}
Expand Down

0 comments on commit 3fddf27

Please sign in to comment.