37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nodeserver.go 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-02-22 22:10 . Local cluster support
package rkenodeconfigserver
import (
"net/http"
"encoding/json"
"github.com/rancher/rancher/pkg/tunnelserver"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
)
type RKENodeConfigServer struct {
auth *tunnelserver.Authorizer
}
func Handler(auth *tunnelserver.Authorizer) http.Handler {
return &RKENodeConfigServer{
auth: auth,
}
}
func (n *RKENodeConfigServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
client, ok, err := n.auth.Authorize(req)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
rw.Write([]byte(err.Error()))
return
}
if !ok {
rw.WriteHeader(http.StatusUnauthorized)
return
}
if client.Node == nil {
rw.WriteHeader(http.StatusNotFound)
return
}
if !client.Node.Spec.Imported || client.Cluster.Status.Driver != v3.ClusterDriverLocal {
rw.WriteHeader(http.StatusNotFound)
return
}
if client.Node.Status.NodeConfig == nil {
rw.WriteHeader(http.StatusServiceUnavailable)
}
nodeConfig, err := AgentConfig(req.Context(), *client.Node.Status.NodeConfig, client.Server, client.Token)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
rw.Write([]byte(err.Error()))
return
}
rw.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(rw).Encode(nodeConfig); err != nil {
logrus.Errorf("failed to write nodeConfig to agent: %v", err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha17

搜索帮助