mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
change client.ListResource to take listOptions
This commit is contained in:
parent
a7e55ed25e
commit
3f59b4cf10
4 changed files with 7 additions and 11 deletions
|
@ -50,7 +50,7 @@ func (c *Client) submitAndApproveCertificateRequest(req *certificates.Certificat
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
csrList, err := c.ListResource(CSRs, "", nil)
|
||||
csrList, err := c.ListResource(CSRs, "", metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to list existing certificate requests: %v", err)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
apps "k8s.io/api/apps/v1"
|
||||
certificates "k8s.io/api/certificates/v1beta1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
helperv1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -122,12 +121,8 @@ func (c *Client) PatchResource(kind string, namespace string, name string, patch
|
|||
|
||||
// ListResource returns the list of resources in unstructured/json format
|
||||
// Access items using []Items
|
||||
func (c *Client) ListResource(kind string, namespace string, lselector *meta.LabelSelector) (*unstructured.UnstructuredList, error) {
|
||||
options := meta.ListOptions{}
|
||||
if lselector != nil {
|
||||
options = meta.ListOptions{LabelSelector: helperv1.FormatLabelSelector(lselector)}
|
||||
}
|
||||
return c.getResourceInterface(kind, namespace).List(options)
|
||||
func (c *Client) ListResource(kind string, namespace string, listOption meta.ListOptions) (*unstructured.UnstructuredList, error) {
|
||||
return c.getResourceInterface(kind, namespace).List(listOption)
|
||||
}
|
||||
|
||||
// DeleteResouce deletes the specified resource
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
client "github.com/nirmata/kyverno/pkg/dclient"
|
||||
"github.com/nirmata/kyverno/pkg/engine"
|
||||
"github.com/nirmata/kyverno/pkg/utils"
|
||||
helperv1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
|
@ -86,7 +87,7 @@ func getResourcesPerNamespace(kind string, client *client.Client, namespace stri
|
|||
// ls := mergeLabelSectors(rule.MatchResources.Selector, rule.ExcludeResources.Selector)
|
||||
// list resources
|
||||
glog.V(4).Infof("get resources for kind %s, namespace %s, selector %v", kind, namespace, rule.MatchResources.Selector)
|
||||
list, err := client.ListResource(kind, namespace, ls)
|
||||
list, err := client.ListResource(kind, namespace, metav1.ListOptions{LabelSelector: helperv1.FormatLabelSelector(ls)})
|
||||
if err != nil {
|
||||
glog.Infof("unable to get resources: err %v", err)
|
||||
return nil
|
||||
|
@ -277,7 +278,7 @@ func excludeNamespaces(namespaces, excludeNs []string) []string {
|
|||
func getAllNamespaces(client *client.Client) []string {
|
||||
var namespaces []string
|
||||
// get all namespaces
|
||||
nsList, err := client.ListResource("Namespace", "", nil)
|
||||
nsList, err := client.ListResource("Namespace", "", metav1.ListOptions{})
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
return namespaces
|
||||
|
|
|
@ -265,7 +265,7 @@ func (pvc *PolicyViolationController) syncBlockedResource(curPv *kyverno.Cluster
|
|||
|
||||
// get resource
|
||||
blockedResource := violatedRule.ManagedResource
|
||||
resources, _ := pvc.client.ListResource(blockedResource.Kind, blockedResource.Namespace, nil)
|
||||
resources, _ := pvc.client.ListResource(blockedResource.Kind, blockedResource.Namespace, metav1.ListOptions{})
|
||||
|
||||
for _, resource := range resources.Items {
|
||||
glog.V(4).Infof("getting owners for %s/%s/%s\n", resource.GetKind(), resource.GetNamespace(), resource.GetName())
|
||||
|
|
Loading…
Reference in a new issue