Skip to content

Commit 7caff55

Browse files
committed
Add statusz to kubelet auth.
1 parent 902dedb commit 7caff55

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

pkg/kubelet/server/auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apiserver/pkg/server/healthz"
2828
utilfeature "k8s.io/apiserver/pkg/util/feature"
2929
"k8s.io/component-base/configz"
30+
"k8s.io/component-base/zpages/statusz"
3031
"k8s.io/klog/v2"
3132
"k8s.io/kubernetes/pkg/features"
3233
)
@@ -72,6 +73,7 @@ func isSubpath(subpath, path string) bool {
7273
// /runningPods/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=pods,proxy
7374
// /healthz/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=healthz,proxy
7475
// /configz => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=configz,proxy
76+
// /statusz => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=statusz,proxy
7577
func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http.Request) []authorizer.Attributes {
7678

7779
apiVerb := ""
@@ -99,6 +101,8 @@ func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *htt
99101
subresources = append(subresources, "healthz")
100102
case isSubpath(requestPath, configz.DefaultConfigzPath):
101103
subresources = append(subresources, "configz")
104+
case isSubpath(requestPath, statusz.DefaultStatuszPath):
105+
subresources = append(subresources, "statusz")
102106
// We put runningpods last since it will allocate a new string on every
103107
// check since the handler path has a trailing slash.
104108
case isSubpath(requestPath, runningPodsPath):

pkg/kubelet/server/auth_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func AuthzTestCases(fineGrained bool) []AuthzTestCase {
125125
"/attach/{podNamespace}/{podID}/{uid}/{containerName}": {"proxy"},
126126
"/checkpoint/{podNamespace}/{podID}/{containerName}": {"checkpoint"},
127127
"/configz": {"proxy"},
128+
"/statusz": {"proxy"},
128129
"/containerLogs/{podNamespace}/{podID}/{containerName}": {"proxy"},
129130
"/debug/flags/v": {"proxy"},
130131
"/debug/pprof/{subpath:*}": {"proxy"},
@@ -159,6 +160,7 @@ func AuthzTestCases(fineGrained bool) []AuthzTestCase {
159160
testPaths["/pods/"] = append([]string{"pods"}, testPaths["/pods/"]...)
160161
testPaths["/runningpods/"] = append([]string{"pods"}, testPaths["/runningpods/"]...)
161162
testPaths["/configz"] = append([]string{"configz"}, testPaths["/configz"]...)
163+
testPaths["/statusz"] = append([]string{"statusz"}, testPaths["/statusz"]...)
162164
}
163165

164166
testCases := []AuthzTestCase{}

pkg/kubelet/server/server_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ func TestAuthzCoverage(t *testing.T) {
573573
func TestAuthFilters(t *testing.T) {
574574
// Enable features.ContainerCheckpoint during test
575575
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ContainerCheckpoint, true)
576+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, zpagesfeatures.ComponentStatusz, true)
576577

577578
fw := newServerTest()
578579
defer fw.testHTTPServer.Close()

staging/src/k8s.io/component-base/zpages/statusz/statusz.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var (
3535
errUnsupportedMediaType = fmt.Errorf("media type not acceptable, must be: text/plain")
3636
)
3737

38+
const DefaultStatuszPath = "/statusz"
39+
3840
const (
3941
headerFmt = `
4042
%s statusz
@@ -73,7 +75,7 @@ func Install(m mux, componentName string, reg statuszRegistry) {
7375
klog.Errorf("error while parsing gotemplates: %v", err)
7476
return
7577
}
76-
m.Handle("/statusz", handleStatusz(componentName, dataTmpl, reg))
78+
m.Handle(DefaultStatuszPath, handleStatusz(componentName, dataTmpl, reg))
7779
}
7880

7981
func initializeTemplates() (*template.Template, error) {

0 commit comments

Comments
 (0)