upgrade from controller-runtime 0.6.5. Reactor substitute.

Upgrade Kubernetes Controller Runtime from v0.6.5

This blog concentrates on test case migration as the real code migration pretty detailed and straight forward on official kubernetes websites.

Are you still using version sigs.k8s.io/controller-runtime v0.6.5, time to rethink your choice, as it has costlier bugs that ends up in event failure(s) or misses. The projects that uses the kubernetes operators extensively depends on optimal management of events.

Kubernetes upgrades related to operators usually comes up with breaking this time along with test cases.

The reactors were once been handy to test the edge scenarios, as the projects grows, test cases grows exponentially, and when it comes to a method that is removed / unusable from core library however leveraged extensively by dependant or child projects... 😭

stack overflow

Major Hurdle

The reactors are unusable via fakes along with ClientBuilder.

Test Cases

The operators (or) reconciler's test cases are heavily depndent on reactors and it is not a good idea to add those to technical debts or just ignore them.

FakeReactor instead of Reactor

Based on researches digging deep into the kubernetes libraries and some searches, generalized the usage of FakeReactor, that could be imported and used by any project.

How to use

go get github.com/DreamAmbitious/k8s-controller-runtime-fake
  • Old client with reactors, would look like below
fakeK8Client.PrependReactor(
		"get",
		"objectKind",
		func(action k8stesting.Action) (bool, runtime.Object, error) {
			return true, nil, errs.New("k8s error")
		}
)
  • Replace your reactors as below with FakeReactingCtrlRuntimeClient
mp := make(map[string]ctrlfake.FakeRunTimeMock)
// CRUD methods create/read/update/delete in lower case, kind refers resource object kind of your operator.
mp["method_kind"] = ctrlfake.FakeRunTimeMock{
	MockFunc: func() (client.Object, error) {
		return nil, errs.New("fake output that you're returning")
	},
)
fakeV1alpha1Client := &ctrlfake.FakeReactingCtrlRuntimeClient{
	Client:          reconcilerClient,
	FakeRunTimeMock: mp,
}

🚯 As this is a mock function, it comes up with more power and responsibility.

initObjects := []runtime.Object{
	// load all the objects, that is required during runtime while testing
}
k8client := fakectrlruntime.NewClientBuilder().WithScheme(fakeRuntimeScheme).WithRuntimeObjects(initObjects...).Build()

Conclusion

The library can be leverage to test the edge and more complex cases.

Owner
Similar Resources

A Kubernetes Terraform Controller

A Kubernetes Terraform Controller

Terraform Controller Terraform Controller is a Kubernetes Controller for Terraform, which can address the requirement of Using Terraform HCL as IaC mo

Jan 2, 2023

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes. This project is inspired by agones. Introduction Genera

Nov 25, 2022

A fluxcd controller for managing remote manifests with kubecfg

kubecfg-operator A fluxcd controller for managing remote manifests with kubecfg This project is in very early stages proof-of-concept. Only latest ima

Nov 1, 2022

the simplest testing framework for Kubernetes controller.

KET(Kind E2e Test framework) KET is the simplest testing framework for Kubernetes controller. KET is available as open source software, and we look fo

Dec 10, 2022

Kubernetes workload controller for container image deployment

kube-image-deployer kube-image-deployer는 Docker Registry의 Image:Tag를 감시하는 Kubernetes Controller입니다. Keel과 유사하지만 단일 태그만 감시하며 더 간결하게 동작합니다. Container, I

Mar 8, 2022

Knative Controller which emits cloud events when Knative Resources change state

Knative Sample Controller Knative sample-controller defines a few simple resources that are validated by webhook and managed by a controller to demons

Oct 2, 2021

A controller managing namespaces deployments, statefulsets and cronjobs objects. Inspired by kube-downscaler.

kube-ns-suspender Kubernetes controller managing namespaces life cycle. kube-ns-suspender Goal Usage Internals The watcher The suspender Flags Resourc

Dec 27, 2022

K8s controller implementing Multi-Cluster Services API based on AWS Cloud Map.

AWS Cloud Map MCS Controller for K8s Introduction AWS Cloud Map multi-cluster service discovery for Kubernetes (K8s) is a controller that implements e

Dec 17, 2022

A Pulumi NGINX Ingress Controller component

Pulumi NGINX Ingress Controller Component This repo contains the Pulumi NGINX Ingress Controller component for Kubernetes. This ingress controller use

Aug 10, 2022
Image clone controller is a kubernetes controller to safe guard against the risk of container images disappearing

Image clone controller image clone controller is a kubernetes controller to safe guard against the risk of container images disappearing from public r

Oct 10, 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
Write controller-runtime based k8s controllers that read/write to git, not k8s

Git Backed Controller The basic idea is to write a k8s controller that runs against git and not k8s apiserver. So the controller is reading and writin

Dec 10, 2021
The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the operator-sdk or controller-runtime.

k8s-generic-webhook The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the opera

Nov 24, 2022
Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Kubedd – Check migration issues of Kubernetes Objects while K8s upgrade

Dec 19, 2022
GoMota - a mass upgrade tool for Tasmota devices.

GoMota GoMota is a mass upgrade tool for Tasmota devices. For each execution, multiple devices on the specified network can be upgraded one version, a

May 12, 2022
terraform-plugin-mux Example (upgrade(sdk/v2) + framework)

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

Feb 8, 2022
Annotated and kubez-autoscaler-controller will maintain the HPA automatically for kubernetes resources.

Kubez-autoscaler Overview kubez-autoscaler 通过为 deployment / statefulset 添加 annotations 的方式,自动维护对应 HorizontalPodAutoscaler 的生命周期. Prerequisites 在 kuber

Jan 2, 2023
network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.
network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of kubernetes.

Network Node Manager network-node-manager is a kubernetes controller that controls the network configuration of a node to resolve network issues of ku

Dec 18, 2022
A controller to create K8s Ingresses for Openshift routes.

route-to-ingress-operator A controller to create corresponding ingress.networking.k8s.io/v1 resources for route.openshift.io/v1 TODO int port string p

Jan 7, 2022