Skip to content

Commit d4bd007

Browse files
committed
adds a list of available HTTP endpoints for the kube-controller-manager component under the /statusz page
1 parent b4b973c commit d4bd007

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

cmd/kube-controller-manager/app/controllermanager.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
225225
}
226226

227227
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
228-
statusz.Install(unsecuredMux, kubeControllerManager, statusz.NewRegistry(c.ComponentGlobalsRegistry.EffectiveVersionFor(basecompatibility.DefaultKubeComponent)))
228+
statusz.Install(
229+
unsecuredMux,
230+
kubeControllerManager,
231+
statusz.NewRegistry(
232+
c.ComponentGlobalsRegistry.EffectiveVersionFor(basecompatibility.DefaultKubeComponent),
233+
statusz.WithListedPaths(unsecuredMux.ListedPaths()),
234+
),
235+
)
229236
}
230237

231238
handler := genericcontrollermanager.BuildHandlerChain(unsecuredMux, &c.Authorization, &c.Authentication)

test/integration/serving/serving_test.go

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"strings"
3030
"testing"
3131

32+
"reflect"
33+
3234
"k8s.io/apiserver/pkg/server"
3335
"k8s.io/apiserver/pkg/server/options"
3436
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -352,15 +354,24 @@ users:
352354
anonymous bool // to use the token or not
353355
wantErr bool
354356
wantSecureCode *int
357+
wantPaths []string
355358
}{
356-
{"serving /statusz", []string{
357-
"--authentication-skip-lookup", // to survive inaccessible extensions-apiserver-authentication configmap
358-
"--authentication-kubeconfig", apiserverConfig.Name(),
359-
"--authorization-kubeconfig", apiserverConfig.Name(),
360-
"--authorization-always-allow-paths", "/statusz",
361-
"--kubeconfig", apiserverConfig.Name(),
362-
"--leader-elect=false",
363-
}, "/statusz", false, false, ptr.To(http.StatusOK)},
359+
{
360+
name: "serving /statusz",
361+
flags: []string{
362+
"--authentication-skip-lookup", // to survive inaccessible extensions-apiserver-authentication configmap
363+
"--authentication-kubeconfig", apiserverConfig.Name(),
364+
"--authorization-kubeconfig", apiserverConfig.Name(),
365+
"--authorization-always-allow-paths", "/statusz",
366+
"--kubeconfig", apiserverConfig.Name(),
367+
"--leader-elect=false",
368+
},
369+
path: "/statusz",
370+
anonymous: false,
371+
wantErr: false,
372+
wantSecureCode: ptr.To(http.StatusOK),
373+
wantPaths: []string{"/configz", "/healthz", "/metrics"},
374+
},
364375
}
365376
for _, tt := range tests {
366377
t.Run(tt.name, func(t *testing.T) {
@@ -416,7 +427,8 @@ users:
416427
t.Fatalf("failed to GET %s from component: %v", tt.path, err)
417428
}
418429

419-
if _, err = io.ReadAll(r.Body); err != nil {
430+
body, err := io.ReadAll(r.Body)
431+
if err != nil {
420432
t.Fatalf("failed to read response body: %v", err)
421433
}
422434
defer func() {
@@ -428,6 +440,39 @@ users:
428440
if got, expected := r.StatusCode, *tt.wantSecureCode; got != expected {
429441
t.Fatalf("expected http %d at %s of component, got: %d", expected, tt.path, got)
430442
}
443+
444+
bodyStr := string(body)
445+
446+
if !strings.Contains(bodyStr, "Paths") {
447+
t.Error("response does not contain Paths section")
448+
}
449+
450+
var foundPathsRaw []string
451+
for _, line := range strings.Split(bodyStr, "\n") {
452+
if strings.HasPrefix(line, "Paths") {
453+
parts := strings.Fields(line)
454+
if len(parts) > 1 {
455+
foundPathsRaw = parts[1:] // Skip "Paths" label
456+
}
457+
break
458+
}
459+
}
460+
461+
expectedPaths := tt.wantPaths
462+
463+
foundPathsSet := make(map[string]struct{})
464+
for _, p := range foundPathsRaw {
465+
foundPathsSet[p] = struct{}{}
466+
}
467+
468+
expectedPathsSet := make(map[string]struct{})
469+
for _, p := range expectedPaths {
470+
expectedPathsSet[p] = struct{}{}
471+
}
472+
473+
if !reflect.DeepEqual(foundPathsSet, expectedPathsSet) {
474+
t.Errorf("path mismatch:\n- want: %v\n- got: %v", expectedPaths, foundPathsRaw)
475+
}
431476
}
432477
})
433478
}

0 commit comments

Comments
 (0)