代码拉取完成,页面将自动刷新
package kontainerdriver
import (
"fmt"
"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"
"k8s.io/apimachinery/pkg/labels"
)
type Validator struct {
KontainerDriverLister v3.KontainerDriverLister
}
func (v *Validator) Validator(request *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
var spec v3.KontainerDriverSpec
if err := convert.ToObj(data, &spec); err != nil {
return httperror.WrapAPIError(err, httperror.InvalidBodyContent, "Kontainer driver spec conversion error")
}
return v.validateKontainerDriverURL(request, spec)
}
func (v *Validator) validateKontainerDriverURL(request *types.APIContext, spec v3.KontainerDriverSpec) error {
kontainerDrivers, err := v.KontainerDriverLister.List("", labels.NewSelector())
if err != nil {
return httperror.WrapAPIError(err, httperror.ServerError, "Failed to list kontainer drivers")
}
for _, driver := range kontainerDrivers {
if driver.Spec.URL == spec.URL && driver.Name != request.ID {
return httperror.NewAPIError(httperror.Conflict, fmt.Sprintf("Driver URL already in use: %s", spec.URL))
}
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。