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

OCPBUGS-48177: UPSTREAM: <carry>: disable etcd readiness checks by default #2174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,27 @@ type CompletedConfig struct {
func (c *Config) AddHealthChecks(healthChecks ...healthz.HealthChecker) {
c.HealthzChecks = append(c.HealthzChecks, healthChecks...)
c.LivezChecks = append(c.LivezChecks, healthChecks...)
c.ReadyzChecks = append(c.ReadyzChecks, healthChecks...)
c.AddReadyzChecks(healthChecks...)
}

// AddReadyzChecks adds a health check to our config to be exposed by the readyz endpoint
// of our configured apiserver.
func (c *Config) AddReadyzChecks(healthChecks ...healthz.HealthChecker) {
c.ReadyzChecks = append(c.ReadyzChecks, healthChecks...)
// Info(ingvagabund): Explicitly exclude etcd and etcd-readiness checks (OCPBUGS-48177)
// and have etcd operator take responsibility for properly reporting etcd readiness.
// Justification: kube-apiserver instances get removed from a load balancer when etcd starts
// to report not ready (as will KA's /readyz). Client connections can withstand etcd unreadiness
// longer than the readiness timeout is. Thus, it is not necessary to drop connections
// in case etcd resumes its readiness before a client connection times out naturally.
// This is a downstream patch only as OpenShift's way of using etcd is unique.
readyzChecks := []healthz.HealthChecker{}
for _, check := range healthChecks {
if check.Name() == "etcd" || check.Name() == "etcd-readiness" {

Choose a reason for hiding this comment

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

instead of this patch shouldn't we exclude the desired check directly from kas-o ? (xref: https://github.com/openshift/cluster-kube-apiserver-operator/blob/master/bindata/assets/kube-apiserver/pod.yaml#L111)

Copy link
Member Author

@ingvagabund ingvagabund Jan 17, 2025

Choose a reason for hiding this comment

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

I have not properly checked though are all KA instances always exposed through service endpoints or a load balancer? Cloud provider LB health check paths are not expected to accept any queries/params like ?exclude=... (AWS, Azure, GCP at least). Unless I misunderstood both openshit-apiserver and oauth-apiserver rely on k8s.io/apiserver/pkg/server code. I.e. https://github.com/openshift/openshift-apiserver/blob/master/go.mod#L197 and https://github.com/openshift/oauth-apiserver/blob/master/go.mod#L144.

Is https://github.com/openshift/kubernetes-apiserver expected to be in sync with https://github.com/openshift/kubernetes?

Choose a reason for hiding this comment

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

I am pretty sure it will work because we already exclude etcd from the liveness probe (xref: https://github.com/openshift/cluster-kube-apiserver-operator/blob/master/bindata/assets/kube-apiserver/pod.yaml#L105)

Copy link
Member Author

@ingvagabund ingvagabund Jan 17, 2025

Choose a reason for hiding this comment

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

All right. So this will work for KA instances and https://github.com/openshift/cluster-kube-apiserver-operator/blob/master/bindata/assets/kube-apiserver/svc.yaml. What about o-a and oauth-a? I was told they are added to a LB. Through:

which OpenShift relies on when creating the LBs. It seems to be a pattern to ignore/reject any such exclusion in the LB's health check paths: https://issues.redhat.com/browse/OCPBUGS-48177?focusedId=26397412&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-26397412.

So even though the ?exclude... could be used for KA instances, it will not work for o-a/oauth-a. Also, disabling the checks in the code directly instead of at every place /readyz is accessed leaves no space for "forgotten" cases.

Choose a reason for hiding this comment

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

What about o-a and oauth-a?

We could also exclude the desired checks directly from the operators, for example:
https://github.com/openshift/cluster-openshift-apiserver-operator/blob/master/bindata/v3.11.0/openshift-apiserver/deploy.yaml#L122

I was told they are added to a LB

I don't think this is true. The extension API servers are proxied by the KAS.

Copy link
Member Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

We do but I think only for KAS.

We could verify it. Please create a cluster on AWS and then log in to the AWS console and check the setting for the LB.

Copy link
Member Author

@ingvagabund ingvagabund Jan 20, 2025

Choose a reason for hiding this comment

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

Me and Lukasz synced over a call to discuss this. Main points:

continue
}
readyzChecks = append(readyzChecks, check)
}
c.ReadyzChecks = append(c.ReadyzChecks, readyzChecks...)
}

// AddPostStartHook allows you to add a PostStartHook that will later be added to the server itself in a New call.
Expand Down
2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiserver/pkg/server/options/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (s *EtcdOptions) maybeApplyResourceTransformers(c *server.Config) (err erro

func addHealthChecksWithoutLivez(c *server.Config, healthChecks ...healthz.HealthChecker) {
c.HealthzChecks = append(c.HealthzChecks, healthChecks...)
c.ReadyzChecks = append(c.ReadyzChecks, healthChecks...)
c.AddReadyzChecks(healthChecks...)
}

func (s *EtcdOptions) addEtcdHealthEndpoint(c *server.Config) error {
Expand Down
19 changes: 17 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/server/options/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ func TestParseWatchCacheSizes(t *testing.T) {
}
}

func excludeEtcdReadyzChecks(readyzChecks []string) []string {
includedReadyzChecks := []string{}
for _, checkName := range readyzChecks {
if checkName == "etcd" || checkName == "etcd-readiness" {
continue
}
includedReadyzChecks = append(includedReadyzChecks, checkName)
}
return includedReadyzChecks
}

func TestKMSHealthzEndpoint(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.KMSv1, true)

Expand Down Expand Up @@ -367,7 +378,9 @@ func TestKMSHealthzEndpoint(t *testing.T) {
}

healthChecksAreEqual(t, tc.wantHealthzChecks, serverConfig.HealthzChecks, "healthz")
healthChecksAreEqual(t, tc.wantReadyzChecks, serverConfig.ReadyzChecks, "readyz")
// Remove the excluded checks here to reduce the carry patch changes in case
// the changes drifts too much during rebases and similar scope-like changes.
healthChecksAreEqual(t, excludeEtcdReadyzChecks(tc.wantReadyzChecks), serverConfig.ReadyzChecks, "readyz")
healthChecksAreEqual(t, tc.wantLivezChecks, serverConfig.LivezChecks, "livez")
})
}
Expand Down Expand Up @@ -407,7 +420,9 @@ func TestReadinessCheck(t *testing.T) {
t.Fatalf("Failed to add healthz error: %v", err)
}

healthChecksAreEqual(t, tc.wantReadyzChecks, serverConfig.ReadyzChecks, "readyz")
// Remove the excluded checks here to reduce the carry patch changes in case
// the changes drifts too much during rebases and similar scope-like changes.
healthChecksAreEqual(t, excludeEtcdReadyzChecks(tc.wantReadyzChecks), serverConfig.ReadyzChecks, "readyz")
healthChecksAreEqual(t, tc.wantHealthzChecks, serverConfig.HealthzChecks, "healthz")
healthChecksAreEqual(t, tc.wantLivezChecks, serverConfig.LivezChecks, "livez")
})
Expand Down
1 change: 0 additions & 1 deletion test/e2e/apimachinery/health_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ var (
requiredReadyzChecks = sets.NewString(
"[+]ping ok",
"[+]log ok",
"[+]etcd ok",
"[+]informer-sync ok",
"[+]poststarthook/start-apiserver-admission-initializer ok",
"[+]poststarthook/generic-apiserver-start-informers ok",
Expand Down