Skip to content

Commit

Permalink
intercept kubelet get node request in order to reduce the traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
rambohe-ch authored and vie-serendipity committed May 6, 2024
1 parent 37addb5 commit 18b6383
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/yurthub/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func (p *yurtReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)
switch {
case util.IsKubeletLeaseReq(req):
p.handleKubeletLease(rw, req)
case util.IsKubeletGetNodeReq(req):
if p.localProxy != nil {
p.localProxy.ServeHTTP(rw, req)
} else {
p.loadBalancer.ServeHTTP(rw, req)
}
case util.IsEventCreateRequest(req):
p.eventHandler(rw, req)
case util.IsPoolScopedResouceListWatchRequest(req):
Expand Down
12 changes: 12 additions & 0 deletions pkg/yurthub/proxy/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,18 @@ func IsKubeletLeaseReq(req *http.Request) bool {
return true
}

// IsKubeletGetNodeReq judge whether the request is a get node request from kubelet
func IsKubeletGetNodeReq(req *http.Request) bool {
ctx := req.Context()
if comp, ok := util.ClientComponentFrom(ctx); !ok || comp != "kubelet" {
return false

Check warning on line 422 in pkg/yurthub/proxy/util/util.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurthub/proxy/util/util.go#L419-L422

Added lines #L419 - L422 were not covered by tests
}
if info, ok := apirequest.RequestInfoFrom(ctx); !ok || info.Resource != "nodes" || info.Verb != "get" {
return false

Check warning on line 425 in pkg/yurthub/proxy/util/util.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurthub/proxy/util/util.go#L424-L425

Added lines #L424 - L425 were not covered by tests
}
return true

Check warning on line 427 in pkg/yurthub/proxy/util/util.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurthub/proxy/util/util.go#L427

Added line #L427 was not covered by tests
}

// WriteObject write object to response writer
func WriteObject(statusCode int, obj runtime.Object, w http.ResponseWriter, req *http.Request) error {
ctx := req.Context()
Expand Down

0 comments on commit 18b6383

Please sign in to comment.