Cleanup schema change reporting

This commit is contained in:
Darren Shepherd 2021-08-09 16:47:09 -07:00
parent bb76e4db56
commit 9f5d802708
3 changed files with 23 additions and 4 deletions

View File

@ -64,6 +64,10 @@ func (l *AccessStore) AccessFor(user user.Info) *AccessSet {
}
func (l *AccessStore) CacheKey(user user.Info) string {
cacheKey, ok := l.cache.Get(user.GetName())
if ok {
return cacheKey.(string)
}
d := sha256.New()
l.users.addRolesToHash(d, user.GetName())
@ -77,5 +81,7 @@ func (l *AccessStore) CacheKey(user user.Info) string {
l.groups.addRolesToHash(d, group)
}
return hex.EncodeToString(d.Sum(nil))
cacheKey = hex.EncodeToString(d.Sum(nil))
l.cache.Add(user.GetName(), cacheKey, 2*time.Second)
return cacheKey.(string)
}

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/rancher/apiserver/pkg/builtin"
"k8s.io/apimachinery/pkg/api/equality"
schemastore "github.com/rancher/apiserver/pkg/store/schema"
"github.com/rancher/apiserver/pkg/types"
@ -96,12 +97,24 @@ func (s *Store) sendSchemas(result chan types.APIEvent, apiOp *types.APIRequest,
inNewSchemas := map[string]bool{}
for _, apiObject := range schemastore.FilterSchemas(apiOp, schemas.Schemas).Objects {
inNewSchemas[apiObject.ID] = true
eventName := types.ChangeAPIEvent
if oldSchema := oldSchemas.LookupSchema(apiObject.ID); oldSchema == nil {
eventName = types.CreateAPIEvent
} else {
newSchemaCopy := apiObject.Object.(*types.APISchema).Schema.DeepCopy()
oldSchemaCopy := oldSchema.Schema.DeepCopy()
newSchemaCopy.Mapper = nil
oldSchemaCopy.Mapper = nil
if equality.Semantic.DeepEqual(newSchemaCopy, oldSchemaCopy) {
continue
}
}
result <- types.APIEvent{
Name: types.ChangeAPIEvent,
Name: eventName,
ResourceType: "schema",
Object: apiObject,
}
inNewSchemas[apiObject.ID] = true
}
for _, oldSchema := range schemastore.FilterSchemas(apiOp, oldSchemas.Schemas).Objects {

View File

@ -29,7 +29,7 @@ func (w *WatchRefresh) Watch(apiOp *types.APIRequest, schema *types.APISchema, w
select {
case <-ctx.Done():
return
case <-time.After(30 * time.Second):
case <-time.After(2 * time.Second):
}
newAs := w.asl.AccessFor(user)