// purgeDeletedNamespaces will remove all namespaces enumerated in a reviewRecordStore that are not in the namespace set func purgeDeletedNamespaces(namespaceSet *util.StringSet, userSubjectRecordStore cache.Store, groupSubjectRecordStore cache.Store, reviewRecordStore cache.Store) { reviewRecordItems := reviewRecordStore.List() for i := range reviewRecordItems { reviewRecord := reviewRecordItems[i].(*reviewRecord) if !namespaceSet.Has(reviewRecord.namespace) { deleteNamespaceFromSubjects(userSubjectRecordStore, reviewRecord.users, reviewRecord.namespace) deleteNamespaceFromSubjects(groupSubjectRecordStore, reviewRecord.groups, reviewRecord.namespace) reviewRecordStore.Delete(reviewRecord) } } }
// deleteNamespaceFromSubjects removes the namespace from each subject // if no other namespaces are active to that subject, it will also delete the subject from the cache entirely func deleteNamespaceFromSubjects(subjectRecordStore cache.Store, subjects []string, namespace string) { for _, subject := range subjects { obj, exists, _ := subjectRecordStore.GetByKey(subject) if exists { subjectRecord := obj.(*subjectRecord) delete(subjectRecord.namespaces, namespace) if len(subjectRecord.namespaces) == 0 { subjectRecordStore.Delete(subjectRecord) } } } }