mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
NK9: Updated policy crd and added minimal policy sample to check controller functions
This commit is contained in:
parent
e96562a1cf
commit
ddf3e4c278
4 changed files with 24 additions and 12 deletions
|
@ -49,13 +49,12 @@ func NewController(masterURL, kubeconfigPath string) (*Controller, error) {
|
|||
workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Policies"),
|
||||
}
|
||||
|
||||
// Set up an event handler for when Foo resources change
|
||||
policyInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: controller.enqueueFoo,
|
||||
AddFunc: controller.enqueue,
|
||||
UpdateFunc: func(old, new interface{}) {
|
||||
controller.enqueueFoo(new)
|
||||
controller.enqueue(new)
|
||||
},
|
||||
DeleteFunc: controller.enqueueFoo,
|
||||
DeleteFunc: controller.enqueue,
|
||||
})
|
||||
|
||||
return controller, nil
|
||||
|
@ -69,7 +68,7 @@ func (c *Controller) Run(threadiness int) error {
|
|||
defer c.workqueue.ShutDown()
|
||||
|
||||
// Start the informer factories to begin populating the informer caches
|
||||
fmt.Println("Starting Foo controller")
|
||||
fmt.Println("Starting controller")
|
||||
|
||||
if ok := cache.WaitForCacheSync(stopCh, c.policiesSynced); !ok {
|
||||
return fmt.Errorf("failed to wait for caches to sync")
|
||||
|
@ -88,12 +87,12 @@ func (c *Controller) Run(threadiness int) error {
|
|||
|
||||
func (c *Controller) runWorker() {
|
||||
for {
|
||||
time.Sleep(5 * time.Second)
|
||||
fmt.Println("I will wait here for 5 secs...")
|
||||
time.Sleep(25 * time.Second)
|
||||
fmt.Println("I will wait here for 25 secs...")
|
||||
}
|
||||
}
|
||||
|
||||
func (*Controller) enqueueFoo(interface{}) {
|
||||
func (*Controller) enqueue(interface{}) {
|
||||
fmt.Println("I have found changes on Policy Resource")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: policies.policy.nirmata.io
|
||||
name: policies.nirmata.io
|
||||
spec:
|
||||
group: policy.nirmata.io
|
||||
group: nirmata.io
|
||||
versions:
|
||||
- name: v1alpha1
|
||||
served: true
|
||||
storage: true
|
||||
scope: Namespaced
|
||||
names:
|
||||
kind: Policy
|
||||
plural: policies
|
||||
|
|
7
crd/sample-policy.yaml
Normal file
7
crd/sample-policy.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
apiVersion: nirmata.io/v1alpha1
|
||||
kind: Policy
|
||||
metadata:
|
||||
name: hello-policy
|
||||
spec:
|
||||
policySpec: 'hi'
|
||||
image: hello-policy-image
|
5
main.go
5
main.go
|
@ -18,12 +18,13 @@ func main() {
|
|||
|
||||
controller, err := controller.NewController(masterURL, kubeconfig)
|
||||
if err != nil {
|
||||
fmt.Println("Error running Controller!")
|
||||
fmt.Printf("Error creating Controller! Error: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = controller.Run(runtime.NumCPU())
|
||||
if err != nil {
|
||||
fmt.Println("Error running Controller!")
|
||||
fmt.Printf("Error running Controller! Error: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue