github.com/argoproj-labs/argocd-operator@v0.10.0/controllers/notificationsconfiguration/notificationsconfiguration_controller.go (about) 1 /* 2 Copyright 2019, 2021. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package notificationsconfiguration 18 19 import ( 20 "context" 21 22 v1alpha1 "github.com/argoproj-labs/argocd-operator/api/v1alpha1" 23 24 "k8s.io/apimachinery/pkg/api/errors" 25 "k8s.io/apimachinery/pkg/runtime" 26 27 ctrl "sigs.k8s.io/controller-runtime" 28 "sigs.k8s.io/controller-runtime/pkg/client" 29 logr "sigs.k8s.io/controller-runtime/pkg/log" 30 "sigs.k8s.io/controller-runtime/pkg/reconcile" 31 ) 32 33 // blank assignment to verify that ReconcileNotificationsConfiguration implements reconcile.Reconciler 34 var _ reconcile.Reconciler = &NotificationsConfigurationReconciler{} 35 36 // NotificationsConfigurationReconciler reconciles a NotificationsConfiguration object 37 type NotificationsConfigurationReconciler struct { 38 client.Client 39 Scheme *runtime.Scheme 40 } 41 42 //+kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;delete;patch;update 43 44 // Reconcile is part of the main kubernetes reconciliation loop which aims to 45 // move the current state closer to the desired state. 46 // 47 // For more details, check Reconcile and its Result here: 48 // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.2/pkg/reconcile 49 50 // +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings,verbs=* 51 // +kubebuilder:rbac:groups="",resources=configmaps,verbs=* 52 // +kubebuilder:rbac:groups=argoproj.io,resources=notificationsconfiguration,verbs=* 53 func (r *NotificationsConfigurationReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) { 54 55 reqLogger := logr.FromContext(ctx, "Request.Namespace", request.Namespace, "Request.Name", request.Name) 56 reqLogger.Info("Reconciling NotificationsConfiguration") 57 58 notificationsConfig := &v1alpha1.NotificationsConfiguration{} 59 err := r.Client.Get(ctx, request.NamespacedName, notificationsConfig) 60 if err != nil { 61 if errors.IsNotFound(err) { 62 // Request object not found, could have been deleted after reconcile request. 63 // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. 64 // Return and don't requeue 65 return reconcile.Result{}, nil 66 } 67 // Error reading the object - requeue the request. 68 return reconcile.Result{}, err 69 } 70 71 if err := r.reconcileNotificationsConfigurationResources(notificationsConfig); err != nil { 72 return reconcile.Result{}, err 73 } 74 75 // Return and don't requeue 76 return reconcile.Result{}, nil 77 } 78 79 // SetupWithManager sets up the controller with the Manager. 80 func (r *NotificationsConfigurationReconciler) SetupWithManager(mgr ctrl.Manager) error { 81 bldr := ctrl.NewControllerManagedBy(mgr) 82 setResourceWatches(bldr) 83 return bldr.Complete(r) 84 }