example • Writing a controller • Scheme • Create a pluggable scheme • Add types into the scheme 17 // create factory kitchenFactory, err := ctlkitchen.NewFactoryFromConfig(restConfig) if err != nil { return nil, err } // instantiate controllers from factory for Order and Meal resource types orders := kitchenFactory.Kitchen().V1().Order() meals := kitchenFactory.Kitchen().V1().Meal() // implement event handler for Order resource type onOrderChange := func(id string, obj *v1.Order) (*v1.Order, error) { meal := &v1.Meal{ // fill in Meal details } // creat new Meal resources using k8s client for i := 0; i < obj.Spec.Replicas; i++ { if _, err := meals.Create(meal); err != nil { return obj, err } } // avoid acting on caches objCopy := obj.DeepCopy() objCopy.Status.Processed = true // update Order resource using k8s client return orders.Update(objCopy) } // register event handler orders.OnChange(context.Background(), "order-controller", onOrderChange) // kick off everything kitchenFactory.Start(threadiness)