diff --git a/cmd/main.go b/cmd/main.go index 2aaa696..3bd6dd7 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -149,8 +149,9 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Account") } if err = (&controller.IngressReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Recorder: mgr.GetEventRecorderFor("uptime-robot-controller"), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Ingress") os.Exit(1) diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 086874d..afd5008 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -12,6 +12,13 @@ rules: - get - list - watch +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch - apiGroups: - networking.k8s.io resources: diff --git a/internal/controller/ingress_controller.go b/internal/controller/ingress_controller.go index 75ff06f..ad0b16f 100644 --- a/internal/controller/ingress_controller.go +++ b/internal/controller/ingress_controller.go @@ -31,6 +31,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" @@ -44,12 +45,14 @@ var IngressAnnotationPrefix = "uptime-robot.clevyr.com/" // IngressReconciler reconciles a Ingress object type IngressReconciler struct { client.Client - Scheme *runtime.Scheme + Scheme *runtime.Scheme + Recorder record.EventRecorder } //+kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses/status,verbs=get;update;patch //+kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses/finalizers,verbs=update +//+kubebuilder:rbac:groups=core,resources=events,verbs=create;patch // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. @@ -132,6 +135,7 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct for _, monitor := range list.Items { if err := r.updateValues(ingress, &monitor, annotations); err != nil { + r.Recorder.Event(ingress, "Warning", "Generating", err.Error()) return ctrl.Result{}, err }