1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-08 17:06:57 +00:00
kyverno/pkg/utils/kube/crd.go
shuting f183154d51
feat: add new updaterequest_controller entrypoint (#6050)
* add ur_controller entrypoint

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* remove commented code

Signed-off-by: ShutingZhao <shuting@nirmata.com>

Signed-off-by: ShutingZhao <shuting@nirmata.com>
2023-01-20 15:53:27 +00:00

35 lines
902 B
Go

package kube
import (
"fmt"
"github.com/kyverno/kyverno/pkg/logging"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type disco interface {
GetGVRFromKind(string) (schema.GroupVersionResource, error)
}
// CRDsInstalled checks if the Kyverno CRDs are installed or not
func CRDsInstalled(discovery disco) bool {
kyvernoCRDs := []string{"ClusterPolicy", "Policy", "ClusterPolicyReport", "PolicyReport", "AdmissionReport", "BackgroundScanReport", "ClusterAdmissionReport", "ClusterBackgroundScanReport", "UpdateRequest"}
for _, crd := range kyvernoCRDs {
if !isCRDInstalled(discovery, crd) {
return false
}
}
return true
}
func isCRDInstalled(discovery disco, kind string) bool {
gvr, err := discovery.GetGVRFromKind(kind)
if gvr.Empty() {
if err == nil {
err = fmt.Errorf("not found")
}
logging.Error(err, "failed to retrieve CRD", "kind", kind)
return false
}
return true
}