-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance YurtHub's caching ability #225
Conversation
@qclc Very much appreciate for your work that refactor cache manager in yurthub component. |
Thanks for your suggestions, I will fix the error and merge all commits. |
6c0d780
to
9aaa238
Compare
ab5eed7
to
8e46456
Compare
8e46456
to
6a95bed
Compare
} else { | ||
tmp := new(unstructured.UnstructuredList) | ||
tmp.SetGroupVersionKind(listGvk) | ||
listObj = tmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about delete tmp var and like that:
listObj = new(unstructured.UnstructuredList)
listObj.GetObjectKind().SetGroupVersionKind(listGvk)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is already updated, thanks for review
tmp := new(unstructured.UnstructuredList) | ||
tmp.SetGroupVersionKind(listGvk) | ||
listObj = tmp | ||
} | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about move this if statement
after 163 line(listObj, err = scheme.Scheme.New(listGvk)
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is already updated, thanks for review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe comment is confusing, The if err !=nil
statement is only need by listObj, err = scheme.Scheme.New(listGvk)
, so move into the following if statement.
if scheme.Scheme.Recognizes(listGvk) {
listObj, err = scheme.Scheme.New(listGvk)
if err != nil {
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for reminding me
// Decode does not do conversion. It keeps the gvk during deserialization. | ||
func (d WithVersionDecoder) Decode(data []byte, defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) { | ||
obj, gvk, err := d.Decoder.Decode(data, defaults, into) | ||
return obj, gvk, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about return d.Decoder.Decode(data, defaults, into)
directly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is already updated, thanks for review
mediaTypes := sm.NegotiatedSerializer.SupportedMediaTypes() | ||
func (sm *SerializerManager) CreateSerializers(contentType, group, version, apiPrefix string) (*rest.Serializers, error) { | ||
var mediaTypes []runtime.SerializerInfo | ||
if apiPrefix == "api" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some normal gvk with apiPrefix="api" and contentType="xxx.protobuf.xxx", and CreateSerializers
can not handle them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my suggestion: use gvr + restMapper to get gvk, so select serializer based on gvk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is already updated, thanks for review
@@ -145,7 +156,18 @@ func (sw *storageWrapper) List(key string) ([]runtime.Object, error) { | |||
} | |||
|
|||
for i := range bb { | |||
obj, gvk, err := sw.backendSerializer.Decode(bb[i], nil, nil) | |||
//get the gvk from json data | |||
gvk, err := json.DefaultMetaFactory.Interpret(bb[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about move Interpret
out of for
loop, so run Interpret
only one time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is already updated, thanks for review
6171e97
to
1491e3f
Compare
@@ -248,20 +221,21 @@ func (cm *cacheManager) saveWatchObject(ctx context.Context, info *apirequest.Re | |||
|
|||
comp, _ := util.ClientComponentFrom(ctx) | |||
reqContentType, _ := util.ReqContentTypeFrom(ctx) | |||
serializers, err := cm.serializerManager.CreateSerializers(reqContentType, info.APIGroup, info.APIVersion) | |||
serializers, err := cm.serializerManager.CreateSerializers(reqContentType, "", "v1", "events") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a serializer for WatchEvent
, so maybe need to use cm.serializerManager.CreateSerializers(reqContentType, info.APIGroup, info.APIVersion, "watchevent")
to create serializer.
and before making a pr we need to build a yurthub image and make sure the new image can work no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is already updated, thanks for review
// our resources. | ||
for _, gv := range defaultGroupVersions { | ||
for kind := range scheme.KnownTypes(gv) { | ||
scope := meta.RESTScopeNamespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that scopes for all gvk are meta.RESTScopeNamespace
is not make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is already updated, thanks for review
352e7a4
to
1301a90
Compare
ns: "default", | ||
kind: "CronTab", | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about add a namespaced=false test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test cases is already added, thanks for review.
@@ -0,0 +1,117 @@ | |||
package cachemanager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add OpenYurt license info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License info is already added, thanks for review.
handlers := hl.GetHandlers(gvk) | ||
if handlers != nil { | ||
var newobj runtime.Object | ||
newobj = obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newobj is redundant, how about use obj directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is already updated, thanks for review
var newobj runtime.Object | ||
newobj = obj | ||
for _, handler := range handlers { | ||
tmp, err := handler.ServeObject(newobj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tmp is the same as newobj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is already updated, thanks for review
} | ||
|
||
//SelectAndProcess determines whether an object meets the filter criteria and processes it if it does | ||
func (hl *HandlerLayer) SelectAndProcess(obj runtime.Object) (runtime.Object, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller of SelectAndProcess is not found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is already updated, change SelectAndProcess to Filter function
type HandlerLayer struct { | ||
sync.Mutex | ||
handlers map[schema.GroupVersionKind][]Handler | ||
selectors map[schema.GroupVersionKind]*storage.SelectionPredicate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SelectionPredicate
is a good idea, but I think that we need to filter object not only based on labels and fields. How about define a common filter function? like Filter(obj runtime.Object) bool
, and SelectionPredicate
is only a specific case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The storage.AttrFunc of SelectionPredicate is used to extract the corresponding field data from the actual Object, which is defined by the user. It can basically meet the matching of all fields of runtime.Object. The newly added hanler_layer_test.go has concrete examples to refer to
1301a90
to
ec500a2
Compare
ec500a2
to
4228462
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Enhance YurtHub's caching ability
Ⅰ. Describe what this PR does
Ⅱ. Does this pull request fix one issue?
fixes #162
This PR extends the ability to cache CR resources, removing the restriction that only resources in resourceToKindMap and resourceToListKindMap can be cached.
Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews