-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit Events for ClusterTriggerAuthentication (#1647)
* Emit Events for ClusterTriggerAuthentication Signed-off-by: Zbynek Roubalik <zroubali@redhat.com> * update changelog Signed-off-by: Zbynek Roubalik <zroubali@redhat.com> Co-authored-by: Ahmed ElSayed <ahmels@microsoft.com>
- Loading branch information
1 parent
6ee8305
commit 57ce756
Showing
8 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"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" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
|
||
kedav1alpha1 "github.com/kedacore/keda/v2/api/v1alpha1" | ||
"github.com/kedacore/keda/v2/pkg/eventreason" | ||
) | ||
|
||
// +kubebuilder:rbac:groups=keda.sh,resources=clustertriggerauthentications;clustertriggerauthentications/status,verbs="*" | ||
|
||
// ClusterTriggerAuthenticationReconciler reconciles a ClusterTriggerAuthentication object | ||
type ClusterTriggerAuthenticationReconciler struct { | ||
Client client.Client | ||
Log logr.Logger | ||
Recorder record.EventRecorder | ||
} | ||
|
||
// Reconcile performs reconciliation on the identified TriggerAuthentication resource based on the request information passed, returns the result and an error (if any). | ||
func (r *ClusterTriggerAuthenticationReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { | ||
reqLogger := r.Log.WithValues("ClusterTriggerAuthentication.Namespace", req.Namespace, "ClusterTriggerAuthentication.Name", req.Name) | ||
|
||
clusterTriggerAuthentication := &kedav1alpha1.ClusterTriggerAuthentication{} | ||
err := r.Client.Get(context.TODO(), req.NamespacedName, clusterTriggerAuthentication) | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
return ctrl.Result{}, nil | ||
} | ||
reqLogger.Error(err, "Failed ot get ClusterTriggerAuthentication") | ||
return ctrl.Result{}, err | ||
} | ||
|
||
if clusterTriggerAuthentication.GetDeletionTimestamp() != nil { | ||
r.Recorder.Event(clusterTriggerAuthentication, corev1.EventTypeNormal, eventreason.ClusterTriggerAuthenticationDeleted, "ClusterTriggerAuthentication was deleted") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
if clusterTriggerAuthentication.ObjectMeta.Generation == 1 { | ||
r.Recorder.Event(clusterTriggerAuthentication, corev1.EventTypeNormal, eventreason.ClusterTriggerAuthenticationAdded, "New ClusterTriggerAuthentication configured") | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
// SetupWithManager initializes the ClusterTriggerAuthenticationReconciler instance and starts a new controller managed by the passed Manager instance. | ||
func (r *ClusterTriggerAuthenticationReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&kedav1alpha1.ClusterTriggerAuthentication{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). | ||
Complete(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters