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


Golang GroupVersion.WithResource方法代码示例

本文整理汇总了Golang中k8s/io/apimachinery/pkg/runtime/schema.GroupVersion.WithResource方法的典型用法代码示例。如果您正苦于以下问题:Golang GroupVersion.WithResource方法的具体用法?Golang GroupVersion.WithResource怎么用?Golang GroupVersion.WithResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在k8s/io/apimachinery/pkg/runtime/schema.GroupVersion的用法示例。


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

示例1: TestKindToResource

func TestKindToResource(t *testing.T) {
	testCases := []struct {
		Kind             string
		Plural, Singular string
	}{
		{Kind: "Pod", Plural: "pods", Singular: "pod"},

		{Kind: "ReplicationController", Plural: "replicationcontrollers", Singular: "replicationcontroller"},

		// Add "ies" when ending with "y"
		{Kind: "ImageRepository", Plural: "imagerepositories", Singular: "imagerepository"},
		// Add "es" when ending with "s"
		{Kind: "miss", Plural: "misses", Singular: "miss"},
		// Add "s" otherwise
		{Kind: "lowercase", Plural: "lowercases", Singular: "lowercase"},
	}
	for i, testCase := range testCases {
		version := schema.GroupVersion{}

		plural, singular := KindToResource(version.WithKind(testCase.Kind))
		if singular != version.WithResource(testCase.Singular) || plural != version.WithResource(testCase.Plural) {
			t.Errorf("%d: unexpected plural and singular: %v %v", i, plural, singular)
		}
	}
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:25,代码来源:restmapper_test.go

示例2: storage

func (p RESTStorageProvider) storage(version schema.GroupVersion, apiResourceConfigSource genericapiserver.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) map[string]rest.Storage {
	once := new(sync.Once)
	var (
		authorizationRuleResolver  rbacregistryvalidation.AuthorizationRuleResolver
		rolesStorage               rest.StandardStorage
		roleBindingsStorage        rest.StandardStorage
		clusterRolesStorage        rest.StandardStorage
		clusterRoleBindingsStorage rest.StandardStorage
	)

	initializeStorage := func() {
		once.Do(func() {
			rolesStorage = rolestore.NewREST(restOptionsGetter)
			roleBindingsStorage = rolebindingstore.NewREST(restOptionsGetter)
			clusterRolesStorage = clusterrolestore.NewREST(restOptionsGetter)
			clusterRoleBindingsStorage = clusterrolebindingstore.NewREST(restOptionsGetter)

			authorizationRuleResolver = rbacregistryvalidation.NewDefaultRuleResolver(
				role.AuthorizerAdapter{Registry: role.NewRegistry(rolesStorage)},
				rolebinding.AuthorizerAdapter{Registry: rolebinding.NewRegistry(roleBindingsStorage)},
				clusterrole.AuthorizerAdapter{Registry: clusterrole.NewRegistry(clusterRolesStorage)},
				clusterrolebinding.AuthorizerAdapter{Registry: clusterrolebinding.NewRegistry(clusterRoleBindingsStorage)},
			)
		})
	}

	storage := map[string]rest.Storage{}
	if apiResourceConfigSource.ResourceEnabled(version.WithResource("roles")) {
		initializeStorage()
		storage["roles"] = rolepolicybased.NewStorage(rolesStorage, authorizationRuleResolver)
	}
	if apiResourceConfigSource.ResourceEnabled(version.WithResource("rolebindings")) {
		initializeStorage()
		storage["rolebindings"] = rolebindingpolicybased.NewStorage(roleBindingsStorage, p.Authorizer, authorizationRuleResolver)
	}
	if apiResourceConfigSource.ResourceEnabled(version.WithResource("clusterroles")) {
		initializeStorage()
		storage["clusterroles"] = clusterrolepolicybased.NewStorage(clusterRolesStorage, authorizationRuleResolver)
	}
	if apiResourceConfigSource.ResourceEnabled(version.WithResource("clusterrolebindings")) {
		initializeStorage()
		storage["clusterrolebindings"] = clusterrolebindingpolicybased.NewStorage(clusterRoleBindingsStorage, p.Authorizer, authorizationRuleResolver)
	}
	return storage
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:45,代码来源:storage_rbac.go

示例3: TestDisabledVersion

func TestDisabledVersion(t *testing.T) {
	g1v1 := schema.GroupVersion{Group: "group1", Version: "version1"}
	g1v2 := schema.GroupVersion{Group: "group1", Version: "version2"}
	g2v1 := schema.GroupVersion{Group: "group2", Version: "version1"}
	g3v1 := schema.GroupVersion{Group: "group3", Version: "version1"}

	resourceType := "the-resource"
	disabledResourceType := "the-disabled-resource"

	config := NewResourceConfig()

	config.DisableVersions(g1v1)
	config.EnableVersions(g1v2, g3v1)
	config.EnableResources(g1v1.WithResource(resourceType), g2v1.WithResource(resourceType))
	config.DisableResources(g1v2.WithResource(disabledResourceType))

	expectedEnabledResources := []schema.GroupVersionResource{
		g1v2.WithResource(resourceType),
		g2v1.WithResource(resourceType),
	}
	expectedDisabledResources := []schema.GroupVersionResource{
		g1v1.WithResource(resourceType), g1v1.WithResource(disabledResourceType),
		g1v2.WithResource(disabledResourceType),
		g2v1.WithResource(disabledResourceType),
	}

	for _, expectedResource := range expectedEnabledResources {
		if !config.ResourceEnabled(expectedResource) {
			t.Errorf("expected enabled for %v, from %v", expectedResource, config)
		}
	}
	for _, expectedResource := range expectedDisabledResources {
		if config.ResourceEnabled(expectedResource) {
			t.Errorf("expected disabled for %v, from %v", expectedResource, config)
		}
	}

	if e, a := false, config.AnyResourcesForVersionEnabled(g1v1); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}
	if e, a := false, config.AllResourcesForVersionEnabled(g1v1); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}
	if e, a := true, config.AnyResourcesForVersionEnabled(g1v2); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}
	if e, a := false, config.AllResourcesForVersionEnabled(g1v2); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}
	if e, a := true, config.AnyResourcesForVersionEnabled(g3v1); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}
	if e, a := true, config.AllResourcesForVersionEnabled(g3v1); e != a {
		t.Errorf("expected %v, got %v", e, a)
	}

	expectedEnabledAnyVersionResources := []schema.GroupResource{
		{Group: "group1", Resource: resourceType},
	}
	expectedDisabledAnyResources := []schema.GroupResource{
		{Group: "group1", Resource: disabledResourceType},
	}

	for _, expectedResource := range expectedEnabledAnyVersionResources {
		if !config.AnyVersionOfResourceEnabled(expectedResource) {
			t.Errorf("expected enabled for %v, from %v", expectedResource, config)
		}
	}
	for _, expectedResource := range expectedDisabledAnyResources {
		if config.AnyVersionOfResourceEnabled(expectedResource) {
			t.Errorf("expected disabled for %v, from %v", expectedResource, config)
		}
	}

}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:75,代码来源:resource_config_test.go


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