Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
3c8fbe39
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
3c8fbe39
编写于
7月 29, 2020
作者:
Z
zryfish
提交者:
GitHub
7月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix websocket lost query string bug (#2705)
Signed-off-by:
N
Jeff
<
zw0948@gmail.com
>
上级
388729e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
7 deletion
+25
-7
pkg/apiserver/dispatch/dispatch.go
pkg/apiserver/dispatch/dispatch.go
+9
-0
pkg/apiserver/filters/requestinfo.go
pkg/apiserver/filters/requestinfo.go
+16
-7
未找到文件。
pkg/apiserver/dispatch/dispatch.go
浏览文件 @
3c8fbe39
...
...
@@ -20,6 +20,7 @@ import (
"fmt"
corev1
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/httpstream"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/proxy"
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
...
...
@@ -159,6 +160,14 @@ func (c *clusterDispatch) Dispatch(w http.ResponseWriter, req *http.Request, han
if
len
(
u
.
Query
()[
"dryRun"
])
!=
0
{
req
.
URL
.
RawQuery
=
strings
.
Replace
(
req
.
URL
.
RawQuery
,
"dryRun"
,
"dryrun"
,
1
)
}
// kube-apiserver lost query string when proxy websocket requests, there are several issues opened
// tracking this, like https://github.com/kubernetes/kubernetes/issues/89360. Also there is a promising
// PR aim to fix this, but it's unlikely it will get merged soon. So here we are again. Put raw query
// string in Header and extract it on member cluster.
if
httpstream
.
IsUpgradeRequest
(
req
)
&&
len
(
req
.
URL
.
RawQuery
)
!=
0
{
req
.
Header
.
Set
(
"X-KubeSphere-Rawquery"
,
req
.
URL
.
RawQuery
)
}
}
else
{
// everything else goes to ks-apiserver, since our ks-apiserver has the ability to proxy kube-apiserver requests
...
...
pkg/apiserver/filters/requestinfo.go
浏览文件 @
3c8fbe39
...
...
@@ -26,13 +26,6 @@ import (
func
WithRequestInfo
(
handler
http
.
Handler
,
resolver
request
.
RequestInfoResolver
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
ctx
:=
req
.
Context
()
info
,
err
:=
resolver
.
NewRequestInfo
(
req
)
if
err
!=
nil
{
responsewriters
.
InternalError
(
w
,
req
,
fmt
.
Errorf
(
"failed to crate RequestInfo: %v"
,
err
))
return
}
// KubeSphere supports kube-apiserver proxy requests in multicluster mode. But kube-apiserver
// stripped all authorization headers. Use custom header to carry token to avoid losing authentication token.
// We may need a better way. See issue below.
...
...
@@ -54,6 +47,22 @@ func WithRequestInfo(handler http.Handler, resolver request.RequestInfoResolver)
req
.
URL
.
RawQuery
=
strings
.
Replace
(
req
.
URL
.
RawQuery
,
"dryrun"
,
"dryRun"
,
1
)
}
// kube-apiserver lost query string when proxy websocket requests, there are several issues opened
// tracking this, like https://github.com/kubernetes/kubernetes/issues/89360. Also there is a promising
// PR aim to fix this, but it's unlikely it will get merged soon. So here we are again. Put raw query
// string in Header and extract it on member cluster.
if
rawQuery
:=
req
.
Header
.
Get
(
"X-KubeSphere-Rawquery"
);
len
(
rawQuery
)
!=
0
&&
len
(
req
.
URL
.
RawQuery
)
==
0
{
req
.
URL
.
RawQuery
=
rawQuery
req
.
Header
.
Del
(
"X-KubeSphere-Rawquery"
)
}
ctx
:=
req
.
Context
()
info
,
err
:=
resolver
.
NewRequestInfo
(
req
)
if
err
!=
nil
{
responsewriters
.
InternalError
(
w
,
req
,
fmt
.
Errorf
(
"failed to crate RequestInfo: %v"
,
err
))
return
}
req
=
req
.
WithContext
(
request
.
WithRequestInfo
(
ctx
,
info
))
handler
.
ServeHTTP
(
w
,
req
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录