A kubernetes operator demo generated by code-generator, it only watches cr's events

intro

a small operator demo which only watches car cr's events.

environment:

ubuntu-20.04-amd64
k3s-1.21
docker-20.10.7
go-1.17

tools

code-generator

download dependences

go mod get -u ./...
go mod vendor

code generate

sudo chmod +x vendor/k8s.io/code-generator/generate-groups.sh
make code_gen

build controller

make build

run controller

make run

regist CRD

kubectl apply -f crd/car.yaml

create CR

kubectl apply -f cr/car.yaml

get CR info

kubectl describe car example-car

practice

regist crd and run controller, you will get:

go run . -kubeconfig /etc/rancher/k3s/k3s.yaml -alsologtostderr=true
I1116 15:47:20.211328  746138 controller.go:82] Setting up event handlers
I1116 15:47:20.211944  746138 controller.go:112] Starting car control loop
I1116 15:47:20.211955  746138 controller.go:114] Waiting for informer caches to sync
I1116 15:47:20.312421  746138 controller.go:119] Starting workers
I1116 15:47:20.312485  746138 controller.go:125] Starting workers

if you create or update a example-car cr in k3s/k8s, you will get:

I1116 15:47:47.780189  746138 controller.go:181] Successfully synced 'default/example-car'
I1116 15:47:47.780265  746138 event.go:282] Event(v1.ObjectReference{Kind:"Car", Namespace:"default", Name:"example-car", UID:"50d0c928-1e1c-4c68-aafd-37a832d576c3", APIVersion:"samplecrd.github.com/v1", ResourceVersion:"61815", FieldPath:""}): type: 'Normal' reason: 'Synced' Car synced successfully

if you delete this cr, you will get:

W1116 15:57:31.026478  746138 controller.go:209] Car: default/example-car does not exist in local cache, will delete it from carset
I1116 15:57:31.026807  746138 controller.go:212] Deleting Car: default/example-car ...
I1116 15:57:31.026816  746138 controller.go:181] Successfully synced 'default/example-car'
Similar Resources

A kubernetes controller that watches the Deployments and “caches” the images

A kubernetes controller that watches the Deployments and “caches” the images

image-cloner This is just an exercise. It's a kubernetes controller that watches

Dec 20, 2021

A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore

bookstore-sample-controller A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore. A resource cre

Jan 20, 2022

Test Operator using operator-sdk 1.15

test-operator Test Operator using operator-sdk 1.15 operator-sdk init --domain rbt.com --repo github.com/ravitri/test-operator Writing kustomize manif

Dec 28, 2021

a k8s operator 、operator-sdk

helloworld-operator a k8s operator 、operator-sdk Operator 参考 https://jicki.cn/kubernetes-operator/ https://learnku.com/articles/60683 https://opensour

Jan 27, 2022

Operator Permissions Advisor is a CLI tool that will take a catalog image and statically parse it to determine what permissions an Operator will request of OLM during an install

Operator Permissions Advisor is a CLI tool that will take a catalog image and statically parse it to determine what permissions an Operator will request of OLM during an install. The permissions are aggregated from the following sources:

Apr 22, 2022

The OCI Service Operator for Kubernetes (OSOK) makes it easy to connect and manage OCI services from a cloud native application running in a Kubernetes environment.

OCI Service Operator for Kubernetes Introduction The OCI Service Operator for Kubernetes (OSOK) makes it easy to create, manage, and connect to Oracle

Sep 27, 2022

PolarDB-X Operator is a Kubernetes extension that aims to create and manage PolarDB-X cluster on Kubernetes.

GalaxyKube -- PolarDB-X Operator PolarDB-X Operator is a Kubernetes extension that aims to create and manage PolarDB-X cluster on Kubernetes. It follo

Dec 19, 2022

Kubernetes Operator to sync secrets between different secret backends and Kubernetes

Vals-Operator Here at Digitalis we love vals, it's a tool we use daily to keep secrets stored securely. We also use secrets-manager on the Kubernetes

Nov 13, 2022

The NiFiKop NiFi Kubernetes operator makes it easy to run Apache NiFi on Kubernetes.

The NiFiKop NiFi Kubernetes operator makes it easy to run Apache NiFi on Kubernetes.

The NiFiKop NiFi Kubernetes operator makes it easy to run Apache NiFi on Kubernetes. Apache NiFI is a free, open-source solution that support powerful and scalable directed graphs of data routing, transformation, and system mediation logic.

Dec 26, 2022
An operator which complements grafana-operator for custom features which are not feasible to be merged into core operator

Grafana Complementary Operator A grafana which complements grafana-operator for custom features which are not feasible to be merged into core operator

Aug 16, 2022
A standalone exporter for vulnerability reports and other CRs created by Starboard.

starboard-exporter Exposes Prometheus metrics from Starboard's VulnerabilityReport custom resources (CRs). Metrics This exporter exposes two types of

Dec 14, 2022
A kubernetes operator sample generated by kubebuilder , which run cmd in pod on specified time

init kubebuilder init --domain github.com --repo github.com/tonyshanc/sample-operator-v2 kubebuilder create api --group sample --version v1 --kind At

Jan 25, 2022
Kubernetes Admission Controller Demo: Validating Webhook for Namespace lifecycle events

Kubernetes Admission Controller Based on How to build a Kubernetes Webhook | Admission controllers Local Kuberbetes cluster # create kubernetes cluste

Feb 27, 2022
The Elastalert Operator is an implementation of a Kubernetes Operator, to easily integrate elastalert with gitops.

Elastalert Operator for Kubernetes The Elastalert Operator is an implementation of a Kubernetes Operator. Getting started Firstly, learn How to use el

Jun 28, 2022
Minecraft-operator - A Kubernetes operator for Minecraft Java Edition servers

Minecraft Operator A Kubernetes operator for dedicated servers of the video game

Dec 15, 2022
K8s-network-config-operator - Kubernetes network config operator to push network config to switches

Kubernetes Network operator Will add more to the readme later :D Operations The

May 16, 2022
Pulumi-k8s-operator-example - OpenGitOps Compliant Pulumi Kubernetes Operator Example

Pulumi GitOps Example OpenGitOps Compliant Pulumi Kubernetes Operator Example Pr

May 6, 2022
Kubernetes Operator Samples using Go, the Operator SDK and OLM
Kubernetes Operator Samples using Go, the Operator SDK and OLM

Kubernetes Operator Patterns and Best Practises This project contains Kubernetes operator samples that demonstrate best practices how to develop opera

Nov 24, 2022