2023-03-13 14:44:39 +00:00
|
|
|
package policycache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
2023-03-17 11:21:26 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2023-03-13 14:44:39 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
podsGVR = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
|
|
|
namespacesGVR = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "namespaces"}
|
|
|
|
clusterrolesGVR = schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterroles"}
|
|
|
|
deploymentsGVR = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
|
|
|
|
statefulsetsGVR = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}
|
|
|
|
daemonsetsGVR = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"}
|
|
|
|
jobsGVR = schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "jobs"}
|
|
|
|
cronjobsGVR = schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "cronjobs"}
|
|
|
|
replicasetsGVR = schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicasets"}
|
|
|
|
replicationcontrollersGVR = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "replicationcontrollers"}
|
|
|
|
|
|
|
|
podsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: podsGVR}
|
|
|
|
namespacesGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: namespacesGVR}
|
|
|
|
clusterrolesGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: clusterrolesGVR}
|
|
|
|
deploymentsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: deploymentsGVR}
|
|
|
|
statefulsetsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: statefulsetsGVR}
|
|
|
|
daemonsetsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: daemonsetsGVR}
|
|
|
|
jobsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: jobsGVR}
|
|
|
|
cronjobsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: cronjobsGVR}
|
|
|
|
replicasetsGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: replicasetsGVR}
|
|
|
|
replicationcontrollersGVRS = dclient.GroupVersionResourceSubresource{GroupVersionResource: replicationcontrollersGVR}
|
|
|
|
)
|
|
|
|
|
|
|
|
type TestResourceFinder struct{}
|
|
|
|
|
2023-03-17 11:21:26 +00:00
|
|
|
func (TestResourceFinder) FindResources(group, version, kind, subresource string) (map[dclient.GroupVersionResourceSubresource]metav1.APIResource, error) {
|
|
|
|
var dummy metav1.APIResource
|
2023-03-13 14:44:39 +00:00
|
|
|
switch kind {
|
|
|
|
case "Pod":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{podsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "Namespace":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{namespacesGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "ClusterRole":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{clusterrolesGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "Deployment":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{deploymentsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "StatefulSet":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{statefulsetsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "DaemonSet":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{daemonsetsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "ReplicaSet":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{replicasetsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "Job":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{jobsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "ReplicationController":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{replicationcontrollersGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
case "CronJob":
|
2023-03-17 11:21:26 +00:00
|
|
|
return map[dclient.GroupVersionResourceSubresource]metav1.APIResource{cronjobsGVRS: dummy}, nil
|
2023-03-13 14:44:39 +00:00
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("not found: %s", kind)
|
|
|
|
}
|