-
Notifications
You must be signed in to change notification settings - Fork 297
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
Update healthcheck Description on BackendConfig removal #2181
Update healthcheck Description on BackendConfig removal #2181
Conversation
Hi @DamianSawicki. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign aojea |
a567521
to
08777ff
Compare
/ok-to-test |
/cc mag-kol |
@DamianSawicki: GitHub didn't allow me to request PR reviews from the following users: mag-kol. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@@ -1743,6 +1792,25 @@ func TestSyncServicePort(t *testing.T) { | |||
t.Errorf("hcs.SyncServicePort(tc.sp, tc.probe) = %q, _; want = %q", gotSelfLink, tc.wantSelfLink) | |||
} | |||
verify() | |||
|
|||
if tc.expectedEvent > 0 { |
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.
it's better to create a new test func then extend this with new cases and special assertion just for your cases
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.
pkg/healthchecks/healthchecks.go
Outdated
if flags.F.EnableUpdateCustomHealthCheckDescription { | ||
desc := &healthcheck.HealthcheckDesc{} | ||
err := json.Unmarshal([]byte(existingHC.Description), desc) | ||
if err == nil && desc.Config == healthcheck.BackendConfigHC && bchcc == 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.
bchcc?
pelase name this properly
it has been declared 50+ lines earlier
maybe healthCheckConfig is a good name
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.
BC stands for BackendConfig
HC must stand for Health Check
C is probably Config
Renaming this is a topic for a refactor, not a quick bug fix.
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.
pkg/healthchecks/healthchecks.go
Outdated
if err != nil { | ||
klog.Errorf("Health check %q update error: %v", existingHC.Name, err) | ||
} | ||
h.notifyAboutTHC(hc, thcConf.THCEvents) |
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.
notifyAboutTHC -> emitTHCEvents
event is well defined concept
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 many times notifyAboutTHC func can be called in one execution? I may happen a few times from what I see
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.
Just once, it's always shortly before a return statement.
// The contents of the following 'if' are temporary, see https://github.com/kubernetes/ingress-gce/pull/2181 for details. | ||
if flags.F.EnableUpdateCustomHealthCheckDescription { | ||
desc := &healthcheck.HealthcheckDesc{} | ||
err := json.Unmarshal([]byte(existingHC.Description), desc) |
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.
you have to do something if this error happens
maybe logging error is enough (with warning severity?)
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.
Error means that the Description is not a JSON. We are in the process of switching from plain strings to JSON, depending on health check types and flags enabled, so it's not really an error to see a non-jsonified Description.
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.
for debugging purposes it would be good to have a log that says that this was not a JSON description
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.
pkg/healthchecks/healthchecks.go
Outdated
@@ -262,6 +263,28 @@ func (h *HealthChecks) sync(hc *translator.HealthCheck, bchcc *backendconfigv1.H | |||
return existingHC.SelfLink, err | |||
} | |||
|
|||
// The contents of the following 'if' are temporary, see https://github.com/kubernetes/ingress-gce/pull/2181 for details. |
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.
please add more info here
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.
Discussed this with Antonio already, there are Google-internal resources with details.
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 second Cezary's comment. Since we cannot link the internal issue, it would be good to have some description in the code.
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.
It would be a good idea to describe what this trying to do as in we are only updating the HC description and nothing else
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.
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.
The changes look good to me. I do agree with the existing feedback that we should have a more detailed comment on what this is fixing. Though this will be changed in the future, we will still be supporting this version of the code for a long time and may need the comment to understand past context.
08777ff
to
31157e7
Compare
desc := &healthcheck.HealthcheckDesc{} | ||
err := json.Unmarshal([]byte(existingHC.Description), desc) | ||
if err != nil { | ||
klog.V(3).Info("Description for healthcheck %s is not a JSON (probably a plain-text description): %s.", existingHC.Name, existingHC.Description) |
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.
Can you do early return here and remove else. Also you can mention in this log that the update is omitted because the description is not a JSON.
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.
Also you can mention in this log that the update is omitted because the description is not a JSON.
Done.
Can you do early return here and remove else.
I would prefer not to to avoid copy-pasting the following lines.
klog.V(2).Infof("Health check %q already exists and needs no update", hc.Name)
return existingHC.SelfLink, nil
// even if changes.hasDiff() above is false. No other health check field is modified. The purpose is for the Description to accurately | ||
// reflect the existence of a backendconfigv1.HealthCheckConfig for the service. This is temporary, see | ||
// https://github.com/kubernetes/ingress-gce/pull/2181 for details. | ||
if flags.F.EnableUpdateCustomHealthCheckDescription { |
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 don't like the idea to postpone the update if it will not happened earlier. I think it would be better to put all logic related to checking against backend config description to a function fg isDescriptionUpdateNeeded
and add condition to line 247
if changes.hasDiff() || isDescriptionUpdateNeeded() {}
WDYT?
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.
Discussed outside GitHub, done. @kl52752 PTAL.
shallowCopy := func(x *compute.HealthCheck) *compute.HealthCheck { y := *x; return &y } | ||
|
||
// Don't recalculate health check on BackendConfig removal (legacy behaviour, to be changed), but update Description. | ||
chc := fixture.hc() |
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.
instead of using ficture.hc() and overriding almost everything can you create new function healthCheckFromBackendConfig
and reuse it below? (I don't see any difference here)
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.
Good idea, done.
t.Fatalf("Got %d healthchecks, want 1\n%s", len(computeHCs), pretty.Sprint(computeHCs)) | ||
} | ||
|
||
// Filter out SelfLink because it is hard to deal with in the mock and |
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.
And description if flag is disabled
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.
This is a temporary solution under the flag --enable-update-hc-description.
31157e7
to
b3e0bdf
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DamianSawicki, kl52752 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
In #2008 and #2068, we guarantee that the health check Description is updated when a BackendConfig is added to the Service (behind the flag --enable-update-hc-description). When a BackendConfig is removed, typically a health check update is triggered, which includes resetting the Description. However, under some circumstances the health check parameters update won't happen on BackendConfig removal, but it is still desirable to reset the Description to reflect the lack of BackendConfig. This reset is added in the present PR.
The changes are behind the abovementioned flag --enable-update-hc-description. This is a temporary fix and corresponding code will be removed with the subsequent planned changes.