Repository: kubernetes/kubernetes (language: go)

Issue:
Add statusz endpoint for kube-scheduler
### What would you like to be added?

Part of 
- https://github.com/kubernetes/enhancements/issues/4827

Add the `/statuz` endpoint for kube-scheduler.

Sample response:
```
Started: Fri Sep  6 06:19:51 UTC 2024
Up: 0 hr 00 min 30 sec
Go version: go1.23.0
Binary version: 1.31.0-beta.0.981&#43;c6be932655a03b-dirty
Emulation version: 1.31.0-beta.0.981
Minimum Compatibility version: 1.30.0

List of useful endpoints
--------------
configz:/configz
healthz:/healthz
livez:/livez
metrics:/metrics
readyz:/readyz
sli metrics:/metrics/slis
```

/sig instrumentation

### Why is this needed?

Refer to [Motivation setcion](https://github.com/kubernetes/enhancements/blob/master/keps/sig-instrumentation/4827-component-statusz/README.md#motivation) in KEP.

```[tasklist]
### Tasks
```



Discussion / hints:
/assign
@Henrywu573 hi bro,I see you've assigned multiple components. If you don't mind, I would like to work on the kub-scheduler part. Thanks~
/assign
Hi @Mokaz111, thank you so much for your interest in helping out! I really appreciate you taking the time to look at these issues. I'm actually already actively working on this issue, kube-proxy, and controller manager at the moment. I'm hoping to have them resolved soon.

Meanwhile, if you are interested in contributing to sig-instrumentation, feel free to join https://github.com/kubernetes/community/tree/master/sig-instrumentation#meetings. Thanks!

cc @richabanker 
Thank you for letting me know! I'm very interested in contributing to sig-instrumentation and would love to join. 

Fix patch:
diff --git a/cmd/kube-scheduler/app/server.go b/cmd/kube-scheduler/app/server.go
index 993fb81e01dbd..c9ab27027cf96 100644
--- a/cmd/kube-scheduler/app/server.go
+++ b/cmd/kube-scheduler/app/server.go
@@ -39,6 +39,7 @@ import (
 	"k8s.io/apiserver/pkg/server/healthz"
 	"k8s.io/apiserver/pkg/server/mux"
 	"k8s.io/apiserver/pkg/server/routes"
+	"k8s.io/apiserver/pkg/util/compatibility"
 	utilfeature "k8s.io/apiserver/pkg/util/feature"
 	"k8s.io/client-go/informers"
 	"k8s.io/client-go/kubernetes/scheme"
@@ -59,6 +60,7 @@ import (
 	"k8s.io/component-base/version/verflag"
 	zpagesfeatures "k8s.io/component-base/zpages/features"
 	"k8s.io/component-base/zpages/flagz"
+	"k8s.io/component-base/zpages/statusz"
 	"k8s.io/klog/v2"
 	schedulerserverconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
 	"k8s.io/kubernetes/cmd/kube-scheduler/app/options"
@@ -371,6 +373,11 @@ func newEndpointsHandler(config *kubeschedulerconfig.KubeSchedulerConfiguration,
 			flagz.Install(pathRecorderMux, kubeScheduler, flagReader)
 		}
 	}
+
+	if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
+		statusz.Install(pathRecorderMux, kubeScheduler, statusz.NewRegistry(compatibility.DefaultBuildEffectiveVersion()))
+	}
+
 	return pathRecorderMux
 }
 


Test patch:
diff --git a/test/integration/scheduler/serving/endpoints_test.go b/test/integration/scheduler/serving/endpoints_test.go
index 91cb2d5ad840d..3de9ab910d12e 100644
--- a/test/integration/scheduler/serving/endpoints_test.go
+++ b/test/integration/scheduler/serving/endpoints_test.go
@@ -39,6 +39,8 @@ import (
 
 func TestEndpointHandlers(t *testing.T) {
 	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ComponentFlagz, true)
+	featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ComponentStatusz, true)
+
 	server, configStr, _, err := startTestAPIServer(t)
 	if err != nil {
 		t.Fatalf("Failed to start kube-apiserver server: %v", err)
@@ -128,6 +130,16 @@ func TestEndpointHandlers(t *testing.T) {
 				`Warning: This endpoint is not meant to be machine parseable, ` +
 				`has no formatting compatibility guarantees and is for debugging purposes only.`,
 		},
+		{
+			name:             "/statusz",
+			path:             "/statusz",
+			requestHeader:    map[string]string{"Accept": "text/plain"},
+			wantResponseCode: http.StatusOK,
+			wantResponseBodyRegx: `^\n` +
+				`kube-scheduler statusz\n` +
+				`Warning: This endpoint is not meant to be machine parseable, ` +
+				`has no formatting compatibility guarantees and is for debugging purposes only.`,
+		},
 	}
 
 	for _, tt := range tests {