1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-16 12:40:43 +00:00

move helper to pkg/utils

This commit is contained in:
Shuting Zhao 2020-01-03 10:41:47 -08:00
parent 0c9053d50d
commit dce1e0555a
2 changed files with 11 additions and 12 deletions

View file

@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"flag" "flag"
"reflect"
"time" "time"
"github.com/golang/glog" "github.com/golang/glog"
@ -22,7 +21,6 @@ import (
"github.com/nirmata/kyverno/pkg/version" "github.com/nirmata/kyverno/pkg/version"
"github.com/nirmata/kyverno/pkg/webhookconfig" "github.com/nirmata/kyverno/pkg/webhookconfig"
"github.com/nirmata/kyverno/pkg/webhooks" "github.com/nirmata/kyverno/pkg/webhooks"
"k8s.io/apimachinery/pkg/runtime/schema"
kubeinformers "k8s.io/client-go/informers" kubeinformers "k8s.io/client-go/informers"
) )
@ -79,7 +77,7 @@ func main() {
} }
// TODO(shuting): To be removed for v1.2.0 // TODO(shuting): To be removed for v1.2.0
cleanupOldCrd(client) utils.CleanupOldCrd(client)
// KUBERNETES RESOURCES INFORMER // KUBERNETES RESOURCES INFORMER
// watches namespace resource // watches namespace resource
@ -251,12 +249,3 @@ func init() {
config.LogDefaultFlags() config.LogDefaultFlags()
flag.Parse() 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.Infof("Failed to remove previous CRD namespacedpolicyviolations: %v", err)
}
}
}

View file

@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
dclient "github.com/nirmata/kyverno/pkg/dclient"
) )
//Contains Check if strint is contained in a list of string //Contains Check if strint is contained in a list of string
@ -73,3 +74,12 @@ func CRDInstalled(discovery client.IDiscovery) bool {
} }
return true return true
} }
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.Infof("Failed to remove previous CRD namespacedpolicyviolations: %v", err)
}
}
}