-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
48 lines (39 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
"time"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
func main() {
withStruct()
withFunc()
}
type reconciler struct {
}
func (reconciler) reconcile(ctx context.Context, o reconcile.Request) (reconcile.Result, error) {
fmt.Printf("reconcile is called with %s/%s\n", o.Namespace, o.Name)
return reconcile.Result{}, nil
}
func withStruct() {
r := reconciler{}
res, err := r.reconcile(context.Background(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})
if err != nil || res.Requeue || res.RequeueAfter != time.Duration(0) {
fmt.Printf("error: %v, res %v", err, res)
} else {
fmt.Println("res is expected")
}
}
func withFunc() {
r := reconcile.Func(func(ctx context.Context, o reconcile.Request) (reconcile.Result, error) {
fmt.Printf("reconcile is called with %s/%s\n", o.Namespace, o.Name)
return reconcile.Result{}, nil
}) // implements reconcile.Reconciler interface
res, err := r.Reconcile(context.Background(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})
if err != nil || res.Requeue || res.RequeueAfter != time.Duration(0) {
fmt.Printf("error: %v, res %v", err, res)
} else {
fmt.Println("res is expected")
}
}