2019-02-21 20:31:18 +02:00
|
|
|
package webhooks
|
|
|
|
|
2019-02-22 18:12:14 +02:00
|
|
|
import (
|
2019-05-06 09:12:37 -07:00
|
|
|
kubeclient "github.com/nirmata/kube-policy/kubeclient"
|
2019-03-04 20:40:02 +02:00
|
|
|
types "github.com/nirmata/kube-policy/pkg/apis/policy/v1alpha1"
|
2019-05-09 22:26:22 -07:00
|
|
|
mutation "github.com/nirmata/kube-policy/pkg/policyengine/mutation"
|
2019-03-04 20:40:02 +02:00
|
|
|
"k8s.io/api/admission/v1beta1"
|
2019-02-22 18:12:14 +02:00
|
|
|
)
|
2019-02-21 20:31:18 +02:00
|
|
|
|
|
|
|
func kindIsSupported(kind string) bool {
|
2019-05-07 13:26:54 -07:00
|
|
|
for _, k := range kubeclient.GetSupportedKinds() {
|
2019-03-04 20:40:02 +02:00
|
|
|
if k == kind {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2019-02-21 20:31:18 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 20:04:23 +02:00
|
|
|
// Checks for admission if kind is supported
|
2019-02-21 20:31:18 +02:00
|
|
|
func AdmissionIsRequired(request *v1beta1.AdmissionRequest) bool {
|
2019-03-04 20:40:02 +02:00
|
|
|
// Here you can make additional hardcoded checks
|
|
|
|
return kindIsSupported(request.Kind.Kind)
|
2019-02-21 20:31:18 +02:00
|
|
|
}
|
2019-02-22 18:12:14 +02:00
|
|
|
|
2019-03-05 20:04:23 +02:00
|
|
|
// Checks requests kind, name and labels to fit the policy
|
2019-05-13 21:27:47 +03:00
|
|
|
func IsRuleApplicableToRequest(policyResource types.ResourceDescription, request *v1beta1.AdmissionRequest) (bool, error) {
|
2019-05-09 22:26:22 -07:00
|
|
|
return mutation.IsRuleApplicableToResource(request.Object.Raw, policyResource)
|
2019-02-22 18:12:14 +02:00
|
|
|
}
|