本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.ObjectMetaFor函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjectMetaFor函数的具体用法?Golang ObjectMetaFor怎么用?Golang ObjectMetaFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectMetaFor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ObjectReaction
// ObjectReaction returns a ReactionFunc that takes a generic action string of the form
// <verb>-<resource> or <verb>-<subresource>-<resource> and attempts to return a runtime
// Object or error that matches the requested action. For instance, list-replicationControllers
// should attempt to return a list of replication controllers. This method delegates to the
// ObjectRetriever interface to satisfy retrieval of lists or retrieval of single items.
// TODO: add support for sub resources
func ObjectReaction(o ObjectRetriever, mapper meta.RESTMapper) ReactionFunc {
return func(action Action) (runtime.Object, error) {
_, kind, err := mapper.VersionAndKindForResource(action.GetResource())
if err != nil {
return nil, fmt.Errorf("unrecognized action %s: %v", action.GetResource(), err)
}
// TODO: have mapper return a Kind for a subresource?
switch castAction := action.(type) {
case ListAction:
return o.Kind(kind+"List", "")
case GetAction:
return o.Kind(kind, castAction.GetName())
case DeleteAction:
return o.Kind(kind, castAction.GetName())
case CreateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return nil, err
}
return o.Kind(kind, meta.Name)
case UpdateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return nil, err
}
return o.Kind(kind, meta.Name)
default:
return nil, fmt.Errorf("no reaction implemented for %s", action)
}
return nil, nil
}
}
开发者ID:Bazooki,项目名称:kubernetes,代码行数:40,代码来源:fixture.go
示例2: labelFunc
func labelFunc(obj runtime.Object, overwrite bool, resourceVersion string, labels map[string]string, remove []string) (runtime.Object, error) {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return nil, err
}
if !overwrite {
if err := validateNoOverwrites(meta, labels); err != nil {
return nil, err
}
}
if meta.Labels == nil {
meta.Labels = make(map[string]string)
}
for key, value := range labels {
meta.Labels[key] = value
}
for _, label := range remove {
delete(meta.Labels, label)
}
if len(resourceVersion) != 0 {
meta.ResourceVersion = resourceVersion
}
return obj, nil
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:27,代码来源:label.go
示例3: annotationFor
// annotationFor returns the annotation with key for obj.
func annotationFor(obj runtime.Object, key string) string {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return ""
}
return meta.Annotations[key]
}
开发者ID:ppitonak,项目名称:origin,代码行数:8,代码来源:util.go
示例4: TestCreateHasMetadata
func (t *Tester) TestCreateHasMetadata(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
}
objectMeta.Name = "test"
objectMeta.Namespace = api.NamespaceDefault
context := api.NewDefaultContext()
if t.clusterScope {
objectMeta.Namespace = api.NamespaceNone
context = api.NewContext()
}
obj, err := t.storage.(rest.Creater).Create(context, valid)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if obj == nil {
t.Fatalf("Unexpected object from result: %#v", obj)
}
if !api.HasObjectMetaSystemFieldValues(objectMeta) {
t.Errorf("storage did not populate object meta field values")
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:25,代码来源:resttest.go
示例5: AddMountedSecretEdges
func AddMountedSecretEdges(g osgraph.Graph, podSpec *kubegraph.PodSpecNode) {
//pod specs are always contained. We'll get the toplevel container so that we can pull a namespace from it
containerNode := osgraph.GetTopLevelContainerNode(g, podSpec)
containerObj := g.GraphDescriber.Object(containerNode)
meta, err := kapi.ObjectMetaFor(containerObj.(runtime.Object))
if err != nil {
// this should never happen. it means that a podSpec is owned by a top level container that is not a runtime.Object
panic(err)
}
for _, volume := range podSpec.Volumes {
source := volume.VolumeSource
if source.Secret == nil {
continue
}
// pod secrets must be in the same namespace
syntheticSecret := &kapi.Secret{}
syntheticSecret.Namespace = meta.Namespace
syntheticSecret.Name = source.Secret.SecretName
secretNode := kubegraph.FindOrCreateSyntheticSecretNode(g, syntheticSecret)
g.AddEdge(podSpec, secretNode, MountedSecretEdgeKind)
}
}
开发者ID:nstrug,项目名称:origin,代码行数:26,代码来源:edges.go
示例6: GetUniqueRuntimeObjectNodeName
func GetUniqueRuntimeObjectNodeName(nodeKind string, obj runtime.Object) UniqueName {
meta, err := kapi.ObjectMetaFor(obj)
if err != nil {
panic(err)
}
return UniqueName(fmt.Sprintf("%s|%s/%s", nodeKind, meta.Namespace, meta.Name))
}
开发者ID:cjnygard,项目名称:origin,代码行数:8,代码来源:types.go
示例7: ObjectResourceVersion
// ObjectResourceVersion implements Versioner
func (a APIObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, error) {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return 0, err
}
version := meta.ResourceVersion
if len(version) == 0 {
return 0, nil
}
return strconv.ParseUint(version, 10, 64)
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:12,代码来源:api_object_versioner.go
示例8: objectMetaAndKind
// objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error.
func objectMetaAndKind(typer runtime.ObjectTyper, obj runtime.Object) (*api.ObjectMeta, string, error) {
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return nil, "", errors.NewInternalError(err)
}
_, kind, err := typer.ObjectVersionAndKind(obj)
if err != nil {
return nil, "", errors.NewInternalError(err)
}
return objectMeta, kind, nil
}
开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:12,代码来源:create.go
示例9: objectMetaData
func objectMetaData(raw interface{}) (runtime.Object, *kapi.ObjectMeta, error) {
obj, ok := raw.(runtime.Object)
if !ok {
return nil, nil, fmt.Errorf("%#v is not a runtime.Object", raw)
}
meta, err := kapi.ObjectMetaFor(obj)
if err != nil {
return nil, nil, err
}
return obj, meta, nil
}
开发者ID:heriipurnama,项目名称:origin,代码行数:11,代码来源:pipeline.go
示例10: UpdateObject
// UpdateObject implements EtcdVersioner
func (a APIObjectVersioner) UpdateObject(obj runtime.Object, node *etcd.Node) error {
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return err
}
version := node.ModifiedIndex
versionString := ""
if version != 0 {
versionString = strconv.FormatUint(version, 10)
}
objectMeta.ResourceVersion = versionString
return nil
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:14,代码来源:etcd_object.go
示例11: TestCreateDiscardsObjectNamespace
func (t *Tester) TestCreateDiscardsObjectNamespace(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
}
// Ignore non-empty namespace in object meta
objectMeta.Namespace = "not-default"
// Ideally, we'd get an error back here, but at least verify the namespace wasn't persisted
created, err := t.storage.(rest.Creater).Create(t.TestContext(), copyOrDie(valid))
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
createdObjectMeta, err := api.ObjectMetaFor(created)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, created)
}
if createdObjectMeta.Namespace != api.NamespaceNone {
t.Errorf("Expected empty namespace on created object, got '%v'", createdObjectMeta.Namespace)
}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:22,代码来源:resttest.go
示例12: TestDeleteInvokesValidation
func (t *Tester) TestDeleteInvokesValidation(invalid ...runtime.Object) {
for i, obj := range invalid {
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, obj)
}
ctx := api.NewDefaultContext()
_, err = t.storage.(rest.GracefulDeleter).Delete(ctx, objectMeta.Name, nil)
if !errors.IsInvalid(err) {
t.Errorf("%d: Expected to get an invalid resource error, got %v", i, err)
}
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:13,代码来源:resttest.go
示例13: TestCreateGeneratesNameReturnsServerTimeout
func (t *Tester) TestCreateGeneratesNameReturnsServerTimeout(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
}
objectMeta.GenerateName = "test-"
t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() {
_, err := t.storage.(rest.Creater).Create(api.NewDefaultContext(), valid)
if err == nil || !errors.IsServerTimeout(err) {
t.Fatalf("Unexpected error: %v", err)
}
})
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:14,代码来源:resttest.go
示例14: validateObject
func validateObject(path string, obj runtime.Object, t *testing.T) {
// if an object requires a namespace server side, be sure that it is filled in for validation
if validation.HasObjectMeta(obj) {
namespaceRequired, err := validation.GetRequiresNamespace(obj)
if err != nil {
t.Errorf("Expected no error, Got %v", err)
return
}
if namespaceRequired {
objectMeta, err := kapi.ObjectMetaFor(obj)
if err != nil {
t.Errorf("Expected no error, Got %v", err)
return
}
objectMeta.Namespace = kapi.NamespaceDefault
}
}
switch typedObj := obj.(type) {
case *kapi.Pod:
if errors := kvalidation.ValidatePod(typedObj); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors)
}
case *kapi.Service:
if errors := kvalidation.ValidateService(typedObj); len(errors) > 0 {
t.Errorf("%s did not validate correctly: %v", path, errors)
}
case *kapi.List, *imageapi.ImageStreamList:
if list, err := runtime.ExtractList(typedObj); err == nil {
runtime.DecodeList(list, kapi.Scheme)
for i := range list {
validateObject(path, list[i], t)
}
} else {
t.Errorf("Expected no error, Got %v", err)
}
default:
if errors := validation.Validator.Validate(obj); len(errors) > 0 {
t.Errorf("%s with %v did not validate correctly: %v", path, reflect.TypeOf(obj), errors)
}
}
}
开发者ID:dustintownsend,项目名称:origin,代码行数:50,代码来源:examples_test.go
示例15: mappedAnnotationFor
// mappedAnnotationFor finds the given annotation in obj using the annotation
// map to search all known key variants.
func mappedAnnotationFor(obj runtime.Object, key string) string {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return ""
}
for _, mappedKey := range annotationMap[key] {
if val, ok := meta.Annotations[mappedKey]; ok {
return val
}
}
if val, ok := meta.Annotations[key]; ok {
return val
}
return ""
}
开发者ID:cjnygard,项目名称:origin,代码行数:17,代码来源:util.go
示例16: TestCreateRejectsNamespace
func (t *Tester) TestCreateRejectsNamespace(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
}
objectMeta.Namespace = "not-default"
_, err = t.storage.(rest.Creater).Create(api.NewDefaultContext(), valid)
if err == nil {
t.Errorf("Expected an error, but we didn't get one")
} else if strings.Contains(err.Error(), "Controller.Namespace does not match the provided context") {
t.Errorf("Expected 'Controller.Namespace does not match the provided context' error, got '%v'", err)
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:15,代码来源:resttest.go
示例17: TestCreateRejectsMismatchedNamespace
func (t *Tester) TestCreateRejectsMismatchedNamespace(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
}
objectMeta.Namespace = "not-default"
_, err = t.storage.(rest.Creater).Create(t.TestContext(), valid)
if err == nil {
t.Errorf("Expected an error, but we didn't get one")
} else if !strings.Contains(err.Error(), "does not match the namespace sent on the request") {
t.Errorf("Expected 'does not match the namespace sent on the request' error, got '%v'", err.Error())
}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:15,代码来源:resttest.go
示例18: UpdateObject
// UpdateObject implements Versioner
func (a APIObjectVersioner) UpdateObject(obj runtime.Object, expiration *time.Time, resourceVersion uint64) error {
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return err
}
if expiration != nil {
objectMeta.DeletionTimestamp = &util.Time{*expiration}
}
versionString := ""
if resourceVersion != 0 {
versionString = strconv.FormatUint(resourceVersion, 10)
}
objectMeta.ResourceVersion = versionString
return nil
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:16,代码来源:api_object_versioner.go
示例19: TestDeleteGracefulUsesZeroOnNil
func (t *Tester) TestDeleteGracefulUsesZeroOnNil(existing runtime.Object, expectedGrace int64) {
objectMeta, err := api.ObjectMetaFor(existing)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, existing)
}
ctx := api.WithNamespace(api.NewContext(), objectMeta.Namespace)
_, err = t.storage.(rest.GracefulDeleter).Delete(ctx, objectMeta.Name, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if _, err := t.storage.(rest.Getter).Get(ctx, objectMeta.Name); !errors.IsNotFound(err) {
t.Errorf("unexpected error, object should exist: %v", err)
}
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:15,代码来源:resttest.go
示例20: TestDeleteNonExist
func (t *Tester) TestDeleteNonExist(createFn func() runtime.Object) {
existing := createFn()
objectMeta, err := api.ObjectMetaFor(existing)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, existing)
}
context := api.NewDefaultContext()
t.withStorageError(&etcd.EtcdError{ErrorCode: tools.EtcdErrorCodeNotFound}, func() {
_, err := t.storage.(rest.GracefulDeleter).Delete(context, objectMeta.Name, nil)
if err == nil || !errors.IsNotFound(err) {
t.Fatalf("Unexpected error: %v", err)
}
})
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:15,代码来源:resttest.go
注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/api.ObjectMetaFor函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论