From ae952f73ab8091dc159f601c64748d668e160395 Mon Sep 17 00:00:00 2001 From: belyshevdenis Date: Thu, 28 Feb 2019 14:25:47 +0200 Subject: [PATCH] NK-10: Fixed group name in crd.yaml and register.go. Fixed crash in controller, removed name checking in the root of admission request. --- controller/controller.go | 8 +++++++- crd/crd.yaml | 4 ++-- pkg/apis/policy/register.go | 2 +- webhooks/admission.go | 5 ++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 94da05a69d..5ec827f8a8 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -2,6 +2,7 @@ package controller import ( "log" + "os" "time" "k8s.io/apimachinery/pkg/labels" @@ -23,6 +24,10 @@ type PolicyController struct { // NewPolicyController from cmd args func NewPolicyController(masterURL, kubeconfigPath string, logger *log.Logger) (*PolicyController, error) { + if logger == nil { + logger = log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile) + } + cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath) if err != nil { logger.Printf("Error building kubeconfig: %v\n", err) @@ -41,6 +46,7 @@ func NewPolicyController(masterURL, kubeconfigPath string, logger *log.Logger) ( controller := &PolicyController{ policyInformerFactory: policyInformerFactory, policyLister: policyInformer.Lister(), + logger: logger, } policyInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ @@ -54,7 +60,7 @@ func NewPolicyController(masterURL, kubeconfigPath string, logger *log.Logger) ( // Run is main controller thread func (c *PolicyController) Run(stopCh <-chan struct{}) { - //c.policyInformerFactory.Start(stopCh) + c.policyInformerFactory.Start(stopCh) } // GetPolicies retrieves all policy resources diff --git a/crd/crd.yaml b/crd/crd.yaml index d4028c8be8..c1e0e303a4 100644 --- a/crd/crd.yaml +++ b/crd/crd.yaml @@ -1,9 +1,9 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: policies.nirmata.io + name: policies.policy.nirmata.io spec: - group: nirmata.io + group: policy.nirmata.io versions: - name: v1alpha1 served: true diff --git a/pkg/apis/policy/register.go b/pkg/apis/policy/register.go index 80b52455ef..a3301eb74f 100644 --- a/pkg/apis/policy/register.go +++ b/pkg/apis/policy/register.go @@ -1,5 +1,5 @@ package policy const ( - GroupName = "nirmata.io" + GroupName = "policy.nirmata.io" ) diff --git a/webhooks/admission.go b/webhooks/admission.go index e354f85027..698128bf87 100644 --- a/webhooks/admission.go +++ b/webhooks/admission.go @@ -48,8 +48,7 @@ func IsRuleResourceFitsRequest(resource types.PolicyResource, request *v1beta1.A if resource.Kind != request.Kind.Kind { return false } - if resource.Name != nil && *resource.Name != request.Name { - return false - } + // TODO: resource.Name must be equal to request.Object.Raw -> /metadata/name + return true }