Giter Site home page Giter Site logo

spotahome / kooper Goto Github PK

View Code? Open in Web Editor NEW
492.0 492.0 51.0 5.98 MB

Kooper is a simple Go library to create Kubernetes operators and controllers.

Home Page: https://product.spotahome.com/kooper-extending-kubernetes-made-easy-4e1edd884687

License: Apache License 2.0

Makefile 2.25% Shell 1.49% Go 94.65% Dockerfile 1.61%
controller framework go golang infrastructure k8s kubernetes library operator toolkit

kooper's People

Contributors

apostov avatar dependabot[bot] avatar ese avatar guilhem avatar jchanam avatar jeffersongirao avatar jeffwidman avatar slok avatar snebel29 avatar vad1mo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kooper's Issues

support go-client 0.24.2

Hi,

at the moment is seems, that [email protected] is not supported. It would be great to upgrade to this version.
Currently it fails with:

# github.com/spotahome/kooper/v2/controller/leaderelection
/home/nilsorbat/go/pkg/mod/github.com/spotahome/kooper/[email protected]/controller/leaderelection/leaderelection.go:118:16: undefined: resourcelock.ConfigMapsResourceLock

Compilation finished with exit code 2

According to the docs, the migration should happen like this:

https://github.com/kubernetes/client-go/blob/a16e76eb69cc9eea8e9c9124a64e6e58a583dad2/tools/leaderelection/resourcelock/interface.go#L195

Expose columns for kubectl

Was wondering whether is possible to get additional columns for the custom resource when using kubectl get
In the example for the operator I can see:

NAME               AGE
nginx-controller   1h

In the same object, for instance, is it possible to specify a field to appear there?
Like example:

NAME               AGE    DRYRUN
nginx-controller   1h     true

Thanks!

Possible to get object for DeleteFunc ?

Hi,

I'm wondering if it's possible to get the object associated with the deletion event (in the same way we an with AddFunc).

It looks like the Handler interface only supports Delete(context.Context, string).

Is there an alternative approach available in this lib. that would help me?

Many thanks

        // Our domain logic that will print every add/sync/update and delete event we .
	hand := &handler.HandlerFunc{
		AddFunc: func(_ context.Context, obj runtime.Object) error {
			pod := obj.(*corev1.Pod)
			log.Infof("Pod added: %s/%s", pod.Namespace, pod.Name)
			return nil
		},
		DeleteFunc: func(_ context.Context, s string) error {
			log.Infof("Pod deleted: %s", s)
			return nil
		},
	}

How to get started with Kooper?

It looks like some documentation is missing. Like Previous example.
Which commands to run to create auto-generated code etc?

Issues running example onefile-echo-pod-controller

I tried to run the example https://github.com/spotahome/kooper/blob/master/examples/onefile-echo-pod-controller/main.go but this doesn't work out of the box:

% go run main.go
# command-line-arguments
./main.go:48:9: cannot use "k8s.io/api/core/v1".Pod literal (type *"k8s.io/api/core/v1".Pod) as type "github.com/spotahome/kooper/vendor/k8s.io/apimachinery/pkg/runtime".Object in field value:
	*"k8s.io/api/core/v1".Pod does not implement "github.com/spotahome/kooper/vendor/k8s.io/apimachinery/pkg/runtime".Object (wrong type for DeepCopyObject method)
		have DeepCopyObject() "k8s.io/apimachinery/pkg/runtime".Object
		want DeepCopyObject() "github.com/spotahome/kooper/vendor/k8s.io/apimachinery/pkg/runtime".Object
./main.go:49:16: cannot use "k8s.io/client-go/tools/cache".ListWatch literal (type *"k8s.io/client-go/tools/cache".ListWatch) as type "github.com/spotahome/kooper/vendor/k8s.io/client-go/tools/cache".ListerWatcher in field value:
	*"k8s.io/client-go/tools/cache".ListWatch does not implement "github.com/spotahome/kooper/vendor/k8s.io/client-go/tools/cache".ListerWatcher (wrong type for List method)
		have List("k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions) ("k8s.io/apimachinery/pkg/runtime".Object, error)
		want List("github.com/spotahome/kooper/vendor/k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions) ("github.com/spotahome/kooper/vendor/k8s.io/apimachinery/pkg/runtime".Object, error)
./main.go:61:10: cannot use func literal (type func("k8s.io/apimachinery/pkg/runtime".Object) error) as type handler.AddFunc in field value

To install the missing packages, I simply executed go get -d ./... in the same directory as this file is stored. My go version is 1.10.

Can you help me to get the example running?

Allow requeuing events for the primary resource

Have the same functionality than the one describe on this issue: operator-framework/operator-sdk#146:

Background
A common pattern for operators is to have a sync handler that reconciles events for a primary resource which is usually the Custom Resource(CR) that defines the custom API for the application.
However there are other secondary resources such as:

Resources that the operator creates e.g deployments, services
Resources that the operator does not create but depends on e.g user provided secrets for TLS setup.
The operator needs to receive an event for the primary resource to reconcile the state anytime any of the secondary resources are changed.

The current SDK Watch API allows watching multiple resources that would send all events to the same handler but provides no way to define or requeue events for the primary resource.

Goal
The SDK should provide an API that allows the operator to watch a primary resource and receive requeued primary resource events upon changes to any secondary resources.

Are 1.14. supported

Hi,

According to the compatibility matrix is doesn't seems like Kubernetes 1.14 are supported?

Code examples

I have to write a simple custom ingress controller servicing HTTP GET requests. There is no need of HTTPS, HTTP/2, performance is not important, the routes are very simple. Which of the examples is the closest to what I need?

Is there a better starting point than the examples, like, a very simple ingress controller in Go which I could refactor for my purposes?

Thanks.

Namespace Is Empty In the Handler

What I am trying to do is having the operator running and be responsible for my new CRD across all the namespaces. In the crd.go (as the pod terminator example) I have the following:

func (p *myCRD) GetListerWatcher() cache.ListerWatcher {
	return &cache.ListWatch{
		ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
			return p.myCRDCli.V1alpha1().MyCRD("").List(options)
		},
		WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
			return p.myCRDCli.V1alpha1().MyCRD("").Watch(options)
		},
	}
}

In the above way I am able to monitor the custom CRDs across all the namespaces.
The definition of the CRD is:

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PodTerminator represents a pod terminator.
type MyCRD struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty"`
}

Notice that I omit the nonNamespaced option of the example.
In the handler this code:

func (h *handler) Add(_ context.Context, obj runtime.Object) error {

	pt, ok := obj.(*v1alpha1.MyCRD)
	if !ok {
		return fmt.Errorf("%v is not a valid object", obj.GetObjectKind())
	}
	
        fmt.Println("namespace is :"+pt.Namespace)

it produces an empty namespace.
An example of the object I create is:

apiVersion: v1alpha1
kind: MyCRD
metadata:
  name: test
  namespace: development

Is this the expected behavior? Is it also possible the namespace to be filled out by the current kubectl context?

Thanks a lot!

[help] crd.NewClient require clientset.Interface with Apiextensions

When I use your code (example).

I have this error:

cannot use aexCli (type *versioned.Clientset) as type clientset.Interface in argument to crd.NewClient:
	*versioned.Clientset does not implement clientset.Interface (missing Apiextensions method)

Because crd.NewClient require in first arg a clientset.Interface that implement clientset.Interface with Apiextensions method.

But I dont have Apiextensions method but something like that:
https://github.com/spotahome/kooper/blob/master/examples/pod-terminator-operator/client/k8s/clientset/versioned/clientset.go#L26

Can you help me? Please.

Thanks a lot!

Question: Leader election vs Deployment

Apologies beforehand if the question doesn't make much sense.

Was wondering what is exactly the benefit of running 1+ instances of the controller in leader election mode VS running a deployment of replica 1? In the sense that if somehow the pod dies, the deployment makes sure it gets scheduled again.

It would be good to know status of controller/operator running or not

Hello there,

We would like to know if our controller is running or not. 

Currently, there is no interface available [here] (

type Controller interface {
) to know that. 

Information already exists [here] (

func (g *generic) isRunning() bool {
) on the controller side; we just need to expose it on the interface.

Thanks in advance!

go mod fails

Hi, I am trying to build the example file https://github.com/spotahome/kooper/blob/master/examples/config-custom-controller/main.go
My Dockerfile is

FROM golang:1.15

RUN mkdir /build 
WORKDIR /build
COPY *.go ./
COPY go.mod ./

RUN go mod download
RUN cat go.mod
RUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -a -o /build ./
# RUN go test -v -failfast ./...

I can not resolve the packages

/go/pkg/mod/k8s.io/[email protected]/discovery/discovery_client.go:29:2: module github.com/googleapis/gnostic@latest found (v0.5.4), but does not contain package github.com/googleapis/gnostic/OpenAPIv2
/go/pkg/mod/k8s.io/[email protected]/pkg/util/proto/document.go:24:2: case-insensitive import collision: "github.com/googleapis/gnostic/openapiv2" and "github.com/googleapis/gnostic/OpenAPIv2"
/go/pkg/mod/k8s.io/[email protected]/kubernetes/scheme/register.go:27:2: module k8s.io/api@latest found (v0.20.4), but does not contain package k8s.io/api/auditregistration/v1alpha1
/go/pkg/mod/k8s.io/[email protected]/kubernetes/scheme/register.go:58:2: module k8s.io/api@latest found (v0.20.4), but does not contain package k8s.io/api/settings/v1alpha1

What am I doing wrong?
Thanks

Handler gets all the old events on controller refresh

I tried running the slok/kooper-as-dependency to test kooper, and it seems to print all the events including the old events every 30 seconds.. Is there any way to print only the changes, after the inital list is printed ? Kubernets docs talks about resourceverion param on watch api, but i cant understand how it can be used in kooper's retrievers/handlers to see only the changes?

Thanks,
Prem

Dealing with deletion

I'm building a controller which keeps track of some resources created by other actors (devs, other systems, ...), in order to keep an inventory listing, basically. I've read about the changes leading to the removal of the DeleteFunc, and the new garbage collection docs, but they don't seem to apply cleanly to my use case.
What is the recommended approach for these scenarios where I don't own the resources? Setting a finalizer on objects whose lifecycle I don't control seems both like an RBAC issue (I need cluster- or namespace-wide edit rights on other systems' resources) and a bit of a reliability issue - what if my controller is down? Then I would become a clean-up blocker.

Hoping for some guidance! @slok @ese you wrote/reviewed the PR in question, any thoughts?

I thought about doing something around the resync interval, basically implementing a TTL on the objects I've seen. That would likely work, but seems like a bit of a hack?

update client-go version

recently,i am doing something adout redis-operator,and find this project,i want to upgrade the client-go version,because i found the client-go version we used is too old,and the code looks a little strange,so can we update the client-go version @slok

Get error when running the examples/config-custom-controller

E0322 06:53:10.221034       1 reflector.go:127] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:156: 
Failed to watch <unspecified>: failed to list <unspecified>: 
pods is forbidden: User "system:serviceaccount:default:default" cannot list resource "pods" in API group "" at the cluster scope

What am I doing wrong? Am I missing RBAC Authorization?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.