本文整理汇总了Golang中github.com/openshift/origin/pkg/build/api.Resource函数的典型用法代码示例。如果您正苦于以下问题:Golang Resource函数的具体用法?Golang Resource怎么用?Golang Resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceForStrategyType
func resourceForStrategyType(strategy buildapi.BuildStrategy) unversioned.GroupResource {
switch {
case strategy.DockerStrategy != nil:
return buildapi.Resource(authorizationapi.DockerBuildResource)
case strategy.CustomStrategy != nil:
return buildapi.Resource(authorizationapi.CustomBuildResource)
case strategy.SourceStrategy != nil:
return buildapi.Resource(authorizationapi.SourceBuildResource)
}
return unversioned.GroupResource{}
}
示例2: resourceForStrategyType
func resourceForStrategyType(strategy buildapi.BuildStrategy) (unversioned.GroupResource, error) {
switch {
case strategy.DockerStrategy != nil:
return buildapi.Resource(authorizationapi.DockerBuildResource), nil
case strategy.CustomStrategy != nil:
return buildapi.Resource(authorizationapi.CustomBuildResource), nil
case strategy.SourceStrategy != nil:
return buildapi.Resource(authorizationapi.SourceBuildResource), nil
case strategy.JenkinsPipelineStrategy != nil:
return buildapi.Resource(authorizationapi.JenkinsPipelineBuildResource), nil
default:
return unversioned.GroupResource{}, fmt.Errorf("unrecognized build strategy: %#v", strategy)
}
}
示例3: 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}
}
示例4: NewREST
// NewStorage returns a RESTStorage object that will work against Build objects.
func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) {
prefix := "/builds"
store := ®istry.Store{
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 registry.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx kapi.Context, id string) (string, error) {
return registry.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,
}
if err := restoptions.ApplyOptions(optsGetter, store, prefix); err != nil {
return nil, nil, err
}
detailsStore := *store
detailsStore.UpdateStrategy = build.DetailsStrategy
return &REST{store}, &DetailsREST{&detailsStore}, nil
}
示例5: NewREST
// NewREST returns a RESTStorage object that will work against Build objects.
func NewREST(optsGetter restoptions.Getter) (*REST, *DetailsREST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Build{} },
NewListFunc: func() runtime.Object { return &api.BuildList{} },
QualifiedResource: api.Resource("builds"),
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Build).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return build.Matcher(label, field)
},
CreateStrategy: build.Strategy,
UpdateStrategy: build.Strategy,
DeleteStrategy: build.Strategy,
Decorator: build.Decorator,
ReturnDeletedObject: false,
}
if err := restoptions.ApplyOptions(optsGetter, store, true, storage.NoTriggerPublisher); err != nil {
return nil, nil, err
}
detailsStore := *store
detailsStore.UpdateStrategy = build.DetailsStrategy
return &REST{store}, &DetailsREST{&detailsStore}, nil
}
示例6: GetBuildConfig
func (r *BuildConfigRegistry) GetBuildConfig(ctx kapi.Context, id string) (*api.BuildConfig, error) {
r.Lock()
defer r.Unlock()
if r.BuildConfig != nil && r.BuildConfig.Name == id {
return r.BuildConfig, r.Err
}
return nil, kapierrors.NewNotFound(api.Resource("buildconfig"), id)
}
示例7: ServeHTTP
// ServeHTTP implements rest.HookHandler
func (w *WebHook) ServeHTTP(writer http.ResponseWriter, req *http.Request, ctx kapi.Context, name, subpath string) error {
parts := strings.Split(subpath, "/")
if len(parts) != 2 {
return errors.NewBadRequest(fmt.Sprintf("unexpected hook subpath %s", subpath))
}
secret, hookType := parts[0], parts[1]
plugin, ok := w.plugins[hookType]
if !ok {
return errors.NewNotFound(buildapi.Resource("buildconfighook"), hookType)
}
config, err := w.registry.GetBuildConfig(ctx, name)
if err != nil {
// clients should not be able to find information about build configs in
// the system unless the config exists and the secret matches
return errors.NewUnauthorized(fmt.Sprintf("the webhook %q for %q did not accept your secret", hookType, name))
}
revision, envvars, proceed, err := plugin.Extract(config, secret, "", req)
if !proceed {
switch err {
case webhook.ErrSecretMismatch, webhook.ErrHookNotEnabled:
return errors.NewUnauthorized(fmt.Sprintf("the webhook %q for %q did not accept your secret", hookType, name))
case webhook.MethodNotSupported:
return errors.NewMethodNotSupported(buildapi.Resource("buildconfighook"), req.Method)
}
if _, ok := err.(*errors.StatusError); !ok && err != nil {
return errors.NewInternalError(fmt.Errorf("hook failed: %v", err))
}
return err
}
warning := err
buildTriggerCauses := generateBuildTriggerInfo(revision, hookType, secret)
request := &buildapi.BuildRequest{
TriggeredBy: buildTriggerCauses,
ObjectMeta: kapi.ObjectMeta{Name: name},
Revision: revision,
Env: envvars,
}
if _, err := w.instantiator.Instantiate(config.Namespace, request); err != nil {
return errors.NewInternalError(fmt.Errorf("could not generate a build: %v", err))
}
return warning
}
示例8: Get
// Get retrieves the Build from the indexer for a given namespace and name.
func (s buildNamespaceLister) Get(name string) (*api.Build, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(api.Resource("build"), name)
}
return obj.(*api.Build), nil
}
示例9: Get
// Get the build config matching the name from the cache.
func (s storeBuildConfigsNamespacer) Get(name string) (*buildapi.BuildConfig, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, kapierrors.NewNotFound(buildapi.Resource("buildconfigs"), name)
}
return obj.(*buildapi.BuildConfig), nil
}
示例10: TestBuildConfigUpdateError
func TestBuildConfigUpdateError(t *testing.T) {
// valid configuration, but build creation fails, in that situation the buildconfig should not be updated
buildcfg := mockBuildConfig("registry.com/namespace/imagename", "registry.com/namespace/imagename", "testImageStream", "testTag")
imageStream := mockImageStream("testImageStream", "registry.com/namespace/imagename", map[string]string{"testTag": "newImageID123"})
image := mockImage("[email protected]", "registry.com/namespace/[email protected]")
controller := mockImageChangeController(buildcfg, imageStream, image)
bcInstantiator := controller.BuildConfigInstantiator.(*buildConfigInstantiator)
bcUpdater := bcInstantiator.buildConfigUpdater
bcUpdater.err = kerrors.NewConflict(buildapi.Resource("BuildConfig"), buildcfg.Name, errors.New("foo"))
err := controller.HandleImageRepo(imageStream)
if len(bcInstantiator.name) == 0 {
t.Error("Expected build generation when new image was created!")
}
if err == nil || !strings.Contains(err.Error(), "will be retried") {
t.Fatalf("Expected 'will be retried' from HandleImageRepo, got %s", err.Error())
}
}
示例11: ServeHTTP
// ServeHTTP implements rest.HookHandler
func (c *controller) ServeHTTP(w http.ResponseWriter, req *http.Request, ctx kapi.Context, name, subpath string) error {
parts := strings.Split(subpath, "/")
if len(parts) < 2 {
return errors.NewBadRequest(fmt.Sprintf("unexpected hook subpath %s", subpath))
}
secret, hookType := parts[0], parts[1]
plugin, ok := c.plugins[hookType]
if !ok {
return errors.NewNotFound(buildapi.Resource("buildconfighook"), hookType)
}
config, err := c.registry.GetBuildConfig(ctx, name)
if err != nil {
// clients should not be able to find information about build configs in the system unless the config exists
// and the secret matches
return errors.NewUnauthorized(fmt.Sprintf("the webhook %q for %q did not accept your secret", hookType, name))
}
revision, proceed, err := plugin.Extract(config, secret, "", req)
switch err {
case webhook.ErrSecretMismatch, webhook.ErrHookNotEnabled:
return errors.NewUnauthorized(fmt.Sprintf("the webhook %q for %q did not accept your secret", hookType, name))
case nil:
default:
return errors.NewInternalError(fmt.Errorf("hook failed: %v", err))
}
if !proceed {
return nil
}
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{Name: name},
Revision: revision,
}
if _, err := c.instantiator.Instantiate(config.Namespace, request); err != nil {
return errors.NewInternalError(fmt.Errorf("could not generate a build: %v", err))
}
return nil
}
示例12: NewREST
// NewREST returns a RESTStorage object that will work against BuildConfig.
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.BuildConfig{} },
NewListFunc: func() runtime.Object { return &api.BuildConfigList{} },
QualifiedResource: api.Resource("buildconfigs"),
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.BuildConfig).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
return buildconfig.Matcher(label, field)
},
CreateStrategy: buildconfig.Strategy,
UpdateStrategy: buildconfig.Strategy,
DeleteStrategy: buildconfig.Strategy,
ReturnDeletedObject: false,
}
if err := restoptions.ApplyOptions(optsGetter, store, true, storage.NoTriggerPublisher); err != nil {
return nil, err
}
return &REST{store}, nil
}
示例13: removeBuildStrategyRoleResources
func removeBuildStrategyRoleResources(t *testing.T, clusterAdminClient, projectAdminClient, projectEditorClient *client.Client) {
// remove resources from role so that certain build strategies are forbidden
removeBuildStrategyPrivileges(t, clusterAdminClient.ClusterRoles(), bootstrappolicy.EditRoleName)
if err := testutil.WaitForPolicyUpdate(projectEditorClient, testutil.Namespace(), "create", buildapi.Resource(authorizationapi.DockerBuildResource), false); err != nil {
t.Error(err)
}
removeBuildStrategyPrivileges(t, clusterAdminClient.ClusterRoles(), bootstrappolicy.AdminRoleName)
if err := testutil.WaitForPolicyUpdate(projectAdminClient, testutil.Namespace(), "create", buildapi.Resource(authorizationapi.DockerBuildResource), false); err != nil {
t.Error(err)
}
}
示例14: TestClusterReaderCoverage
func TestClusterReaderCoverage(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)
_, clusterAdminKubeConfig, err := testserver.StartTestMasterAPI()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
discoveryClient := client.NewDiscoveryClient(clusterAdminClient.RESTClient)
// (map[string]*unversioned.APIResourceList, error)
allResourceList, err := discoveryClient.ServerResources()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
allResources := map[unversioned.GroupResource]bool{}
for _, resources := range allResourceList {
version, err := unversioned.ParseGroupVersion(resources.GroupVersion)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, resource := range resources.APIResources {
allResources[version.WithResource(resource.Name).GroupResource()] = true
}
}
escalatingResources := map[unversioned.GroupResource]bool{
oauthapi.Resource("oauthauthorizetokens"): true,
oauthapi.Resource("oauthaccesstokens"): true,
oauthapi.Resource("oauthclients"): true,
imageapi.Resource("imagestreams/secrets"): true,
kapi.Resource("secrets"): true,
kapi.Resource("pods/exec"): true,
kapi.Resource("pods/proxy"): true,
kapi.Resource("pods/portforward"): true,
kapi.Resource("nodes/proxy"): true,
kapi.Resource("services/proxy"): true,
}
readerRole, err := clusterAdminClient.ClusterRoles().Get(bootstrappolicy.ClusterReaderRoleName)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, rule := range readerRole.Rules {
for _, group := range rule.APIGroups {
for resource := range rule.Resources {
gr := unversioned.GroupResource{Group: group, Resource: resource}
if escalatingResources[gr] {
t.Errorf("cluster-reader role has escalating resource %v. Check pkg/cmd/server/bootstrappolicy/policy.go.", gr)
}
delete(allResources, gr)
}
}
}
// remove escalating resources that cluster-reader should not have access to
for resource := range escalatingResources {
delete(allResources, resource)
}
// remove resources without read APIs
nonreadingResources := []unversioned.GroupResource{
buildapi.Resource("buildconfigs/instantiatebinary"), buildapi.Resource("buildconfigs/instantiate"), buildapi.Resource("builds/clone"),
deployapi.Resource("deploymentconfigrollbacks"), deployapi.Resource("generatedeploymentconfigs"), deployapi.Resource("deploymentconfigs/rollback"),
imageapi.Resource("imagestreamimports"), imageapi.Resource("imagestreammappings"),
extensionsapi.Resource("deployments/rollback"),
kapi.Resource("pods/attach"), kapi.Resource("namespaces/finalize"),
}
for _, resource := range nonreadingResources {
delete(allResources, resource)
}
// anything left in the map is missing from the permissions
if len(allResources) > 0 {
t.Errorf("cluster-reader role is missing %v. Check pkg/cmd/server/bootstrappolicy/policy.go.", allResources)
}
}
示例15: TestStop
func TestStop(t *testing.T) {
notFound := func() runtime.Object {
return &(kerrors.NewNotFound(buildapi.Resource("BuildConfig"), configName).ErrStatus)
}
tests := map[string]struct {
targetBC string
oc *testclient.Fake
expected []ktestclient.Action
err bool
}{
"simple stop": {
targetBC: configName,
oc: newBuildListFake(makeBuildConfig(configName, 0, false)),
expected: []ktestclient.Action{
ktestclient.NewGetAction("buildconfigs", "default", configName),
// Since there are no builds associated with this build config, do not expect an update
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
ktestclient.NewDeleteAction("buildconfigs", "default", configName),
},
err: false,
},
"multiple builds": {
targetBC: configName,
oc: newBuildListFake(makeBuildConfig(configName, 4, false), makeBuildList(configName, 4)),
expected: []ktestclient.Action{
ktestclient.NewGetAction("buildconfigs", "default", configName),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
ktestclient.NewGetAction("buildconfigs", "default", configName), // Second GET to enable conflict retry logic
ktestclient.NewUpdateAction("buildconfigs", "default", makeBuildConfig(configName, 4, true)), // Because this bc has builds, it is paused
ktestclient.NewDeleteAction("builds", "default", "build-1"),
ktestclient.NewDeleteAction("builds", "default", "build-2"),
ktestclient.NewDeleteAction("builds", "default", "build-3"),
ktestclient.NewDeleteAction("builds", "default", "build-4"),
ktestclient.NewDeleteAction("buildconfigs", "default", configName),
},
err: false,
},
"long name builds": {
targetBC: longConfigNameA,
oc: newBuildListFake(makeBuildConfig(longConfigNameA, 4, false), makeBuildList(longConfigNameA, 4), makeBuildList(longConfigNameB, 4)),
expected: []ktestclient.Action{
ktestclient.NewGetAction("buildconfigs", "default", longConfigNameA),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(longConfigNameA)}),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(longConfigNameA)}),
ktestclient.NewGetAction("buildconfigs", "default", longConfigNameA), // Second GET to enable conflict retry logic
ktestclient.NewUpdateAction("buildconfigs", "default", makeBuildConfig(longConfigNameA, 4, true)), // Because this bc has builds, it is paused
ktestclient.NewDeleteAction("builds", "default", "build-1"),
ktestclient.NewDeleteAction("builds", "default", "build-2"),
ktestclient.NewDeleteAction("builds", "default", "build-3"),
ktestclient.NewDeleteAction("builds", "default", "build-4"),
ktestclient.NewDeleteAction("buildconfigs", "default", longConfigNameA),
},
err: false,
},
"no config, no or some builds": {
targetBC: configName,
oc: testclient.NewSimpleFake(notFound(), makeBuildList(configName, 2)),
expected: []ktestclient.Action{
ktestclient.NewGetAction("buildconfigs", "default", configName),
},
err: true,
},
"config, no builds": {
targetBC: configName,
oc: testclient.NewSimpleFake(makeBuildConfig(configName, 0, false)),
expected: []ktestclient.Action{
ktestclient.NewGetAction("buildconfigs", "default", configName),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelector(configName)}),
ktestclient.NewListAction("builds", "default", kapi.ListOptions{LabelSelector: buildutil.BuildConfigSelectorDeprecated(configName)}),
ktestclient.NewDeleteAction("buildconfigs", "default", configName),
},
err: false,
},
}
for testName, test := range tests {
reaper := &BuildConfigReaper{oc: test.oc, pollInterval: time.Millisecond, timeout: time.Millisecond}
err := reaper.Stop("default", test.targetBC, 1*time.Second, nil)
if !test.err && err != nil {
t.Errorf("%s: unexpected error: %v", testName, err)
}
if test.err && err == nil {
t.Errorf("%s: expected an error", testName)
}
if len(test.oc.Actions()) != len(test.expected) {
t.Fatalf("%s: unexpected actions: %v, expected %v", testName, test.oc.Actions(), test.expected)
}
for j, actualAction := range test.oc.Actions() {
if !actionsAreEqual(actualAction, test.expected[j]) {
t.Errorf("%s: unexpected action: %v, expected %v", testName, actualAction, test.expected[j])
}
}
}
}