Skip to content

Commit 1efd2e0

Browse files
committed
Add resource events logs
1 parent 7459ad7 commit 1efd2e0

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

cmd/machine-api-operator/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func startControllers(ctx *ControllerContext) {
125125
ctx.ClientBuilder.KubeClientOrDie(componentName),
126126
ctx.ClientBuilder.OpenshiftClientOrDie(componentName),
127127
recorder,
128-
).Run(2, ctx.Stop)
128+
).Run(1, ctx.Stop)
129129
}
130130

131131
func startMetricsCollectionAndServer(ctx *ControllerContext) {

install/0000_30_machine-api-operator_11_deployment.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ spec:
8383
- name: config
8484
configMap:
8585
name: kube-rbac-proxy
86+
defaultMode: 420
8687
- name: images
8788
configMap:
88-
name: machine-api-operator-images
89+
defaultMode: 420
90+
name: machine-api-operator-images
8991
- name: machine-api-operator-tls
9092
secret:
93+
defaultMode: 420
9194
secretName: machine-api-operator-tls

pkg/operator/operator.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"os"
66
"time"
77

8+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
9+
10+
"k8s.io/apimachinery/pkg/runtime"
11+
812
"github.com/golang/glog"
913
osconfigv1 "github.com/openshift/api/config/v1"
1014
osclientset "github.com/openshift/client-go/config/clientset/versioned"
@@ -125,12 +129,42 @@ func (optr *Operator) Run(workers int, stopCh <-chan struct{}) {
125129
<-stopCh
126130
}
127131

132+
func logResource(obj interface{}) {
133+
runtimeObj, OkRuntimeObj := obj.(runtime.Object)
134+
metaObj, okObject := obj.(metav1.Object)
135+
if !OkRuntimeObj || !okObject {
136+
glog.Errorf("Error assigning type to interface when logging")
137+
}
138+
gvk, err := apiutil.GVKForObject(runtimeObj, runtime.NewScheme())
139+
if err != nil {
140+
glog.Errorf("Error getting GVKForObject: %v", err)
141+
}
142+
glog.V(3).Infof("Resource: %v %v/%v",
143+
gvk,
144+
metaObj.GetNamespace(),
145+
metaObj.GetName(),
146+
)
147+
glog.V(3).Infof("Resource: %v \n", obj)
148+
}
149+
128150
func (optr *Operator) eventHandler() cache.ResourceEventHandler {
129151
workQueueKey := fmt.Sprintf("%s/%s", optr.namespace, optr.name)
130152
return cache.ResourceEventHandlerFuncs{
131-
AddFunc: func(obj interface{}) { optr.queue.Add(workQueueKey) },
132-
UpdateFunc: func(old, new interface{}) { optr.queue.Add(workQueueKey) },
133-
DeleteFunc: func(obj interface{}) { optr.queue.Add(workQueueKey) },
153+
AddFunc: func(obj interface{}) {
154+
glog.Infof("Event: Add")
155+
logResource(obj)
156+
optr.queue.Add(workQueueKey)
157+
},
158+
UpdateFunc: func(old, new interface{}) {
159+
glog.Infof("Event: Update")
160+
logResource(old)
161+
optr.queue.Add(workQueueKey)
162+
},
163+
DeleteFunc: func(obj interface{}) {
164+
glog.Infof("Event: Delete")
165+
logResource(obj)
166+
optr.queue.Add(workQueueKey)
167+
},
134168
}
135169
}
136170

0 commit comments

Comments
 (0)