36 Star 412 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
app
chart
cleanup
package
pkg
agent
api
controllers
customization
alert
app
authn
catalog
cluster
actionhandler.go
formatter.go
shell.go
validator.go
clusterregistrationtokens
cred
globaldns
globalnamespaceaccess
globalresource
kontainerdriver
logging
monitor
multiclusterapp
namespace
node
nodetemplate
pipeline
podsecuritypolicytemplate
project
roletemplate
roletemplatebinding
setting
workload
yaml
server
store
server.go
audit
auth
catalog
cert
clustermanager
clusterprovisioninglogger
clusterrouter
configfield
controllers
dialer
dynamiclistener
encryptedstore
httpproxy
image
k8slookup
k8sproxy
kubeconfig
kubectl
librke
logserver
monitoring
namespace
node
nodeconfig
notifiers
pipeline
project
randomtoken
rbac
ref
resourcelink
resourcequota
rkecerts
rkedialerfactory
rkenodeconfigclient
rkenodeconfigserver
rkeworker
settings
systemaccount
systemtemplate
telemetry
ticker
tls
tunnelserver
rke-templates
scripts
server
tests
vendor
.dockerignore
.drone.yml
.gitignore
.gometalinter.json
CONTRIBUTING.md
Dockerfile.dapper
LICENSE
Makefile
README.md
README_1_6.md
code-of-conduct.md
keybase.md
main.go
vendor.conf
克隆/下载
validator.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
package cluster
import (
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
type Validator struct {
ClusterLister v3.ClusterLister
}
func (v *Validator) Validator(request *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
var spec v3.ClusterSpec
if err := convert.ToObj(data, &spec); err != nil {
return httperror.WrapAPIError(err, httperror.InvalidBodyContent, "Cluster spec conversion error")
}
if err := v.validateLocalClusterAuthEndpoint(request, &spec); err != nil {
return err
}
return nil
}
func (v *Validator) validateLocalClusterAuthEndpoint(request *types.APIContext, spec *v3.ClusterSpec) error {
if !spec.LocalClusterAuthEndpoint.Enabled {
return nil
}
var isValidCluster bool
if request.ID == "" {
isValidCluster = spec.RancherKubernetesEngineConfig != nil
} else {
cluster, err := v.ClusterLister.Get("", request.ID)
if err != nil {
return err
}
isValidCluster = cluster.Status.Driver == "" ||
cluster.Status.Driver == v3.ClusterDriverRKE ||
cluster.Status.Driver == v3.ClusterDriverImported
}
if !isValidCluster {
return httperror.NewFieldAPIError(httperror.InvalidState, "LocalClusterAuthEndpoint.Enabled", "Can only enable LocalClusterAuthEndpoint with RKE")
}
if spec.LocalClusterAuthEndpoint.CACerts != "" && spec.LocalClusterAuthEndpoint.FQDN == "" {
return httperror.NewFieldAPIError(httperror.MissingRequired, "LocalClusterAuthEndpoint.FQDN", "CACerts defined but FQDN is not defined")
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.2-rc6

搜索帮助