1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

658 removing deprecated functions

This commit is contained in:
shravan 2020-02-05 16:33:55 +05:30
parent 12c2909d27
commit a43e7dc9fd
2 changed files with 56 additions and 58 deletions

View file

@ -165,7 +165,7 @@ func (nsc *NamespaceController) processPolicy(policy *kyverno.ClusterPolicy) {
func listpolicies(ns unstructured.Unstructured, pMetaStore policystore.LookupInterface) []kyverno.ClusterPolicy { func listpolicies(ns unstructured.Unstructured, pMetaStore policystore.LookupInterface) []kyverno.ClusterPolicy {
var filteredpolicies []kyverno.ClusterPolicy var filteredpolicies []kyverno.ClusterPolicy
glog.V(4).Infof("listing policies for namespace %s", ns.GetName()) 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 { if err != nil {
glog.Errorf("failed to get list policies: %v", err) glog.Errorf("failed to get list policies: %v", err)
return nil return nil

View file

@ -36,8 +36,6 @@ type UpdateInterface interface {
//LookupInterface provides api to lookup policies //LookupInterface provides api to lookup policies
type LookupInterface interface { type LookupInterface interface {
// Lookup based on kind and namespaces
LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error)
ListAll() ([]kyverno.ClusterPolicy, error) ListAll() ([]kyverno.ClusterPolicy, error)
} }
@ -84,20 +82,20 @@ func (ps *PolicyStore) Register(policy kyverno.ClusterPolicy) {
} }
} }
//LookUp look up the resources ////LookUp look up the resources
func (ps *PolicyStore) LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error) { //func (ps *PolicyStore) LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error) {
ret := []kyverno.ClusterPolicy{} // ret := []kyverno.ClusterPolicy{}
// lookup meta-store // // lookup meta-store
policyNames := ps.lookUp(kind, namespace) // policyNames := ps.lookUp(kind, namespace)
for _, policyName := range policyNames { // for _, policyName := range policyNames {
policy, err := ps.pLister.Get(policyName) // policy, err := ps.pLister.Get(policyName)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
ret = append(ret, *policy) // ret = append(ret, *policy)
} // }
return ret, nil // return ret, nil
} //}
func (ps *PolicyStore) ListAll() ([]kyverno.ClusterPolicy, error) { func (ps *PolicyStore) ListAll() ([]kyverno.ClusterPolicy, error) {
policyPointers, err := ps.pLister.List(labels.NewSelector()) policyPointers, err := ps.pLister.List(labels.NewSelector())
@ -142,47 +140,47 @@ func (ps *PolicyStore) UnRegister(policy kyverno.ClusterPolicy) error {
return nil return nil
} }
//LookUp lookups up the policies for kind and namespace ////LookUp lookups up the policies for kind and namespace
// returns a list of <policy, rule> that statisfy the filters //// returns a list of <policy, rule> that statisfy the filters
func (ps *PolicyStore) lookUp(kind, namespace string) []string { //func (ps *PolicyStore) lookUp(kind, namespace string) []string {
ps.mu.RLock() // ps.mu.RLock()
defer ps.mu.RUnlock() // defer ps.mu.RUnlock()
var policyMap policyMap // var policyMap policyMap
var ret []string // var ret []string
// kind // // kind
kindMap := ps.getKind(kind) // kindMap := ps.getKind(kind)
if kindMap == nil { // if kindMap == nil {
return []string{} // return []string{}
} // }
// get namespace specific policies // // get namespace specific policies
policyMap = kindMap[namespace] // policyMap = kindMap[namespace]
ret = append(ret, transform(policyMap)...) // ret = append(ret, transform(policyMap)...)
// get policies on all namespaces // // get policies on all namespaces
policyMap = kindMap["*"] // policyMap = kindMap["*"]
ret = append(ret, transform(policyMap)...) // ret = append(ret, transform(policyMap)...)
return unique(ret) // return unique(ret)
} //}
//
func unique(intSlice []string) []string { //func unique(intSlice []string) []string {
keys := make(map[string]bool) // keys := make(map[string]bool)
list := []string{} // list := []string{}
for _, entry := range intSlice { // for _, entry := range intSlice {
if _, value := keys[entry]; !value { // if _, value := keys[entry]; !value {
keys[entry] = true // keys[entry] = true
list = append(list, entry) // list = append(list, entry)
} // }
} // }
return list // return list
} //}
//
// generates a copy //// generates a copy
func transform(pmap policyMap) []string { //func transform(pmap policyMap) []string {
ret := []string{} // ret := []string{}
for k := range pmap { // for k := range pmap {
ret = append(ret, k) // ret = append(ret, k)
} // }
return ret // return ret
} //}
func (ps *PolicyStore) addKind(kind string) namespaceMap { func (ps *PolicyStore) addKind(kind string) namespaceMap {
val, ok := ps.data[kind] val, ok := ps.data[kind]