make generic proxy can be marked as deprecated

Signed-off-by: zhu733756 <zhu733756@kubesphere.io>
This commit is contained in:
zhu733756
2022-01-17 16:18:17 +08:00
parent b6e960766a
commit e42d9517b7
2 changed files with 13 additions and 0 deletions

View File

@@ -41,6 +41,9 @@ type genericProxy struct {
// api version
Version string
// mark as desprecated
desprecated bool
}
func NewGenericProxy(endpoint string, groupName string, version string) (*genericProxy, error) {
@@ -59,6 +62,10 @@ func NewGenericProxy(endpoint string, groupName string, version string) (*generi
}, nil
}
func (g *genericProxy) SetProxyDesprecated() {
g.desprecated = true
}
// currently, we only support proxy GET/PUT/POST/DELETE/PATCH.
// Maybe we can try another way to implement proxy.
func (g *genericProxy) AddToContainer(container *restful.Container) error {
@@ -93,6 +100,10 @@ func (g *genericProxy) AddToContainer(container *restful.Container) error {
}
func (g *genericProxy) handler(request *restful.Request, response *restful.Response) {
if g.desprecated {
klog.Warning(fmt.Sprintf("This proxy group %s has deprecated", g.GroupName))
}
u := g.makeURL(request)
httpProxy := proxy.NewUpgradeAwareHandler(u, http.DefaultTransport, false, false, &errorResponder{})

View File

@@ -33,5 +33,7 @@ func AddToContainer(container *restful.Container, endpoint string) error {
return nil
}
proxy.SetProxyDesprecated()
return proxy.AddToContainer(container)
}