mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
658 removing deprecated functions
This commit is contained in:
parent
12c2909d27
commit
a43e7dc9fd
2 changed files with 56 additions and 58 deletions
|
@ -165,7 +165,7 @@ func (nsc *NamespaceController) processPolicy(policy *kyverno.ClusterPolicy) {
|
|||
func listpolicies(ns unstructured.Unstructured, pMetaStore policystore.LookupInterface) []kyverno.ClusterPolicy {
|
||||
var filteredpolicies []kyverno.ClusterPolicy
|
||||
glog.V(4).Infof("listing policies for namespace %s", ns.GetName())
|
||||
policies, err := pMetaStore.LookUp(ns.GetKind(), ns.GetNamespace())
|
||||
policies, err := pMetaStore.ListAll()
|
||||
if err != nil {
|
||||
glog.Errorf("failed to get list policies: %v", err)
|
||||
return nil
|
||||
|
|
|
@ -36,8 +36,6 @@ type UpdateInterface interface {
|
|||
|
||||
//LookupInterface provides api to lookup policies
|
||||
type LookupInterface interface {
|
||||
// Lookup based on kind and namespaces
|
||||
LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error)
|
||||
ListAll() ([]kyverno.ClusterPolicy, error)
|
||||
}
|
||||
|
||||
|
@ -84,20 +82,20 @@ func (ps *PolicyStore) Register(policy kyverno.ClusterPolicy) {
|
|||
}
|
||||
}
|
||||
|
||||
//LookUp look up the resources
|
||||
func (ps *PolicyStore) LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error) {
|
||||
ret := []kyverno.ClusterPolicy{}
|
||||
// lookup meta-store
|
||||
policyNames := ps.lookUp(kind, namespace)
|
||||
for _, policyName := range policyNames {
|
||||
policy, err := ps.pLister.Get(policyName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret = append(ret, *policy)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
////LookUp look up the resources
|
||||
//func (ps *PolicyStore) LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error) {
|
||||
// ret := []kyverno.ClusterPolicy{}
|
||||
// // lookup meta-store
|
||||
// policyNames := ps.lookUp(kind, namespace)
|
||||
// for _, policyName := range policyNames {
|
||||
// policy, err := ps.pLister.Get(policyName)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// ret = append(ret, *policy)
|
||||
// }
|
||||
// return ret, nil
|
||||
//}
|
||||
|
||||
func (ps *PolicyStore) ListAll() ([]kyverno.ClusterPolicy, error) {
|
||||
policyPointers, err := ps.pLister.List(labels.NewSelector())
|
||||
|
@ -142,47 +140,47 @@ func (ps *PolicyStore) UnRegister(policy kyverno.ClusterPolicy) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//LookUp lookups up the policies for kind and namespace
|
||||
// returns a list of <policy, rule> that statisfy the filters
|
||||
func (ps *PolicyStore) lookUp(kind, namespace string) []string {
|
||||
ps.mu.RLock()
|
||||
defer ps.mu.RUnlock()
|
||||
var policyMap policyMap
|
||||
var ret []string
|
||||
// kind
|
||||
kindMap := ps.getKind(kind)
|
||||
if kindMap == nil {
|
||||
return []string{}
|
||||
}
|
||||
// get namespace specific policies
|
||||
policyMap = kindMap[namespace]
|
||||
ret = append(ret, transform(policyMap)...)
|
||||
// get policies on all namespaces
|
||||
policyMap = kindMap["*"]
|
||||
ret = append(ret, transform(policyMap)...)
|
||||
return unique(ret)
|
||||
}
|
||||
|
||||
func unique(intSlice []string) []string {
|
||||
keys := make(map[string]bool)
|
||||
list := []string{}
|
||||
for _, entry := range intSlice {
|
||||
if _, value := keys[entry]; !value {
|
||||
keys[entry] = true
|
||||
list = append(list, entry)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// generates a copy
|
||||
func transform(pmap policyMap) []string {
|
||||
ret := []string{}
|
||||
for k := range pmap {
|
||||
ret = append(ret, k)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
////LookUp lookups up the policies for kind and namespace
|
||||
//// returns a list of <policy, rule> that statisfy the filters
|
||||
//func (ps *PolicyStore) lookUp(kind, namespace string) []string {
|
||||
// ps.mu.RLock()
|
||||
// defer ps.mu.RUnlock()
|
||||
// var policyMap policyMap
|
||||
// var ret []string
|
||||
// // kind
|
||||
// kindMap := ps.getKind(kind)
|
||||
// if kindMap == nil {
|
||||
// return []string{}
|
||||
// }
|
||||
// // get namespace specific policies
|
||||
// policyMap = kindMap[namespace]
|
||||
// ret = append(ret, transform(policyMap)...)
|
||||
// // get policies on all namespaces
|
||||
// policyMap = kindMap["*"]
|
||||
// ret = append(ret, transform(policyMap)...)
|
||||
// return unique(ret)
|
||||
//}
|
||||
//
|
||||
//func unique(intSlice []string) []string {
|
||||
// keys := make(map[string]bool)
|
||||
// list := []string{}
|
||||
// for _, entry := range intSlice {
|
||||
// if _, value := keys[entry]; !value {
|
||||
// keys[entry] = true
|
||||
// list = append(list, entry)
|
||||
// }
|
||||
// }
|
||||
// return list
|
||||
//}
|
||||
//
|
||||
//// generates a copy
|
||||
//func transform(pmap policyMap) []string {
|
||||
// ret := []string{}
|
||||
// for k := range pmap {
|
||||
// ret = append(ret, k)
|
||||
// }
|
||||
// return ret
|
||||
//}
|
||||
|
||||
func (ps *PolicyStore) addKind(kind string) namespaceMap {
|
||||
val, ok := ps.data[kind]
|
||||
|
|
Loading…
Add table
Reference in a new issue