Storage: Make entity to runtime.Object conversion public (#89549)

* make conversion public

* make conversion public
pull/89558/head
Ryan McKinley 11 months ago committed by GitHub
parent 9f04b6d6a8
commit 70cd002826
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      pkg/apiserver/endpoints/filters/requester.go
  2. 20
      pkg/services/apiserver/storage/entity/storage.go
  3. 2
      pkg/services/apiserver/storage/entity/utils.go
  4. 2
      pkg/services/apiserver/storage/entity/utils_test.go

@ -33,6 +33,7 @@ func WithRequester(handler http.Handler) http.Handler {
slices.Contains(info.GetGroups(), user.SystemPrivilegedGroup) {
orgId := int64(1)
requester = &identity.StaticRequester{
Namespace: identity.NamespaceServiceAccount, // system:apiserver
UserID: 1,
OrgID: orgId,
Name: info.GetName(),

@ -100,7 +100,7 @@ func (s *Storage) Create(ctx context.Context, key string, obj runtime.Object, ou
return fmt.Errorf("this was not a create operation... (%s)", rsp.Status.String())
}
err = entityToResource(rsp.Entity, out, s.codec)
err = EntityToRuntimeObject(rsp.Entity, out, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -140,7 +140,7 @@ func (s *Storage) Delete(ctx context.Context, key string, out runtime.Object, pr
return err
}
err = entityToResource(rsp.Entity, out, s.codec)
err = EntityToRuntimeObject(rsp.Entity, out, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -328,7 +328,7 @@ func (s *Storage) Get(ctx context.Context, key string, opts storage.GetOptions,
return apierrors.NewNotFound(s.gr, k.Name)
}
err = entityToResource(rsp, objPtr, s.codec)
err = EntityToRuntimeObject(rsp, objPtr, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -394,7 +394,7 @@ func (s *Storage) GetList(ctx context.Context, key string, opts storage.ListOpti
for _, r := range rsp.Versions {
res := s.newFunc()
err := entityToResource(r, res, s.codec)
err := EntityToRuntimeObject(r, res, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -466,7 +466,7 @@ func (s *Storage) GetList(ctx context.Context, key string, opts storage.ListOpti
for _, r := range rsp.Results {
res := s.newFunc()
err := entityToResource(r, res, s.codec)
err := EntityToRuntimeObject(r, res, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -582,7 +582,7 @@ func (s *Storage) GuaranteedUpdate(
return err
}
err = entityToResource(rsp.Entity, destination, s.codec)
err = EntityToRuntimeObject(rsp.Entity, destination, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -605,7 +605,7 @@ func (s *Storage) GuaranteedUpdate(
return nil // destination is already set
}
err = entityToResource(rsp.Entity, destination, s.codec)
err = EntityToRuntimeObject(rsp.Entity, destination, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
@ -676,7 +676,7 @@ decode:
return watch.Bookmark, obj, nil
}
err = entityToResource(resp.Entity, obj, d.codec)
err = EntityToRuntimeObject(resp.Entity, obj, d.codec)
if err != nil {
klog.Errorf("error decoding entity: %s", err)
return watch.Error, nil, err
@ -710,7 +710,7 @@ decode:
prevMatches := false
prevObj := d.newFunc()
if resp.Previous != nil {
err = entityToResource(resp.Previous, prevObj, d.codec)
err = EntityToRuntimeObject(resp.Previous, prevObj, d.codec)
if err != nil {
klog.Errorf("error decoding entity: %s", err)
return watch.Error, nil, err
@ -751,7 +751,7 @@ decode:
// if we have a previous object, return that in the deleted event
if resp.Previous != nil {
err = entityToResource(resp.Previous, obj, d.codec)
err = EntityToRuntimeObject(resp.Previous, obj, d.codec)
if err != nil {
klog.Errorf("error decoding entity: %s", err)
return watch.Error, nil, err

@ -19,7 +19,7 @@ import (
entityStore "github.com/grafana/grafana/pkg/services/store/entity"
)
func entityToResource(rsp *entityStore.Entity, res runtime.Object, codec runtime.Codec) error {
func EntityToRuntimeObject(rsp *entityStore.Entity, res runtime.Object, codec runtime.Codec) error {
var err error
// Read the body first -- it includes old resourceVersion!

@ -201,7 +201,7 @@ func TestEntityToResource(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.entity.Key+" to resource conversion should succeed", func(t *testing.T) {
var p v0alpha1.Playlist
err := entityToResource(tc.entity, &p, Codecs.LegacyCodec(v0alpha1.PlaylistResourceInfo.GroupVersion()))
err := EntityToRuntimeObject(tc.entity, &p, Codecs.LegacyCodec(v0alpha1.PlaylistResourceInfo.GroupVersion()))
require.NoError(t, err)
assert.Equal(t, tc.expectedApiVersion, p.TypeMeta.APIVersion)
assert.Equal(t, tc.expectedCreationTimestamp.Unix(), p.ObjectMeta.CreationTimestamp.Unix())

Loading…
Cancel
Save