本文整理汇总了Golang中github.com/openshift/origin/pkg/image/api.Resource函数的典型用法代码示例。如果您正苦于以下问题:Golang Resource函数的具体用法?Golang Resource怎么用?Golang Resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Resource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Complete
// Complete completes the required options for build-chain
func (o *BuildChainOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
if len(args) != 1 {
return cmdutil.UsageError(cmd, "Must pass an image stream tag. If only an image stream name is specified, 'latest' will be used for the tag.")
}
// Setup client
oc, _, _, err := f.Clients()
if err != nil {
return err
}
o.c, o.t = oc, oc
resource := unversioned.GroupResource{}
mapper, _ := f.Object(false)
resource, o.name, err = osutil.ResolveResource(imageapi.Resource("imagestreamtags"), args[0], mapper)
if err != nil {
return err
}
switch resource {
case imageapi.Resource("imagestreamtags"):
o.name = imageapi.NormalizeImageStreamTag(o.name)
glog.V(4).Infof("Using %q as the image stream tag to look dependencies for", o.name)
default:
return fmt.Errorf("invalid resource provided: %v", resource)
}
// Setup namespace
if o.allNamespaces {
// TODO: Handle different uses of build-chain; user and admin
projectList, err := oc.Projects().List(kapi.ListOptions{})
if err != nil {
return err
}
for _, project := range projectList.Items {
glog.V(4).Infof("Found namespace %q", project.Name)
o.namespaces.Insert(project.Name)
}
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
o.defaultNamespace = namespace
glog.V(4).Infof("Using %q as the namespace for %q", o.defaultNamespace, o.name)
o.namespaces.Insert(namespace)
glog.V(4).Infof("Will look for deps in %s", strings.Join(o.namespaces.List(), ","))
return nil
}
开发者ID:php-coder,项目名称:origin,代码行数:53,代码来源:buildchain.go
示例2: TestRunTag_AddAccrossNamespaces
func TestRunTag_AddAccrossNamespaces(t *testing.T) {
streams := testData()
client := testclient.NewSimpleFake(streams[2], streams[0])
client.PrependReactor("create", "imagestreamtags", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, kapierrors.NewMethodNotSupported(imageapi.Resource("imagestreamtags"), "create")
})
client.PrependReactor("update", "imagestreamtags", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, kapierrors.NewMethodNotSupported(imageapi.Resource("imagestreamtags"), "update")
})
test := struct {
opts *TagOptions
expectedActions []testAction
expectedErr error
}{
opts: &TagOptions{
out: os.Stdout,
osClient: client,
ref: imageapi.DockerImageReference{
Namespace: "openshift",
Name: "ruby",
Tag: "latest",
},
namespace: "myproject2",
sourceKind: "ImageStreamTag",
destNamespace: []string{"yourproject"},
destNameAndTag: []string{"rails:tip"},
},
expectedActions: []testAction{
{verb: "update", resource: "imagestreamtags"},
{verb: "create", resource: "imagestreamtags"},
{verb: "get", resource: "imagestreams"},
{verb: "update", resource: "imagestreams"},
},
expectedErr: nil,
}
if err := test.opts.RunTag(); err != test.expectedErr {
t.Fatalf("error mismatch: expected %v, got %v", test.expectedErr, err)
}
got := client.Actions()
if len(test.expectedActions) != len(got) {
t.Fatalf("action length mismatch: expectedc %d, got %d", len(test.expectedActions), len(got))
}
for i, action := range test.expectedActions {
if !got[i].Matches(action.verb, action.resource) {
t.Errorf("action mismatch: expected %s %s, got %s %s", action.verb, action.resource, got[i].GetVerb(), got[i].GetResource())
}
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:52,代码来源:tag_test.go
示例3: Delete
// Delete removes a tag from a stream. `id` is of the format <stream name>:<tag>.
// The associated image that the tag points to is *not* deleted.
// The tag history remains intact and is not deleted.
func (r *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
name, tag, err := nameAndTag(id)
if err != nil {
return nil, err
}
stream, err := r.imageStreamRegistry.GetImageStream(ctx, name)
if err != nil {
return nil, err
}
notFound := true
// Try to delete the status tag
if _, ok := stream.Status.Tags[tag]; ok {
delete(stream.Status.Tags, tag)
notFound = false
}
// Try to delete the spec tag
if _, ok := stream.Spec.Tags[tag]; ok {
delete(stream.Spec.Tags, tag)
notFound = false
}
if notFound {
return nil, kapierrors.NewNotFound(api.Resource("imagestreamtags"), tag)
}
if _, err = r.imageStreamRegistry.UpdateImageStream(ctx, stream); err != nil {
return nil, fmt.Errorf("cannot remove tag from image stream: %v", err)
}
return &unversioned.Status{Status: unversioned.StatusSuccess}, nil
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:38,代码来源:rest.go
示例4: NewREST
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Image{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageList{} },
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Image).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return image.Matcher(label, field)
},
QualifiedResource: api.Resource("images"),
// Used to validate image creation
CreateStrategy: image.Strategy,
// Used to validate image updates
UpdateStrategy: image.Strategy,
ReturnDeletedObject: false,
}
if err := restoptions.ApplyOptions(optsGetter, store, false, storage.NoTriggerPublisher); err != nil {
return nil, err
}
return &REST{store}, nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:32,代码来源:etcd.go
示例5: Delete
func (r *REST) Delete(ctx kapi.Context, name string) (runtime.Object, error) {
imageName, _, err := imageapi.SplitImageSignatureName(name)
if err != nil {
return nil, kapierrors.NewBadRequest("ImageSignatures must be accessed with <imageName>@<signatureName>")
}
image, err := r.imageClient.Get(imageName)
if err != nil {
return nil, err
}
index := imageapi.IndexOfImageSignatureByName(image.Signatures, name)
if index < 0 {
return nil, kapierrors.NewNotFound(imageapi.Resource("imageSignatures"), name)
}
size := len(image.Signatures)
copy(image.Signatures[index:size-1], image.Signatures[index+1:size])
image.Signatures = image.Signatures[0 : size-1]
if _, err := r.imageClient.Update(image); err != nil {
return nil, err
}
return &unversioned.Status{Status: unversioned.StatusSuccess}, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:26,代码来源:rest.go
示例6: imageFor
// imageFor retrieves the most recent image for a tag in a given imageStreem.
func (r *REST) imageFor(ctx kapi.Context, tag string, imageStream *api.ImageStream) (*api.Image, error) {
event := api.LatestTaggedImage(imageStream, tag)
if event == nil || len(event.Image) == 0 {
return nil, kapierrors.NewNotFound(api.Resource("imagestreamtags"), api.JoinImageStreamTag(imageStream.Name, tag))
}
return r.imageRegistry.GetImage(ctx, event.Image)
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:9,代码来源:rest.go
示例7: TestAdmitImageStreamMapping
func TestAdmitImageStreamMapping(t *testing.T) {
tests := map[string]struct {
imageStreamMapping *imageapi.ImageStreamMapping
limitRange *kapi.LimitRange
shouldAdmit bool
operation kadmission.Operation
}{
"new ism, no limit range": {
imageStreamMapping: getImageStreamMapping(),
operation: kadmission.Create,
shouldAdmit: true,
},
"new ism, under limit range": {
imageStreamMapping: getImageStreamMapping(),
limitRange: getLimitRange("1Ki"),
operation: kadmission.Create,
shouldAdmit: true,
},
"new ism, over limit range": {
imageStreamMapping: getImageStreamMapping(),
limitRange: getLimitRange("0Ki"),
operation: kadmission.Create,
shouldAdmit: false,
},
}
for k, v := range tests {
var fakeKubeClient clientset.Interface
if v.limitRange != nil {
fakeKubeClient = clientsetfake.NewSimpleClientset(v.limitRange)
} else {
fakeKubeClient = clientsetfake.NewSimpleClientset()
}
plugin, err := NewImageLimitRangerPlugin(fakeKubeClient, nil)
if err != nil {
t.Errorf("%s failed creating plugin %v", k, err)
continue
}
attrs := kadmission.NewAttributesRecord(v.imageStreamMapping,
imageapi.Kind("ImageStreamMapping").WithVersion("version"),
v.imageStreamMapping.Namespace,
v.imageStreamMapping.Name,
imageapi.Resource("imagestreammappings").WithVersion("version"),
"",
v.operation,
nil)
err = plugin.Admit(attrs)
if v.shouldAdmit && err != nil {
t.Errorf("%s expected to be admitted but received error %v", k, err)
}
if !v.shouldAdmit && err == nil {
t.Errorf("%s expected to be rejected but received no error", k)
}
}
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:58,代码来源:admission_test.go
示例8: Create
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
istag, ok := obj.(*imageapi.ImageStreamTag)
if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("obj is not an ImageStreamTag: %#v", obj))
}
if err := rest.BeforeCreate(Strategy, ctx, obj); err != nil {
return nil, err
}
namespace, ok := kapi.NamespaceFrom(ctx)
if !ok {
return nil, kapierrors.NewBadRequest("a namespace must be specified to import images")
}
imageStreamName, imageTag, ok := imageapi.SplitImageStreamTag(istag.Name)
if !ok {
return nil, fmt.Errorf("%q must be of the form <stream_name>:<tag>", istag.Name)
}
target, err := r.imageStreamRegistry.GetImageStream(ctx, imageStreamName)
if err != nil {
if !kapierrors.IsNotFound(err) {
return nil, err
}
// try to create the target if it doesn't exist
target = &imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Name: imageStreamName,
Namespace: namespace,
},
}
}
if target.Spec.Tags == nil {
target.Spec.Tags = make(map[string]imageapi.TagReference)
}
// The user wants to symlink a tag.
_, exists := target.Spec.Tags[imageTag]
if exists {
return nil, kapierrors.NewAlreadyExists(imageapi.Resource("imagestreamtag"), istag.Name)
}
target.Spec.Tags[imageTag] = *istag.Tag
// Check the stream creation timestamp and make sure we will not
// create a new image stream while deleting.
if target.CreationTimestamp.IsZero() {
_, err = r.imageStreamRegistry.CreateImageStream(ctx, target)
} else {
_, err = r.imageStreamRegistry.UpdateImageStream(ctx, target)
}
if err != nil {
return nil, err
}
return istag, nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:57,代码来源:rest.go
示例9: NewREST
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter, defaultRegistry api.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry, limitVerifier imageadmission.LimitVerifier) (*REST, *StatusREST, *InternalREST, error) {
prefix := "/imagestreams"
store := registry.Store{
NewFunc: func() runtime.Object { return &api.ImageStream{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
// Produces a path that etcd understands, to the root of the resource
// by combining the namespace in the context with the given prefix.
KeyRootFunc: func(ctx kapi.Context) string {
return registry.NamespaceKeyRootFunc(ctx, prefix)
},
// Produces a path that etcd understands, to the resource by combining
// the namespace in the context with the given prefix
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return registry.NamespaceKeyFunc(ctx, prefix, name)
},
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ImageStream).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return imagestream.MatchImageStream(label, field)
},
QualifiedResource: api.Resource("imagestreams"),
ReturnDeletedObject: false,
}
strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry, limitVerifier)
rest := &REST{Store: &store, subjectAccessReviewRegistry: subjectAccessReviewRegistry}
strategy.ImageStreamGetter = rest
store.CreateStrategy = strategy
store.UpdateStrategy = strategy
store.Decorator = strategy.Decorate
if err := restoptions.ApplyOptions(optsGetter, &store, prefix); err != nil {
return nil, nil, nil, err
}
statusStore := store
statusStore.Decorator = nil
statusStore.CreateStrategy = nil
statusStore.UpdateStrategy = imagestream.NewStatusStrategy(strategy)
internalStore := store
internalStrategy := imagestream.NewInternalStrategy(strategy)
internalStore.Decorator = nil
internalStore.CreateStrategy = internalStrategy
internalStore.UpdateStrategy = internalStrategy
return rest, &StatusREST{store: &statusStore}, &InternalREST{store: &internalStore}, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:57,代码来源:etcd.go
示例10: Get
// Get the image stream matching the name from the cache.
func (s storeImageStreamsNamespacer) Get(name string) (*imageapi.ImageStream, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, kapierrors.NewNotFound(imageapi.Resource("imagestream"), name)
}
return obj.(*imageapi.ImageStream), nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:11,代码来源:imagestream.go
示例11: newISTag
func newISTag(tag string, imageStream *api.ImageStream, image *api.Image) (*api.ImageStreamTag, error) {
istagName := api.JoinImageStreamTag(imageStream.Name, tag)
event := api.LatestTaggedImage(imageStream, tag)
if event == nil || len(event.Image) == 0 {
return nil, kapierrors.NewNotFound(api.Resource("imagestreamtag"), istagName)
}
ist := &api.ImageStreamTag{
ObjectMeta: kapi.ObjectMeta{
Namespace: imageStream.Namespace,
Name: istagName,
CreationTimestamp: event.Created,
Annotations: map[string]string{},
ResourceVersion: imageStream.ResourceVersion,
},
}
// if the imageStream has Spec.Tags[tag].Annotations[k] = v, copy it to the image's annotations
// and add them to the istag's annotations
if imageStream.Spec.Tags != nil {
if tagRef, ok := imageStream.Spec.Tags[tag]; ok {
if image != nil && image.Annotations == nil {
image.Annotations = make(map[string]string)
}
for k, v := range tagRef.Annotations {
ist.Annotations[k] = v
if image != nil {
image.Annotations[k] = v
}
}
}
}
if image != nil {
if err := api.ImageWithMetadata(image); err != nil {
return nil, err
}
image.DockerImageManifest = ""
ist.Image = *image
} else {
ist.Image = api.Image{}
ist.Image.Name = event.Image
}
// Replace the DockerImageReference with the value from event, which contains
// real value from status. This should fix the problem for v1 registries,
// where mutliple tags point to a single id and only the first image's metadata
// is saved. This in turn will always return the pull spec from the first
// imported image, which might be different than the requested tag.
ist.Image.DockerImageReference = event.DockerImageReference
return ist, nil
}
开发者ID:rrati,项目名称:origin,代码行数:54,代码来源:rest.go
示例12: TestCreateRetryConflictTagDiff
// TestCreateRetryConflictTagDiff ensures that attempts to create a mapping
// that result in resource conflicts that DO contain tag diffs causes the
// conflict error to be returned.
func TestCreateRetryConflictTagDiff(t *testing.T) {
firstGet := true
firstUpdate := true
rest := &REST{
strategy: NewStrategy(testDefaultRegistry),
imageRegistry: &fakeImageRegistry{
createImage: func(ctx kapi.Context, image *api.Image) error {
return nil
},
},
imageStreamRegistry: &fakeImageStreamRegistry{
getImageStream: func(ctx kapi.Context, id string) (*api.ImageStream, error) {
// For the first get, return a stream with a latest tag pointing to "original"
if firstGet {
firstGet = false
stream := validImageStream()
stream.Status = api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {Items: []api.TagEvent{{DockerImageReference: "localhost:5000/someproject/somerepo:original"}}},
},
}
return stream, nil
}
// For subsequent gets, return a stream with the latest tag changed to "newer"
stream := validImageStream()
stream.Status = api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"latest": {Items: []api.TagEvent{{DockerImageReference: "localhost:5000/someproject/somerepo:newer"}}},
},
}
return stream, nil
},
updateImageStreamStatus: func(ctx kapi.Context, repo *api.ImageStream) (*api.ImageStream, error) {
// For the first update, return a conflict so that the stream
// get/compare is retried.
if firstUpdate {
firstUpdate = false
return nil, errors.NewConflict(api.Resource("imagestreams"), repo.Name, fmt.Errorf("resource modified"))
}
return repo, nil
},
},
}
obj, err := rest.Create(kapi.NewDefaultContext(), validNewMappingWithName())
if err == nil {
t.Fatalf("expected an error")
}
if !errors.IsConflict(err) {
t.Errorf("expected a conflict error, got %v", err)
}
if obj != nil {
t.Fatalf("expected a nil result")
}
}
开发者ID:legionus,项目名称:origin,代码行数:57,代码来源:rest_test.go
示例13: VerifyLimits
func (v *limitVerifier) VerifyLimits(namespace string, is *imageapi.ImageStream) error {
limits, err := v.limiter.LimitsForNamespace(namespace)
if err != nil || len(limits) == 0 {
return err
}
usage := GetImageStreamUsage(is)
if err := verifyImageStreamUsage(usage, limits); err != nil {
return kapierrors.NewForbidden(imageapi.Resource("ImageStream"), is.Name, err)
}
return nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:12,代码来源:imagestream_limits.go
示例14: NewREST
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter, defaultRegistry api.DefaultRegistry, subjectAccessReviewRegistry subjectaccessreview.Registry, limitVerifier imageadmission.LimitVerifier) (*REST, *StatusREST, *InternalREST, error) {
store := registry.Store{
NewFunc: func() runtime.Object { return &api.ImageStream{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageStreamList{} },
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.ImageStream).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return imagestream.Matcher(label, field)
},
QualifiedResource: api.Resource("imagestreams"),
ReturnDeletedObject: false,
}
rest := &REST{
Store: &store,
subjectAccessReviewRegistry: subjectAccessReviewRegistry,
}
// strategy must be able to load image streams across namespaces during tag verification
strategy := imagestream.NewStrategy(defaultRegistry, subjectAccessReviewRegistry, limitVerifier, rest)
store.CreateStrategy = strategy
store.UpdateStrategy = strategy
store.Decorator = strategy.Decorate
if err := restoptions.ApplyOptions(optsGetter, &store, true, storage.NoTriggerPublisher); err != nil {
return nil, nil, nil, err
}
statusStrategy := imagestream.NewStatusStrategy(strategy)
statusStore := store
statusStore.Decorator = nil
statusStore.CreateStrategy = nil
statusStore.UpdateStrategy = statusStrategy
statusREST := &StatusREST{store: &statusStore}
internalStore := store
internalStrategy := imagestream.NewInternalStrategy(strategy)
internalStore.Decorator = nil
internalStore.CreateStrategy = internalStrategy
internalStore.UpdateStrategy = internalStrategy
internalREST := &InternalREST{store: &internalStore}
return rest, statusREST, internalREST, nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:51,代码来源:etcd.go
示例15: formatRepositoryError
func formatRepositoryError(repository *importRepository, refName string, refID string, defErr error) (err error) {
err = defErr
switch {
case isDockerError(err, v2.ErrorCodeManifestUnknown):
ref := repository.Ref
ref.Tag, ref.ID = refName, refID
err = kapierrors.NewNotFound(api.Resource("dockerimage"), ref.Exact())
case isDockerError(err, errcode.ErrorCodeUnauthorized):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
case strings.HasSuffix(err.Error(), "no basic auth credentials"):
err = kapierrors.NewUnauthorized(fmt.Sprintf("you may not have access to the Docker image %q", repository.Ref.Exact()))
}
return
}
开发者ID:Xmagicer,项目名称:origin,代码行数:14,代码来源:importer.go
示例16: TestImageStreamImportUnsupported
func TestImageStreamImportUnsupported(t *testing.T) {
testCases := []struct {
status unversioned.Status
errFn func(err error) bool
}{
{
status: errors.NewNotFound(api.Resource(""), "").(errors.APIStatus).Status(),
errFn: func(err error) bool { return err == ErrImageStreamImportUnsupported },
},
{
status: errors.NewNotFound(api.Resource("ImageStreamImport"), "").(errors.APIStatus).Status(),
errFn: func(err error) bool { return err != ErrImageStreamImportUnsupported && errors.IsNotFound(err) },
},
{
status: errors.NewConflict(api.Resource("ImageStreamImport"), "", nil).(errors.APIStatus).Status(),
errFn: func(err error) bool { return err != ErrImageStreamImportUnsupported && errors.IsConflict(err) },
},
{
status: errors.NewForbidden(api.Resource("ImageStreamImport"), "", nil).(errors.APIStatus).Status(),
errFn: func(err error) bool { return err == ErrImageStreamImportUnsupported },
},
}
for i, test := range testCases {
c, err := New(&kclient.Config{
Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
buf := bytes.NewBuffer([]byte(runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(api.SchemeGroupVersion), &test.status)))
return &http.Response{StatusCode: http.StatusNotFound, Body: ioutil.NopCloser(buf)}, nil
}),
})
if err != nil {
t.Fatal(err)
}
if _, err := c.ImageStreams("test").Import(&api.ImageStreamImport{}); !test.errFn(err) {
t.Errorf("%d: error: %v", i, err)
}
}
}
开发者ID:richm,项目名称:origin,代码行数:37,代码来源:imagestreams_test.go
示例17: TestRunTag_DeleteOld
func TestRunTag_DeleteOld(t *testing.T) {
streams := testData()
client := testclient.NewSimpleFake(streams[1])
client.PrependReactor("delete", "imagestreamtags", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, kapierrors.NewForbidden(imageapi.Resource("imagestreamtags"), "rails:tip", fmt.Errorf("dne"))
})
client.PrependReactor("get", "imagestreams", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, testData()[1], nil
})
client.PrependReactor("update", "imagestreams", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, nil
})
test := struct {
opts *TagOptions
expectedActions []testAction
expectedErr error
}{
opts: &TagOptions{
out: os.Stdout,
osClient: client,
deleteTag: true,
destNamespace: []string{"yourproject"},
destNameAndTag: []string{"rails:tip"},
},
expectedActions: []testAction{
{verb: "delete", resource: "imagestreamtags"},
{verb: "get", resource: "imagestreams"},
{verb: "update", resource: "imagestreams"},
},
expectedErr: nil,
}
if err := test.opts.RunTag(); err != test.expectedErr {
t.Fatalf("error mismatch: expected %v, got %v", test.expectedErr, err)
}
got := client.Actions()
if len(test.expectedActions) != len(got) {
t.Fatalf("action length mismatch: expectedc %d, got %d", len(test.expectedActions), len(got))
}
for i, action := range test.expectedActions {
if !got[i].Matches(action.verb, action.resource) {
t.Errorf("action mismatch: expected %s %s, got %s %s", action.verb, action.resource, got[i].GetVerb(), got[i].GetResource())
}
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:48,代码来源:tag_test.go
示例18: Get
// Get retrieves an image by ID that has previously been tagged into an image stream.
// `id` is of the form <repo name>@<image id>.
func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
name, imageID, err := ParseNameAndID(id)
if err != nil {
return nil, err
}
repo, err := r.imageStreamRegistry.GetImageStream(ctx, name)
if err != nil {
return nil, err
}
if repo.Status.Tags == nil {
return nil, errors.NewNotFound(api.Resource("imagestreamimage"), imageID)
}
event, err := api.ResolveImageID(repo, imageID)
if err != nil {
return nil, err
}
imageName := event.Image
image, err := r.imageRegistry.GetImage(ctx, imageName)
if err != nil {
return nil, err
}
if err := api.ImageWithMetadata(image); err != nil {
return nil, err
}
image.DockerImageManifest = ""
if d, err := digest.ParseDigest(imageName); err == nil {
imageName = d.Hex()
}
if len(imageName) > 7 {
imageName = imageName[:7]
}
isi := api.ImageStreamImage{
ObjectMeta: kapi.ObjectMeta{
Namespace: kapi.NamespaceValue(ctx),
Name: fmt.Sprintf("%[email protected]%s", name, imageName),
},
Image: *image,
}
return &isi, nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:49,代码来源:rest.go
示例19: NewREST
// NewREST returns a new REST.
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
prefix := "/images"
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.Image{} },
// NewListFunc returns an object capable of storing results of an etcd list.
NewListFunc: func() runtime.Object { return &api.ImageList{} },
// Produces a path that etcd understands, to the root of the resource
// by combining the namespace in the context with the given prefix.
// Yet images are not namespace scoped, so we're returning just prefix here.
KeyRootFunc: func(ctx kapi.Context) string {
return prefix
},
// Produces a path that etcd understands, to the resource by combining
// the namespace in the context with the given prefix
// Yet images are not namespace scoped, so we're returning just prefix here.
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return registry.NoNamespaceKeyFunc(ctx, prefix, name)
},
// Retrieve the name field of an image
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.Image).Name, nil
},
// Used to match objects based on labels/fields for list and watch
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return image.MatchImage(label, field)
},
QualifiedResource: api.Resource("images"),
// Used to validate image creation
CreateStrategy: image.Strategy,
// Used to validate image updates
UpdateStrategy: image.Strategy,
ReturnDeletedObject: false,
}
if err := restoptions.ApplyOptions(optsGetter, store, prefix); err != nil {
return nil, err
}
return &REST{store}, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:46,代码来源:etcd.go
示例20: TestGenerate_reportsNotFoundErrorWhenMissingDeploymentConfig
func TestGenerate_reportsNotFoundErrorWhenMissingDeploymentConfig(t *testing.T) {
generator := &DeploymentConfigGenerator{
Client: Client{
DCFn: func(ctx kapi.Context, name string) (*deployapi.DeploymentConfig, error) {
return nil, kerrors.NewNotFound(deployapi.Resource("DeploymentConfig"), name)
},
ISFn: func(ctx kapi.Context, name string) (*imageapi.ImageStream, error) {
return nil, kerrors.NewNotFound(imageapi.Resource("ImageStream"), name)
},
},
}
_, err := generator.Generate(kapi.NewDefaultContext(), "deploy1")
if err == nil || !kerrors.IsNotFound(err) {
t.Fatalf("Unexpected error type: %v", err)
}
if !strings.Contains(err.Error(), "DeploymentConfig \"deploy1\" not found") {
t.Errorf("unexpected error message: %v", err)
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:19,代码来源:config_generator_test.go
注:本文中的github.com/openshift/origin/pkg/image/api.Resource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论