本文整理汇总了Golang中k8s/io/kubernetes/pkg/api/validation.ValidateService函数的典型用法代码示例。如果您正苦于以下问题:Golang ValidateService函数的具体用法?Golang ValidateService怎么用?Golang ValidateService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ValidateService函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCompatibility_v1_Service
func TestCompatibility_v1_Service(t *testing.T) {
// Test "spec.portalIP" -> "spec.clusterIP"
expectedIP := "1.2.3.4"
// Test "tcp" protocol gets converted to "TCP" and validated
originalProtocol := "tcp"
expectedProtocol := "TCP"
input := []byte(fmt.Sprintf(`
{
"kind":"Service",
"apiVersion":"v1",
"metadata":{"name":"my-service-name", "namespace":"my-service-namespace"},
"spec": {
"portalIP":"%s",
"ports":[{"port":1,"protocol":"%s"}]
}
}
`, expectedIP, originalProtocol))
t.Log("Testing 1.0.0 v1 migration added in PR #3592")
testCompatibility(
t, "v1", input,
func(obj runtime.Object) fielderrors.ValidationErrorList {
return validation.ValidateService(obj.(*api.Service))
},
map[string]string{
"spec.portalIP": expectedIP,
"spec.clusterIP": expectedIP,
"spec.ports[0].protocol": expectedProtocol,
},
)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:32,代码来源:compatibility_test.go
示例2: validateObject
func validateObject(path string, obj runtime.Object, t *testing.T) {
// if an object requires a namespace server side, be sure that it is filled in for validation
if validation.HasObjectMeta(obj) {
namespaceRequired, err := validation.GetRequiresNamespace(obj)
if err != nil {
t.Errorf("Expected no error, Got %v", err)
return
}
if namespaceRequired {
objectMeta, err := kapi.ObjectMetaFor(obj)
if err != nil {
t.Errorf("Expected no error, Got %v", err)
return
}
objectMeta.Namespace = kapi.NamespaceDefault
}
}
switch typedObj := obj.(type) {
case *kapi.Pod:
if errors := kvalidation.ValidatePod(typedObj); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors)
}
case *kapi.Service:
if errors := kvalidation.ValidateService(typedObj); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors)
}
case *kapi.List, *imageapi.ImageStreamList:
if list, err := runtime.ExtractList(typedObj); err == nil {
runtime.DecodeList(list, kapi.Scheme)
for i := range list {
validateObject(path, list[i], t)
}
} else {
t.Errorf("Expected no error, Got %v", err)
}
default:
if errors := validation.Validator.Validate(obj); len(errors) > 0 {
t.Errorf("%s with %v did not validate correctly: %v", path, reflect.TypeOf(obj), errors)
}
}
}
开发者ID:ncantor,项目名称:origin,代码行数:50,代码来源:examples_test.go
示例3: Validate
// Validate validates a new service.
func (svcStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
service := obj.(*api.Service)
return validation.ValidateService(service)
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:5,代码来源:strategy.go
示例4: validateObject
func validateObject(obj runtime.Object) (errors field.ErrorList) {
switch t := obj.(type) {
case *api.ReplicationController:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateReplicationController(t)
case *api.ReplicationControllerList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Service:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateService(t)
case *api.ServiceList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Pod:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePod(t)
case *api.PodList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.PersistentVolume:
errors = validation.ValidatePersistentVolume(t)
case *api.PersistentVolumeClaim:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePersistentVolumeClaim(t)
case *api.PodTemplate:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePodTemplate(t)
case *api.Endpoints:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateEndpoints(t)
case *api.Namespace:
errors = validation.ValidateNamespace(t)
case *api.Secret:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateSecret(t)
case *api.LimitRange:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateLimitRange(t)
case *api.ResourceQuota:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateResourceQuota(t)
case *extensions.Deployment:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateDeployment(t)
case *extensions.Job:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateJob(t)
case *extensions.Ingress:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateIngress(t)
case *extensions.DaemonSet:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateDaemonSet(t)
default:
return field.ErrorList{field.InternalError(field.NewPath(""), fmt.Errorf("no validation defined for %#v", obj))}
}
return errors
}
开发者ID:koori02,项目名称:kubernetes,代码行数:88,代码来源:examples_test.go
示例5: validateObject
func validateObject(obj runtime.Object) (errors []error) {
switch t := obj.(type) {
case *api.ReplicationController:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateReplicationController(t)
case *api.ReplicationControllerList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Service:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateService(t)
case *api.ServiceList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Pod:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePod(t)
case *api.PodList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.PersistentVolume:
errors = validation.ValidatePersistentVolume(t)
case *api.PersistentVolumeClaim:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePersistentVolumeClaim(t)
case *api.PodTemplate:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePodTemplate(t)
case *api.Endpoints:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateEndpoints(t)
case *api.Namespace:
errors = validation.ValidateNamespace(t)
case *api.Secret:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateSecret(t)
case *api.LimitRange:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateLimitRange(t)
case *api.ResourceQuota:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateResourceQuota(t)
default:
return []error{fmt.Errorf("no validation defined for %#v", obj)}
}
return errors
}
开发者ID:swarmanetes,项目名称:kubernetes,代码行数:68,代码来源:examples_test.go
示例6: validateObject
func validateObject(obj runtime.Object) (errors field.ErrorList) {
switch t := obj.(type) {
case *api.ReplicationController:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateReplicationController(t)
case *api.ReplicationControllerList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Service:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateService(t)
case *api.ServiceList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.Pod:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePod(t)
case *api.PodList:
for i := range t.Items {
errors = append(errors, validateObject(&t.Items[i])...)
}
case *api.PersistentVolume:
errors = validation.ValidatePersistentVolume(t)
case *api.PersistentVolumeClaim:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePersistentVolumeClaim(t)
case *api.PodTemplate:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidatePodTemplate(t)
case *api.Endpoints:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateEndpoints(t)
case *api.Namespace:
errors = validation.ValidateNamespace(t)
case *api.Secret:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateSecret(t)
case *api.LimitRange:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateLimitRange(t)
case *api.ResourceQuota:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = validation.ValidateResourceQuota(t)
case *extensions.Deployment:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateDeployment(t)
case *extensions.Job:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
// Job needs generateSelector called before validation, and job.Validate does this.
// See: https://github.com/kubernetes/kubernetes/issues/20951#issuecomment-187787040
t.ObjectMeta.UID = types.UID("fakeuid")
errors = job.Strategy.Validate(nil, t)
case *extensions.Ingress:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateIngress(t)
case *extensions.DaemonSet:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
}
errors = expvalidation.ValidateDaemonSet(t)
default:
errors = field.ErrorList{}
errors = append(errors, field.InternalError(field.NewPath(""), fmt.Errorf("no validation defined for %#v", obj)))
}
return errors
}
开发者ID:jeremyeder,项目名称:kubernetes,代码行数:92,代码来源:examples_test.go
注:本文中的k8s/io/kubernetes/pkg/api/validation.ValidateService函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论