mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-30 06:09:11 +00:00
Unify ComponentKubelet and add unit tests.
This commit is contained in:
parent
a04df83f86
commit
816cd40280
@ -132,14 +132,9 @@ func init() {
|
|||||||
otel.SetMeterProvider(noop.NewMeterProvider())
|
otel.SetMeterProvider(noop.NewMeterProvider())
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
// Kubelet component name
|
|
||||||
componentKubelet = "kubelet"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewKubeletCommand creates a *cobra.Command object with default parameters
|
// NewKubeletCommand creates a *cobra.Command object with default parameters
|
||||||
func NewKubeletCommand() *cobra.Command {
|
func NewKubeletCommand() *cobra.Command {
|
||||||
cleanFlagSet := pflag.NewFlagSet(componentKubelet, pflag.ContinueOnError)
|
cleanFlagSet := pflag.NewFlagSet(server.ComponentKubelet, pflag.ContinueOnError)
|
||||||
cleanFlagSet.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
cleanFlagSet.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
kubeletFlags := options.NewKubeletFlags()
|
kubeletFlags := options.NewKubeletFlags()
|
||||||
|
|
||||||
@ -151,7 +146,7 @@ func NewKubeletCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: componentKubelet,
|
Use: server.ComponentKubelet,
|
||||||
Long: `The kubelet is the primary "node agent" that runs on each
|
Long: `The kubelet is the primary "node agent" that runs on each
|
||||||
node. It can register the node with the apiserver using one of: the hostname; a flag to
|
node. It can register the node with the apiserver using one of: the hostname; a flag to
|
||||||
override the hostname; or specific logic for a cloud provider.
|
override the hostname; or specific logic for a cloud provider.
|
||||||
@ -562,7 +557,7 @@ func makeEventRecorder(ctx context.Context, kubeDeps *kubelet.Dependencies, node
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
eventBroadcaster := record.NewBroadcaster(record.WithContext(ctx))
|
eventBroadcaster := record.NewBroadcaster(record.WithContext(ctx))
|
||||||
kubeDeps.Recorder = eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: componentKubelet, Host: string(nodeName)})
|
kubeDeps.Recorder = eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: server.ComponentKubelet, Host: string(nodeName)})
|
||||||
eventBroadcaster.StartStructuredLogging(3)
|
eventBroadcaster.StartStructuredLogging(3)
|
||||||
if kubeDeps.EventClient != nil {
|
if kubeDeps.EventClient != nil {
|
||||||
klog.V(4).InfoS("Sending events to api server")
|
klog.V(4).InfoS("Sending events to api server")
|
||||||
@ -1386,7 +1381,7 @@ func newTracerProvider(s *options.KubeletServer) (oteltrace.TracerProvider, erro
|
|||||||
}
|
}
|
||||||
resourceOpts := []otelsdkresource.Option{
|
resourceOpts := []otelsdkresource.Option{
|
||||||
otelsdkresource.WithAttributes(
|
otelsdkresource.WithAttributes(
|
||||||
semconv.ServiceNameKey.String(componentKubelet),
|
semconv.ServiceNameKey.String(server.ComponentKubelet),
|
||||||
semconv.HostNameKey.String(hostname),
|
semconv.HostNameKey.String(hostname),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -107,8 +107,11 @@ const (
|
|||||||
debugFlagPath = "/debug/flags/v"
|
debugFlagPath = "/debug/flags/v"
|
||||||
podsPath = "/pods"
|
podsPath = "/pods"
|
||||||
runningPodsPath = "/runningpods/"
|
runningPodsPath = "/runningpods/"
|
||||||
|
)
|
||||||
|
|
||||||
kubeletComponent = "kubelet"
|
const (
|
||||||
|
// Kubelet component name
|
||||||
|
ComponentKubelet = "kubelet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is a http.Handler which exposes kubelet functionality over HTTP.
|
// Server is a http.Handler which exposes kubelet functionality over HTTP.
|
||||||
@ -411,7 +414,8 @@ func (s *Server) InstallDefaultHandlers() {
|
|||||||
healthz.InstallHandler(s.restfulCont, checkers...)
|
healthz.InstallHandler(s.restfulCont, checkers...)
|
||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
|
if utilfeature.DefaultFeatureGate.Enabled(zpagesfeatures.ComponentStatusz) {
|
||||||
statusz.Install(s.restfulCont, kubeletComponent, statusz.NewRegistry())
|
s.addMetricsBucketMatcher("statusz")
|
||||||
|
statusz.Install(s.restfulCont, ComponentKubelet, statusz.NewRegistry())
|
||||||
}
|
}
|
||||||
|
|
||||||
slis.SLIMetricsWithReset{}.Install(s.restfulCont)
|
slis.SLIMetricsWithReset{}.Install(s.restfulCont)
|
||||||
|
@ -57,6 +57,7 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/server/healthz"
|
"k8s.io/apiserver/pkg/server/healthz"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
|
zpagesfeatures "k8s.io/component-base/zpages/features"
|
||||||
"k8s.io/kubelet/pkg/cri/streaming"
|
"k8s.io/kubelet/pkg/cri/streaming"
|
||||||
"k8s.io/kubelet/pkg/cri/streaming/portforward"
|
"k8s.io/kubelet/pkg/cri/streaming/portforward"
|
||||||
remotecommandserver "k8s.io/kubelet/pkg/cri/streaming/remotecommand"
|
remotecommandserver "k8s.io/kubelet/pkg/cri/streaming/remotecommand"
|
||||||
@ -1648,9 +1649,11 @@ func TestMetricBuckets(t *testing.T) {
|
|||||||
"runningpods": {url: "/runningpods/", bucket: "runningpods"},
|
"runningpods": {url: "/runningpods/", bucket: "runningpods"},
|
||||||
"stats": {url: "/stats/", bucket: "stats"},
|
"stats": {url: "/stats/", bucket: "stats"},
|
||||||
"stats summary sub": {url: "/stats/summary", bucket: "stats"},
|
"stats summary sub": {url: "/stats/summary", bucket: "stats"},
|
||||||
|
"statusz": {url: "/statusz", bucket: "statusz"},
|
||||||
"invalid path": {url: "/junk", bucket: "other"},
|
"invalid path": {url: "/junk", bucket: "other"},
|
||||||
"invalid path starting with good": {url: "/healthzjunk", bucket: "other"},
|
"invalid path starting with good": {url: "/healthzjunk", bucket: "other"},
|
||||||
}
|
}
|
||||||
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, zpagesfeatures.ComponentStatusz, true)
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
defer fw.testHTTPServer.Close()
|
defer fw.testHTTPServer.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user