本文整理汇总了Golang中vulcan/kubernetes/pkg/api.ObjectMetaFor函数的典型用法代码示例。如果您正苦于以下问题:Golang ObjectMetaFor函数的具体用法?Golang ObjectMetaFor怎么用?Golang ObjectMetaFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectMetaFor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: annotateRuntimeObject
func annotateRuntimeObject(t *testing.T, originalObj, currentObj runtime.Object, kind string) (string, []byte) {
originalMeta, err := api.ObjectMetaFor(originalObj)
if err != nil {
t.Fatal(err)
}
originalMeta.Labels["DELETE_ME"] = "DELETE_ME"
original, err := json.Marshal(originalObj)
if err != nil {
t.Fatal(err)
}
currentMeta, err := api.ObjectMetaFor(currentObj)
if err != nil {
t.Fatal(err)
}
if currentMeta.Annotations == nil {
currentMeta.Annotations = map[string]string{}
}
currentMeta.Annotations[kubectl.LastAppliedConfigAnnotation] = string(original)
current, err := json.Marshal(currentObj)
if err != nil {
t.Fatal(err)
}
return currentMeta.Name, current
}
示例2: validateCommonFields
// TODO: add other common fields that require global validation.
func validateCommonFields(obj, old runtime.Object) fielderrors.ValidationErrorList {
allErrs := fielderrors.ValidationErrorList{}
objectMeta, err := api.ObjectMetaFor(obj)
if err != nil {
return append(allErrs, errors.NewInternalError(err))
}
oldObjectMeta, err := api.ObjectMetaFor(old)
if err != nil {
return append(allErrs, errors.NewInternalError(err))
}
allErrs = append(allErrs, validation.ValidateObjectMetaUpdate(objectMeta, oldObjectMeta)...)
return allErrs
}
示例3: getObjectMetaOrFail
func (t *Tester) getObjectMetaOrFail(obj runtime.Object) *api.ObjectMeta {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, obj)
}
return meta
}
示例4: getObject
func (t *Tester) getObject(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return nil, err
}
key, err := t.storage.KeyFunc(ctx, meta.Name)
if err != nil {
return nil, err
}
key = etcdtest.AddPrefix(key)
resp, err := t.fakeClient.Get(key, false, false)
if err != nil {
return nil, err
}
result := t.storage.NewFunc()
codec, err := getCodec(obj)
if err != nil {
return nil, err
}
if err := codec.DecodeInto([]byte(resp.Node.Value), result); err != nil {
return nil, err
}
return result, nil
}
示例5: labelFunc
func labelFunc(obj runtime.Object, overwrite bool, resourceVersion string, labels map[string]string, remove []string) error {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return err
}
if !overwrite {
if err := validateNoOverwrites(meta, labels); err != nil {
return 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 nil
}
示例6: updateAnnotations
// updateAnnotations updates annotations of obj
func (o AnnotateOptions) updateAnnotations(obj runtime.Object) error {
meta, err := api.ObjectMetaFor(obj)
if err != nil {
return err
}
if !o.overwrite {
if err := validateNoAnnotationOverwrites(meta, o.newAnnotations); err != nil {
return err
}
}
if meta.Annotations == nil {
meta.Annotations = make(map[string]string)
}
for key, value := range o.newAnnotations {
meta.Annotations[key] = value
}
for _, annotation := range o.removeAnnotations {
delete(meta.Annotations, annotation)
}
if len(o.resourceVersion) != 0 {
meta.ResourceVersion = o.resourceVersion
}
return nil
}
示例7: 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) (bool, runtime.Object, error) {
_, kind, err := mapper.VersionAndKindForResource(action.GetResource())
if err != nil {
return false, 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:
resource, err := o.Kind(kind+"List", "")
return true, resource, err
case GetAction:
resource, err := o.Kind(kind, castAction.GetName())
return true, resource, err
case DeleteAction:
resource, err := o.Kind(kind, castAction.GetName())
return true, resource, err
case CreateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return true, nil, err
}
resource, err := o.Kind(kind, meta.Name)
return true, resource, err
case UpdateAction:
meta, err := api.ObjectMetaFor(castAction.GetObject())
if err != nil {
return true, nil, err
}
resource, err := o.Kind(kind, meta.Name)
return true, resource, err
default:
return false, nil, fmt.Errorf("no reaction implemented for %s", action)
}
return true, nil, nil
}
}
示例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
}
示例9: 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)
}
示例10: 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 := t.TestContext()
_, 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)
}
}
}
示例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)
}
}
示例12: 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 := t.TestContext()
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)
}
})
}
示例13: 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())
}
}
示例14: 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.Name = ""
objectMeta.GenerateName = "test-"
t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() {
_, err := t.storage.(rest.Creater).Create(t.TestContext(), valid)
if err == nil || !errors.IsServerTimeout(err) {
t.Fatalf("Unexpected error: %v", err)
}
})
}
示例15: 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(t.TestContext(), 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)
}
}