1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 02:45:06 +00:00

remove old crd namespacedpolicyviolation

This commit is contained in:
Shuting Zhao 2020-01-02 15:33:57 -08:00
parent db4d3d2c8c
commit b5192dc559
2 changed files with 15 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"reflect"
"time"
"github.com/golang/glog"
@ -21,6 +22,7 @@ import (
"github.com/nirmata/kyverno/pkg/version"
"github.com/nirmata/kyverno/pkg/webhookconfig"
"github.com/nirmata/kyverno/pkg/webhooks"
"k8s.io/apimachinery/pkg/runtime/schema"
kubeinformers "k8s.io/client-go/informers"
)
@ -76,6 +78,9 @@ func main() {
glog.Fatalf("Error creating kubernetes client: %v\n", err)
}
// TODO(shuting): To be removed for v1.2.0
cleanupOldCrd(client)
// KUBERNETES RESOURCES INFORMER
// watches namespace resource
// - cache resync time: 10 seconds
@ -246,3 +251,12 @@ func init() {
config.LogDefaultFlags()
flag.Parse()
}
func cleanupOldCrd(client *dclient.Client) {
gvr := client.DiscoveryClient.GetGVRFromKind("NamespacedPolicyViolation")
if !reflect.DeepEqual(gvr, (schema.GroupVersionResource{})) {
if err := client.DeleteResource("CustomResourceDefinition", "", "namespacedpolicyviolations.kyverno.io", false); err != nil {
glog.Info("Failed to remove previous CRD namespacedpolicyviolations: %v", err)
}
}
}

View file

@ -68,7 +68,7 @@ func CRDInstalled(discovery client.IDiscovery) bool {
glog.Infof("CRD %s found ", kind)
return true
}
if !check("ClusterPolicy") || !check("ClusterPolicyViolation") {
if !check("ClusterPolicy") || !check("ClusterPolicyViolation") || !check("PolicyViolation") {
return false
}
return true