当前位置: 首页>>代码示例>>Golang>>正文


Golang etcd.NamespaceKeyFunc函数代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/registry/generic/etcd.NamespaceKeyFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang NamespaceKeyFunc函数的具体用法?Golang NamespaceKeyFunc怎么用?Golang NamespaceKeyFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NamespaceKeyFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestEtcdDeleteService

func TestEtcdDeleteService(t *testing.T) {
	ctx := api.NewDefaultContext()
	fakeClient := tools.NewFakeEtcdClient(t)
	registry := NewTestEtcdRegistryWithPods(fakeClient)
	key, _ := etcdgeneric.NamespaceKeyFunc(ctx, "/services/specs", "foo")
	key = etcdtest.AddPrefix(key)
	fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
	path, _ := etcdgeneric.NamespaceKeyFunc(ctx, "/services/endpoints", "foo")
	endpointsKey := etcdtest.AddPrefix(path)
	fakeClient.Set(endpointsKey, runtime.EncodeOrDie(latest.Codec, &api.Endpoints{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)

	err := registry.DeleteService(ctx, "foo")
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if len(fakeClient.DeletedKeys) != 2 {
		t.Errorf("Expected 2 delete, found %#v", fakeClient.DeletedKeys)
	}
	if fakeClient.DeletedKeys[0] != key {
		t.Errorf("Unexpected key: %s, expected %s", fakeClient.DeletedKeys[0], key)
	}
	if fakeClient.DeletedKeys[1] != endpointsKey {
		t.Errorf("Unexpected key: %s, expected %s", fakeClient.DeletedKeys[1], endpointsKey)
	}
}
开发者ID:keithtobin,项目名称:kubernetes,代码行数:26,代码来源:etcd_test.go

示例2: NewStorage

// NewStorage returns a RESTStorage object that will work against nodes.
func NewStorage(s storage.Interface) *REST {
	store := &etcdgeneric.Etcd{
		NewFunc:           func() runtime.Object { return &authorizationapi.Policy{} },
		NewListFunc:       func() runtime.Object { return &authorizationapi.PolicyList{} },
		QualifiedResource: authorizationapi.Resource("policy"),
		KeyRootFunc: func(ctx kapi.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, PolicyPath)
		},
		KeyFunc: func(ctx kapi.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, PolicyPath, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*authorizationapi.Policy).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return policy.Matcher(label, field)
		},

		CreateStrategy: policy.Strategy,
		UpdateStrategy: policy.Strategy,

		Storage: s,
	}

	return &REST{store}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:etcd.go

示例3: NewREST

// NewREST returns a registry which will store ThirdPartyResourceData in the given helper
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator, group, kind string) *REST {
	prefix := "/ThirdPartyResourceData/" + group + "/" + strings.ToLower(kind) + "s"

	// We explicitly do NOT do any decoration here yet.
	storageInterface := s

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &extensions.ThirdPartyResourceData{} },
		NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceDataList{} },
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*extensions.ThirdPartyResourceData).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return thirdpartyresourcedata.Matcher(label, field)
		},
		EndpointName:   "thirdpartyresourcedata",
		CreateStrategy: thirdpartyresourcedata.Strategy,
		UpdateStrategy: thirdpartyresourcedata.Strategy,

		Storage: storageInterface,
	}

	return &REST{store}
}
开发者ID:erinboyd,项目名称:origin,代码行数:31,代码来源:etcd.go

示例4: NewREST

// NewREST returns a RESTStorage object that will work against horizontal pod autoscalers.
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *REST {
	prefix := "/limitranges"

	newListFunc := func() runtime.Object { return &api.LimitRangeList{} }
	storageInterface := storageDecorator(
		s, 100, &api.LimitRange{}, prefix, limitrange.Strategy, newListFunc)

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.LimitRange{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.LimitRange).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return limitrange.MatchLimitRange(label, field)
		},
		QualifiedResource: api.Resource("limitranges"),

		CreateStrategy: limitrange.Strategy,
		UpdateStrategy: limitrange.Strategy,
		ExportStrategy: limitrange.Strategy,

		Storage: storageInterface,
	}
	return &REST{store}
}
开发者ID:XiaoningDing,项目名称:UbernetesPOC,代码行数:33,代码来源:etcd.go

示例5: NewREST

// NewREST returns a registry which will store ThirdPartyResourceData in the given helper
func NewREST(opts generic.RESTOptions, group, kind string) *REST {
	prefix := "/ThirdPartyResourceData/" + group + "/" + strings.ToLower(kind) + "s"

	// We explicitly do NOT do any decoration here yet.
	storageInterface := opts.Storage

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &extensions.ThirdPartyResourceData{} },
		NewListFunc: func() runtime.Object { return &extensions.ThirdPartyResourceDataList{} },
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*extensions.ThirdPartyResourceData).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return thirdpartyresourcedata.Matcher(label, field)
		},
		QualifiedResource:       extensions.Resource("thirdpartyresourcedatas"),
		DeleteCollectionWorkers: opts.DeleteCollectionWorkers,
		CreateStrategy:          thirdpartyresourcedata.Strategy,
		UpdateStrategy:          thirdpartyresourcedata.Strategy,
		DeleteStrategy:          thirdpartyresourcedata.Strategy,

		Storage: storageInterface,
	}

	return &REST{
		Etcd: store,
		kind: kind,
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:36,代码来源:etcd.go

示例6: NewREST

// NewREST returns a RESTStorage object that will work against pod templates.
func NewREST(opts generic.RESTOptions) *REST {
	prefix := "/podtemplates"

	newListFunc := func() runtime.Object { return &api.PodTemplateList{} }
	storageInterface := opts.Decorator(
		opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.PodTemplates), &api.PodTemplate{}, prefix, podtemplate.Strategy, newListFunc)

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.PodTemplate{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, name string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.PodTemplate).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return podtemplate.MatchPodTemplate(label, field)
		},
		QualifiedResource:       api.Resource("podtemplates"),
		DeleteCollectionWorkers: opts.DeleteCollectionWorkers,

		CreateStrategy: podtemplate.Strategy,
		UpdateStrategy: podtemplate.Strategy,
		ExportStrategy: podtemplate.Strategy,

		ReturnDeletedObject: true,

		Storage: storageInterface,
	}
	return &REST{store}
}
开发者ID:mataihang,项目名称:kubernetes,代码行数:36,代码来源:etcd.go

示例7: NewREST

// NewREST returns a RESTStorage object that will work against routes.
func NewREST(s storage.Interface, allocator route.RouteAllocator) RouteStorage {
	strategy := rest.NewStrategy(allocator)
	prefix := "/routes"
	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Route{} },
		NewListFunc: func() runtime.Object { return &api.RouteList{} },
		KeyRootFunc: func(ctx kapi.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx kapi.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Route).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return rest.Matcher(label, field)
		},
		EndpointName: "routes",

		CreateStrategy: strategy,
		UpdateStrategy: strategy,

		Storage: s,
	}
	return RouteStorage{
		Route:  &REST{store},
		Status: &StatusREST{store},
	}
}
开发者ID:johnmccawley,项目名称:origin,代码行数:31,代码来源:etcd.go

示例8: NewREST

// NewStorage returns a RESTStorage object that will work against Build objects.
func NewREST(s storage.Interface) (*REST, *DetailsREST) {
	prefix := "/builds"

	store := &etcdgeneric.Etcd{
		NewFunc:           func() runtime.Object { return &api.Build{} },
		NewListFunc:       func() runtime.Object { return &api.BuildList{} },
		QualifiedResource: api.Resource("builds"),
		KeyRootFunc: func(ctx kapi.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx kapi.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Build).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return build.Matcher(label, field)
		},
		CreateStrategy:      build.Strategy,
		UpdateStrategy:      build.Strategy,
		DeleteStrategy:      build.Strategy,
		Decorator:           build.Decorator,
		ReturnDeletedObject: false,
		Storage:             s,
	}

	detailsStore := *store
	detailsStore.UpdateStrategy = build.DetailsStrategy

	return &REST{store}, &DetailsREST{&detailsStore}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:etcd.go

示例9: NewREST

// NewREST returns a new REST.
func NewREST(s storage.Interface, defaultRegistry imagestream.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry) (*REST, *StatusREST) {
	prefix := "/imagestreams"
	store := etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.ImageStream{} },
		NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
		KeyRootFunc: func(ctx kapi.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx kapi.Context, name string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.ImageStream).Name, nil
		},
		EndpointName: "imageStream",

		ReturnDeletedObject: false,
		Storage:             s,
	}

	strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry)
	rest := &REST{subjectAccessReviewRegistry: subjectAccessReviewRegistry}
	strategy.ImageStreamGetter = rest

	statusStore := store
	statusStore.UpdateStrategy = imagestream.NewStatusStrategy(strategy)

	store.CreateStrategy = strategy
	store.UpdateStrategy = strategy
	store.Decorator = strategy.Decorate

	rest.store = &store

	return rest, &StatusREST{store: &statusStore}
}
开发者ID:jhadvig,项目名称:origin,代码行数:36,代码来源:etcd.go

示例10: NewREST

// NewREST returns a RESTStorage object that will work against secrets.
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator) *REST {
	prefix := "/secrets"

	newListFunc := func() runtime.Object { return &api.SecretList{} }
	storageInterface := storageDecorator(
		s, 100, &api.Secret{}, prefix, true, newListFunc)

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Secret{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Secret).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return secret.Matcher(label, field)
		},
		EndpointName: "secrets",

		CreateStrategy: secret.Strategy,
		UpdateStrategy: secret.Strategy,

		Storage: storageInterface,
	}
	return &REST{store}
}
开发者ID:erinboyd,项目名称:origin,代码行数:32,代码来源:etcd.go

