kandi background

sample-controller | Repository for sample controller | Model View Controller library

Download this library from

kandi X-RAY | sample-controller Summary

sample-controller is a Go library typically used in Architecture, Model View Controller applications. sample-controller has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
This repository implements a simple controller for watching Foo resources as defined with a CustomResourceDefinition (CRD). Note: go-get or vendor this package as k8s.io/sample-controller.

kandi-support Support

  • sample-controller has a medium active ecosystem.
  • It has 2172 star(s) with 799 fork(s). There are 77 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 5 open issues and 68 have been closed. On average issues are closed in 113 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of sample-controller is current.

quality kandi Quality

  • sample-controller has 0 bugs and 0 code smells.

securitySecurity

  • sample-controller has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • sample-controller code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license License

  • sample-controller is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.

buildReuse

  • sample-controller releases are not available. You will need to build from source code and install.
  • Installation instructions are not available. Examples and code snippets are available.
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

sample-controller Key Features

This is an example of how to build a kube-like controller with a single type.

sample-controller Examples and Code Snippets

  • Fetch with godep
  • When using go 1.11 modules
  • Running
  • Defining types
  • Example
  • Cleanup
  • Get annotations from object in k8s event handler
  • Resource not found error performing SSA create using dynamic client

Fetch with godep

go get -d k8s.io/sample-controller
cd $GOPATH/src/k8s.io/sample-controller
godep restore

Community Discussions

Trending Discussions on sample-controller
  • Get annotations from object in k8s event handler
  • Resource not found error performing SSA create using dynamic client
Trending Discussions on sample-controller

QUESTION

Get annotations from object in k8s event handler

Asked 2021-May-27 at 18:51

I'm building a little k8s controller based on the sample-controller.

I'm listening for ServiceAccount events with the following event handler:

...
serviceAccountInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
    AddFunc:    controller.enqueueServiceAccount,
    DeleteFunc: controller.enqueueServiceAccount,
})
...

func (c *Controller) enqueueServiceAccount(obj interface{}) {
    var key string
    var err error

    if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
        utilruntime.HandleError(err)
        return
    }
    c.workqueue.Add(key)
}

This is working fine; my events are coming in and the enqueueServiceAccount() function is getting called.

This is my first foray into Golang and I can't figure out how to get the object's Kubernetes annotations from the obj.

I dumped the object with go-spew and can confirm it's got an ObjectMeta. I'm just not sure how I cast this into some object where I can access the ObjectMeta - and from there it should be easy to get the annotations (in this case this object does't have any, it's one of the <nil> values.

(*v1.ServiceAccount)(0xc0002c1010)(&ServiceAccount{ObjectMeta:{kube-proxy  kube-system /api/v1/namespaces/kube-system/serviceaccounts/kube-proxy d2013421-92c8-44ae-b6d8-202231ea557c 234 0 2021-04-29 18:40:20 +0100 BST <nil> <nil> map[eks.amazonaws.com/component:kube-proxy k8s-app:kube-proxy] map[kubectl.kubernetes.io/last-applied-configuration:{"apiVersion":"v1","kind":"ServiceAccount","metadata":{"annotations":{},"labels":{"eks.amazonaws.com/component":"kube-proxy","k8s-app":"kube-proxy"},"name":"kube-proxy","namespace":"kube-system"}}

How can I access this object's annotations?

ANSWER

Answered 2021-May-27 at 17:35

SampleController is not the most easy code to deal with. They have example on how they cast objects to a known resource type. And they also have example on how they lookup the resource from a lister.

Unless you have specific needs, I would recommend to also consider using kubebuilder and follow the kubebuilder book that has intuitive explanations of making controllers.

Source https://stackoverflow.com/questions/67726840

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install sample-controller

You can download it from GitHub.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Explore Related Topics

Build your Application

Share this kandi XRay Report

Reuse Pre-built Kits with sample-controller