-
Notifications
You must be signed in to change notification settings - Fork 68
Update remove-clusters to remove clusters from urlmaps status as well #151
Update remove-clusters to remove clusters from urlmaps status as well #151
Conversation
I'll take a look at this one. |
return fmt.Errorf("errors in updating both http and https forwarding rules, http rule error: %s, https rule error: %s", httpErr, httpsErr) | ||
} | ||
|
||
// canIgnoreStatusUpdateError returns true iff either of the following is true: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think it might be better to expand "iff" to "if and only if". I'm always concerned that people will think that "iff" is a typo and miss out on the meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// * err is nil | ||
// * err has http.StatusNotFound code | ||
func canIgnoreStatusUpdateError(err error) bool { | ||
if err == nil || utils.IsHTTPErrorCode(err, http.StatusNotFound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return err == nil || utils.IsHTTPErrorCode(err, http.StatusNotFound)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right :) Updated!
httpErr := s.removeClustersFromStatus("http", s.namer.HttpForwardingRuleName(), clusters) | ||
// If both are not found, then return that. | ||
if utils.IsHTTPErrorCode(httpErr, http.StatusNotFound) && utils.IsHTTPErrorCode(httpsErr, http.StatusNotFound) { | ||
return httpErr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a combined error that explains that both are not found?
Also, why is it OK if only one is not found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default users create http only ingress, so only HttpForwardingRule will exist.
Similarly for https only ingress, only HttpsForwardingRule will exist.
Generally speaking, if this was able to update the status's that it found, it returns success.
For combining: the error only has the NotFound status code, so combining wont change anything.
We handle both NotFound specially since we want to surface "load balancer does not exist" errors.
fmt.Println(httpProtocol, "forwarding rule not found. Nothing to update. Continuing") | ||
return nil | ||
// Return this error as is. | ||
return err | ||
} | ||
err := fmt.Errorf("error in fetching existing forwarding rule %s: %s", name, err) | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be Printf("%v\n", err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um why?
I dont need any special formatting. Println will print the error fine.
Example: https://play.golang.org/p/CEl9eX_esTh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK. I think this was a mental holdover on my part from doing C-based language work for years, where the arguments to "PrintX" methods were always strings. Apologies!
if err := frs.RemoveClustersFromStatus([]string{"cluster1"}); err != nil { | ||
t.Errorf("unexpected error in updating status to remove clusters: %s", err) | ||
err := frs.RemoveClustersFromStatus([]string{"cluster1"}) | ||
if c.shouldErr != (err != nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe create a local variable for err != nil
hasErr := err != nil
if c.ShouldErr != hasErr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its fine here without it but good point to keep in mind for places with more complex code.
return err | ||
} | ||
|
||
func (l *LoadBalancerSyncer) removeClustersFromStatus(lbName string, removeClusters []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// Also note that it continues silently if either HTTP or HTTPS forwarding rules do not exist. | ||
if err := s.removeClustersFromStatus("https", s.namer.HttpsForwardingRuleName(), clusters); err != nil { | ||
return fmt.Errorf("unexpected error in updating the https forwarding rule status: %s", err) | ||
httpsErr := s.removeClustersFromStatus("https", s.namer.HttpsForwardingRuleName(), clusters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this relate to the URL map change? It seems independent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking yes its independent. The reason its here is that the interface is tighter now and consistent with UrlMapSyncer.RemoveClustersFromStatus. Both return NotFound if the urlmap or forwarding rule does not exist.
|
||
// RemoveClusters removes the given list of clusters from the given status string. | ||
// Returns NotFoundError if the given statusStr is not a valid LoadBalancerStatus. | ||
func RemoveClusters(statusStr string, removeClusters []string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: clustersToRemove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, here and everywhere
status.Clusters = newClusters | ||
newDesc, err := status.ToString() | ||
if err != nil { | ||
return statusStr, fmt.Errorf("unexpected error in converting status to string. status: %s, err: %s", status, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a NotFoundError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This is error in serializing Status struct to string. This should ideally never be hit.
@@ -117,6 +118,32 @@ func (s *URLMapSyncer) DeleteURLMap() error { | |||
} | |||
} | |||
|
|||
// See interface for comment. | |||
func (s *URLMapSyncer) RemoveClustersFromStatus(clusters []string) error { | |||
fmt.Println("Removing clusters", clusters, "from url map") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use Printf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um why? We use Println throughout the code base for simple output strings that dont require special formatting.
e5a47ce
to
3423bcc
Compare
Thanks for the review @perotinus |
275da99
to
3f49d05
Compare
Rebased to remove merge conflicts and fixed test. |
fmt.Println(httpProtocol, "forwarding rule not found. Nothing to update. Continuing") | ||
return nil | ||
// Return this error as is. | ||
return err | ||
} | ||
err := fmt.Errorf("error in fetching existing forwarding rule %s: %s", name, err) | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK. I think this was a mental holdover on my part from doing C-based language work for years, where the arguments to "PrintX" methods were always strings. Apologies!
t.Errorf("unexpected error in updating status to remove clusters: %s", err) | ||
err := frs.RemoveClustersFromStatus([]string{"cluster1"}) | ||
if c.shouldErr != (err != nil) { | ||
t.Errorf("unexpected error in updating status to remove clusters, expected err != nil: %v, actual err: %s", c.shouldErr, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I think the test output and this code would be more readable if you had two branches. If this test failed and I had to look at it without having seen it before, it would take me some time to parse out all of the boolean conditions to actually understand the failure, which is not ideal in a test.
If you wanted to leave one branch, I think the failure output would be clearer if you replaced expected err != nil: %v
with expected err %s nil:
and a branch that set either ==
or !=
as the replacement for %s
.
/lgtm |
3f49d05
to
a40d474
Compare
Thanks for the review @perotinus Updated as per comments and squashed commits. |
Ref #58 (remove-clusters) and #145 (storing status on url map instead of forwarding rule).
Follow up to #146 which added a
kubemci remove-clusters
command. That PR updated the status stored on forwarding rule.This PR updates that code to update the status on url map as well.
The status could be stored on forwarding rule (for old MCIs) or url map (for new MCIs).
cc @G-Harmon @csbell @madhusudancs