mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
commit
0106afd749
2 changed files with 27 additions and 0 deletions
5
main.go
5
main.go
|
@ -60,6 +60,11 @@ func main() {
|
|||
glog.Fatalf("Error creating client: %v\n", err)
|
||||
}
|
||||
|
||||
// CRD CHECK
|
||||
// - verify if the CRD for Policy & PolicyViolation are avialalbe
|
||||
if !utils.CRDInstalled(client.DiscoveryClient) {
|
||||
glog.Fatalf("Required CRDs unavailable")
|
||||
}
|
||||
// KUBERNETES CLIENT
|
||||
kubeClient, err := utils.NewKubeClient(clientConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/minio/minio/pkg/wildcard"
|
||||
client "github.com/nirmata/kyverno/pkg/dclient"
|
||||
"k8s.io/api/admission/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
@ -94,3 +99,20 @@ func Btoi(b bool) int {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
//CRDInstalled to check if the CRD is installed or not
|
||||
func CRDInstalled(discovery client.IDiscovery) bool {
|
||||
check := func(kind string) bool {
|
||||
gvr := discovery.GetGVRFromKind(kind)
|
||||
if reflect.DeepEqual(gvr, (schema.GroupVersionResource{})) {
|
||||
glog.Errorf("%s CRD not installed", kind)
|
||||
return false
|
||||
}
|
||||
glog.Infof("CRD %s found ", kind)
|
||||
return true
|
||||
}
|
||||
if !check("Policy") || !check("PolicyViolation") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue