Skip to content

Commit 0a34d4f

Browse files
committed
Delete example from godoc and point to exmaple/main.go
1 parent db7c46a commit 0a34d4f

File tree

1 file changed

+2
-83
lines changed

1 file changed

+2
-83
lines changed

pkg/controller/doc.go

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ EventHandler enqueues Request:
106106
107107
Reconcile is called with the Request:
108108
109-
* Reconcile(Request{"foo", "bar"})
109+
* Reconcile(reconcile.Request{"foo", "bar"})
110110
111111
112112
controllerManager
@@ -120,88 +120,7 @@ Usage
120120
The following example shows creating a new Controller program which Reconciles ReplicaSet objects in response
121121
to Pod or ReplicaSet events. The Reconcile function simply adds a label to the ReplicaSet.
122122
123-
func main() {
124-
flag.Parse()
125-
logf.SetLogger(logf.ZapLogger(false))
126-
127-
// Setup a Manager
128-
manager, err := controller.NewManager(controller.ManagerArgs{})
129-
if err != nil {
130-
log.Fatal(err)
131-
}
132-
133-
// Setup a new controller to Reconcile ReplicaSets
134-
c := manager.NewController(
135-
controller.Args{Name: "my-replicaset-controller", MaxConcurrentReconciles: 1},
136-
&ReconcileReplicaSet{client: manager.GetClient()},
137-
)
138-
139-
err = c.Watch(
140-
// Watch ReplicaSets
141-
&source.KindSource{Type: &appsv1.ReplicaSet{}},
142-
// Enqueue ReplicaSet object key
143-
&eventhandler.EnqueueHandler{})
144-
if err != nil {
145-
log.Fatal(err)
146-
}
147-
148-
err = c.Watch(
149-
// Watch Pods
150-
&source.KindSource{Type: &corev1.Pod{}},
151-
// Enqueue Owning ReplicaSet object key
152-
&eventhandler.EnqueueOwnerHandler{OwnerType: &appsv1.ReplicaSet{}, IsController: true})
153-
if err != nil {
154-
log.Fatal(err)
155-
}
156-
157-
log.Fatal(manager.Start(signals.SetupSignalHandler()))
158-
}
159-
160-
// ReconcileReplicaSet reconciles ReplicaSets
161-
type ReconcileReplicaSet struct {
162-
client client.Interface
163-
}
164-
165-
// Implement reconcile.Reconcile so the controller can reconcile objects
166-
var _ reconcile.Reconcile = &ReconcileReplicaSet{}
167-
168-
// Reconcile writes a "hello": "world" annotation to ReplicaSets that don't have one.
169-
func (r *ReconcileReplicaSet) Reconcile(request reconcile.Request) (reconcile.Result, error) {
170-
// Fetch the ReplicaSet from the cache
171-
rs := &appsv1.ReplicaSet{}
172-
err := r.client.Get(context.TODO(), request.NamespacedName, rs)
173-
if errors.IsNotFound(err) {
174-
log.Printf("Could not find ReplicaSet %v.\n", request)
175-
return reconcile.Result{}, nil
176-
}
177-
178-
if err != nil {
179-
log.Printf("Could not fetch ReplicaSet %v for %+v\n", err, request)
180-
return reconcile.Result{}, err
181-
}
182-
183-
// Print the ReplicaSet
184-
log.Printf("ReplicaSet Name %s Namespace %s, Pod Name: %s\n",
185-
rs.Name, rs.Namespace, rs.Spec.Template.Spec.Containers[0].Name)
186-
187-
// Set the label if it is missing
188-
if rs.Labels == nil {
189-
rs.Labels = map[string]string{}
190-
}
191-
if rs.Labels["hello"] == "world" {
192-
return reconcile.Result{}, nil
193-
}
194-
195-
// Update the ReplicaSet
196-
rs.Labels["hello"] = "world"
197-
err = r.client.Update(context.TODO(), rs)
198-
if err != nil {
199-
log.Printf("Could not write ReplicaSet %v\n", err)
200-
return reconcile.Result{}, err
201-
}
202-
203-
return reconcile.Result{}, nil
204-
}
123+
See the example/main.go for a usage example.
205124
206125
Controller Example
207126

0 commit comments

Comments
 (0)