示例11: NewREST

// NewREST returns a RESTStorage object that will work against routes.
func NewREST(s storage.Interface, allocator route.RouteAllocator) (*REST, *StatusREST) {
	strategy := rest.NewStrategy(allocator)
	prefix := "/routes"

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Route{} },
		NewListFunc: func() runtime.Object { return &api.RouteList{} },
		KeyRootFunc: func(ctx kapi.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx kapi.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Route).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return rest.Matcher(label, field)
		},
		QualifiedResource: api.Resource("routes"),

		CreateStrategy: strategy,
		UpdateStrategy: strategy,

		Storage: s,
	}

	statusStore := *store
	statusStore.UpdateStrategy = rest.StatusStrategy

	return &REST{store}, &StatusREST{&statusStore}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:33,代码来源:etcd.go

示例12: NewREST

// NewREST returns a RESTStorage object that will work against events.
func NewREST(s storage.Interface, storageDecorator generic.StorageDecorator, ttl uint64) *REST {
	prefix := "/events"

	// We explicitly do NOT do any decoration here - switching on Cacher
	// for events will lead to too high memory consumption.
	storageInterface := s

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Event{} },
		NewListFunc: func() runtime.Object { return &api.EventList{} },
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Event).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return event.MatchEvent(label, field)
		},
		TTLFunc: func(runtime.Object, uint64, bool) (uint64, error) {
			return ttl, nil
		},
		QualifiedResource: api.Resource("events"),

		CreateStrategy: event.Strategy,
		UpdateStrategy: event.Strategy,

		Storage: storageInterface,
	}
	return &REST{store}
}
开发者ID:johndmulhausen,项目名称:kubernetes,代码行数:35,代码来源:etcd.go

示例13: NewStorage

// NewStorage returns a RESTStorage object that will work against endpoints.
func NewStorage(s storage.Interface) *REST {
	prefix := "/services/endpoints"
	return &REST{
		&etcdgeneric.Etcd{
			NewFunc:     func() runtime.Object { return &api.Endpoints{} },
			NewListFunc: func() runtime.Object { return &api.EndpointsList{} },
			KeyRootFunc: func(ctx api.Context) string {
				return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
			},
			KeyFunc: func(ctx api.Context, name string) (string, error) {
				return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
			},
			ObjectNameFunc: func(obj runtime.Object) (string, error) {
				return obj.(*api.Endpoints).Name, nil
			},
			PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
				return endpoint.MatchEndpoints(label, field)
			},
			EndpointName: "endpoints",

			CreateStrategy: endpoint.Strategy,
			UpdateStrategy: endpoint.Strategy,

			Storage: s,
		},
	}
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:28,代码来源:etcd.go

示例14: NewREST

// NewREST returns a RESTStorage object that will work against secrets.
func NewREST(opts generic.RESTOptions) *REST {
	prefix := "/secrets"

	newListFunc := func() runtime.Object { return &api.SecretList{} }
	storageInterface := opts.Decorator(
		opts.Storage, cachesize.GetWatchCacheSizeByResource(cachesize.Secrets), &api.Secret{}, prefix, secret.Strategy, newListFunc)

	store := &etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Secret{} },
		NewListFunc: newListFunc,
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, id string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, id)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Secret).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return secret.Matcher(label, field)
		},
		QualifiedResource: api.Resource("secrets"),

		CreateStrategy: secret.Strategy,
		UpdateStrategy: secret.Strategy,

		Storage: storageInterface,
	}
	return &REST{store}
}
开发者ID:satnam6502,项目名称:kubernetes,代码行数:32,代码来源:etcd.go

示例15: NewREST

// NewREST returns a RESTStorage object that will work against services.
func NewREST(s storage.Interface) *REST {
	prefix := "/services/specs"
	store := etcdgeneric.Etcd{
		NewFunc:     func() runtime.Object { return &api.Service{} },
		NewListFunc: func() runtime.Object { return &api.ServiceList{} },
		KeyRootFunc: func(ctx api.Context) string {
			return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
		},
		KeyFunc: func(ctx api.Context, name string) (string, error) {
			return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
		},
		ObjectNameFunc: func(obj runtime.Object) (string, error) {
			return obj.(*api.Service).Name, nil
		},
		PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
			return MatchServices(label, field)
		},
		EndpointName: "services",

		CreateStrategy: rest.Services,
		UpdateStrategy: rest.Services,

		Storage: s,
	}
	return &REST{store}
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:27,代码来源:etcd.go


注:本文中的k8s/io/kubernetes/pkg/registry/generic/etcd.NamespaceKeyFunc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。