k8s/io/kubernetes/pkg/api.ValidNamespace 示例代码

2022-03-03

以下示例是关于golang中包含api.ValidNamespace用法的示例代码,想了解api.ValidNamespace的具体用法?api.ValidNamespace怎么用?api.ValidNamespace使用的例子?那么可以参考以下10个相关示例代码来学习它的具体使用方法。

示例1:
context_test.go开发语言: Go项目名称: kubernetes代码行数: 69
47	resource := api.ReplicationController{}
48	if !api.ValidNamespace(ctx, &resource.ObjectMeta) {
49		t.Errorf("expected success")
54	resource = api.ReplicationController{ObjectMeta: api.ObjectMeta{Namespace: "other"}}
55	if api.ValidNamespace(ctx, &resource.ObjectMeta) {
56		t.Errorf("Expected error that resource and context errors do not match because resource has different namespace")
58	ctx = api.NewContext()
59	if api.ValidNamespace(ctx, &resource.ObjectMeta) {
60		t.Errorf("Expected error that resource and context errors do not match since context has no namespace")
示例2:
context_test.go开发语言: Go项目名称: kubernetes代码行数: 69
47	resource := api.ReplicationController{}
48	if !api.ValidNamespace(ctx, &resource.TypeMeta) {
49		t.Errorf("expected success")
54	resource = api.ReplicationController{TypeMeta: api.TypeMeta{Namespace: "other"}}
55	if api.ValidNamespace(ctx, &resource.TypeMeta) {
56		t.Errorf("Expected error that resource and context errors do not match because resource has different namespace")
58	ctx = api.NewContext()
59	if api.ValidNamespace(ctx, &resource.TypeMeta) {
60		t.Errorf("Expected error that resource and context errors do not match since context has no namespace")
示例3:
examples_test.go开发语言: Go项目名称: kubernetes代码行数: 233
49		}
50		api.ValidNamespace(ctx, &t.ObjectMeta)
51		errors = validation.ValidateService(t)
59		}
60		api.ValidNamespace(ctx, &t.ObjectMeta)
61		errors = validation.ValidatePod(t)
示例4:
examples_test.go开发语言: Go项目名称: kubernetes代码行数: 193
43	case *api.Service:
44		api.ValidNamespace(ctx, &t.TypeMeta)
45		errors = validation.ValidateService(t)
50	case *api.Pod:
51		api.ValidNamespace(ctx, &t.TypeMeta)
52		errors = validation.ValidateManifest(&t.DesiredState.Manifest)
示例5:
rest.go开发语言: Go项目名称: kubernetes代码行数: 324
92	pod := obj.(*api.Pod)
93	if !api.ValidNamespace(ctx, &pod.TypeMeta) {
94		return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
188	pod := obj.(*api.Pod)
189	if !api.ValidNamespace(ctx, &pod.TypeMeta) {
190		return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
示例6:
rest.go开发语言: Go项目名称: kubernetes代码行数: 163
51
52	if !api.ValidNamespace(ctx, &secret.ObjectMeta) {
53		return nil, errors.NewConflict("secret", secret.Namespace, fmt.Errorf("Secret.Namespace does not match the provided context"))
78
79	if !api.ValidNamespace(ctx, &secret.ObjectMeta) {
80		return nil, false, errors.NewConflict("secret", secret.Namespace, fmt.Errorf("Secret.Namespace does not match the provided context"))
示例7:
rest.go开发语言: Go项目名称: kubernetes代码行数: 153
51
52	if !api.ValidNamespace(ctx, &limitRange.ObjectMeta) {
53		return nil, errors.NewConflict("limitRange", limitRange.Namespace, fmt.Errorf("LimitRange.Namespace does not match the provided context"))
78
79	if !api.ValidNamespace(ctx, &limitRange.ObjectMeta) {
80		return nil, false, errors.NewConflict("limitRange", limitRange.Namespace, fmt.Errorf("LimitRange.Namespace does not match the provided context"))
示例8:
rest.go开发语言: Go项目名称: kubernetes代码行数: 151
49	if api.NamespaceValue(ctx) != "" {
50		if !api.ValidNamespace(ctx, &event.ObjectMeta) {
51			return nil, errors.NewConflict("event", event.Namespace, fmt.Errorf("event.namespace does not match the provided context"))
72	if api.NamespaceValue(ctx) != "" {
73		if !api.ValidNamespace(ctx, &event.ObjectMeta) {
74			return nil, false, errors.NewConflict("event", event.Namespace, fmt.Errorf("event.namespace does not match the provided context"))
示例9:
rest.go开发语言: Go项目名称: kubernetes代码行数: 156
51
52	if !api.ValidNamespace(ctx, &resourceQuota.ObjectMeta) {
53		return nil, errors.NewConflict("resourceQuota", resourceQuota.Namespace, fmt.Errorf("ResourceQuota.Namespace does not match the provided context"))
81
82	if !api.ValidNamespace(ctx, &resourceQuota.ObjectMeta) {
83		return nil, false, errors.NewConflict("resourceQuota", resourceQuota.Namespace, fmt.Errorf("ResourceQuota.Namespace does not match the provided context"))
示例10:
context_test.go开发语言: Go项目名称: cjcullen代码行数: 68
47	resource := api.ReplicationController{}
48	if !api.ValidNamespace(ctx, &resource.ObjectMeta) {
49		t.Errorf("expected success")
54	resource = api.ReplicationController{ObjectMeta: api.ObjectMeta{Namespace: "other"}}
55	if api.ValidNamespace(ctx, &resource.ObjectMeta) {
56		t.Errorf("Expected error that resource and context errors do not match because resource has different namespace")
58	ctx = api.NewContext()
59	if api.ValidNamespace(ctx, &resource.ObjectMeta) {
60		t.Errorf("Expected error that resource and context errors do not match since context has no namespace")

本文地址:https://www.itbaoku.cn/snippets/415637.html