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

Recalculate health check params on BC/THC removal #2192

Merged
merged 2 commits into from
Jul 11, 2023

Conversation

DamianSawicki
Copy link
Contributor

The purpose of the present PR is to skip the function mergeUserSettings() when the removal of a BackendConfig or TransparentHealthCheck annotation is detected (or the removal of a health check specification from a BackendConfig). The rationale is that by removing custom annotations, the user should expect falling back to the default (or Readiness Probe) health check parameters and invoking mergeUserSettings() effectively preserves the custom setup.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 6, 2023
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 6, 2023
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 6, 2023
@code-elinka
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 6, 2023
pkg/flags/flags.go Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
@@ -218,10 +261,13 @@ func (h *HealthChecks) sync(hc *translator.HealthCheck, backendConfigHCConfig *b
return "", err
}

// Do not merge the existing settings and perform the full diff in calculateDiff.
var recalculate bool = thcConf.THCOptInOnSvc || h.shouldRecalculateOnBCRemoval(existingHC, backendConfigHCConfig) || h.shouldRecalculateOnTHCRemoval(existingHC, thcConf.THCOptInOnSvc)
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 it should be called reconfigureHC and why not using ":=" instead of "var"?

extract those ors to new function like shouldReconfigureHC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

why not using ":=" instead of "var"?

No particular reason. Is one preferred over the other?

pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Show resolved Hide resolved
}
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

why this is commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't remember exactly, but it's possible that I realised that the bug fixed in #2181 existed while writing this. The behaviour described in the commented out test case is incorrect, and I will remove this case. Btw. now we have similar (but correct) cases in TestCustomHealthcheckRemoval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted.

pkg/healthchecks/healthchecks_test.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks_test.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks_test.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks_test.go Outdated Show resolved Hide resolved
healthchecker *HealthChecks
hc *translator.HealthCheck
bchcc *backendconfigv1.HealthCheckConfig
want bool
Copy link
Contributor

Choose a reason for hiding this comment

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

what does "want" stands for? want recalculation? please rename

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 does "want" stands for?

It stands for the return value of the tested function, like in the pattern got-want. Don't you think this name makes sense?

I renamed the tested functions and the test function in v2, please let me know if you still recommend renaming want to something else.

pkg/healthchecks/healthchecks_test.go Outdated Show resolved Hide resolved
"ILB": translator.DescriptionForDefaultILBHealthChecks,
"NEG": translator.DescriptionForDefaultNEGHealthChecks,
"RP": translator.DescriptionForHealthChecksFromReadinessProbe,
"BC": (&healthcheck.HealthcheckInfo{HealthcheckConfig: healthcheck.BackendConfigHC}).GenerateHealthcheckDescription(),
Copy link
Contributor

Choose a reason for hiding this comment

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

BC is taking priority over THC so THC removal should be NoOp for BC based hc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. This test is probably overly complicated, but it tests a very simple thing: that shouldRecalculateOnTHCRemoval returns true only for beforeKey == "THC" && afterKey == "NO-THC", and false otherwise. It does not look at annotations for before, so the case you are describing is beforeKey == BC && afterKey == NO-THC, in which case false should be returned. It is correct.

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 7, 2023
@DamianSawicki DamianSawicki force-pushed the bc-removal branch 2 times, most recently from 6a1ba74 to 2844d38 Compare July 7, 2023 15:56
@DamianSawicki
Copy link
Contributor Author

/cc swetharepakula

Copy link
Contributor

@kl52752 kl52752 left a comment

Choose a reason for hiding this comment

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

Overall LGTM, waiting to @swetharepakula to look at.

return false
}
// The existing HC is configured via Transparent Health Checks, but the annotation has been removed.
if hcDesc.Config == healthcheck.TransparentHC && !thcOptIn {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can be just return hcDesc.Config == healthcheck.TransparentHC && !thcOptIn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! Fixed.

return hc
}
gotHC := filter(*computeHCs[0])
wantHC := filter(*tc.wantComputeHC)

if !reflect.DeepEqual(gotHC, wantHC) {
t.Fatalf("Compute healthcheck is:\n%s, want:\n%s", pretty.Sprint(gotHC), pretty.Sprint(wantHC))
t.Errorf("Compute healthcheck is:\n%s, want:\n%s", pretty.Sprint(gotHC), pretty.Sprint(wantHC))
Copy link
Contributor

Choose a reason for hiding this comment

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

why changing that?

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 changed it during debugging to be able to see more and remembered to revert it... but then I forgot in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@DamianSawicki DamianSawicki force-pushed the bc-removal branch 2 times, most recently from 042d2f3 to f51f667 Compare July 10, 2023 08:54
@DamianSawicki DamianSawicki marked this pull request as ready for review July 10, 2023 16:57
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2023
Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

Mostly nits. Otherwise LGTM

@@ -57,28 +57,28 @@ func calculateDiff(old, new *translator.HealthCheck, c *backendconfigv1.HealthCh

// TODO(bowei): why don't we check Port, timeout etc.

if c == nil && !thcEnabled {
if c == nil && !fullDiff {
return &changes
}

// This code assumes that the changes wrt to `c` has been applied to `new`.
Copy link
Member

Choose a reason for hiding this comment

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

To make these checks a little simpler can we not check if fullDIff is false and return early?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I also think that calculateDiff is overly complicated and these conditions in practise duplicate the functionality of mergeUserSettings. Eventually, there should be no early returns, just comparisons old.X != new.X. Having said that, health checks is a very sensitive issue, and a refactor here should be a separate and well-tested PR, perhaps additionally consulted. For now, I'm just renaming fullDiff -> fullDiffOnRecalculation to make clear what we do.

return hcDesc.Config == healthcheck.TransparentHC && !thcOptIn
}

func (h *HealthChecks) shouldRecalculateHC(existingHC *translator.HealthCheck, backendConfigHCConfig *backendconfigv1.HealthCheckConfig, thcConf utils.THCConfiguration) bool {
Copy link
Member

Choose a reason for hiding this comment

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

nit: i would unmarshal the healthcheck once in here and pass it to the various validation functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -183,6 +196,37 @@ func (h *HealthChecks) emitTHCEvents(hc *translator.HealthCheck, thcEvents utils

}

func (h *HealthChecks) isBackendConfigRemoved(hc *translator.HealthCheck, bchcc *backendconfigv1.HealthCheckConfig) bool {
if !h.healthcheckFlags.EnableRecalculationOnBackendConfigRemoval {
Copy link
Member

Choose a reason for hiding this comment

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

nit: based on the name, this is a little weird that we don't consider the BackendConfig removed based on a flag.

Instead I would think we would check the flag at where this would be called, and only if enabled we would check if the backend config was removed.

Either a rename or slight change in the code to make it match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead I would think we would check the flag at where this would be called, and only if enabled we would check if the backend config was removed.

Done.

@kl52752
Copy link
Contributor

kl52752 commented Jul 11, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 11, 2023
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2023
@k8s-ci-robot k8s-ci-robot merged commit 9bef6d1 into kubernetes:master Jul 11, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants