代码拉取完成,页面将自动刷新
package cluster
import (
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
v3 "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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。