|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - "os" |
8 | 7 | "reflect" |
9 | 8 | "strings" |
10 | 9 |
|
@@ -70,18 +69,6 @@ func (r *ReconcileArgoCD) reconcileNotificationsController(cr *argoproj.ArgoCD) |
70 | 69 | return err |
71 | 70 | } |
72 | 71 |
|
73 | | - // create clusterrole & clusterrolebinding if cluster-scoped ArgoCD |
74 | | - log.Info("reconciling notifications clusterroles") |
75 | | - clusterrole, err := r.reconcileNotificationsClusterRole(cr) |
76 | | - if err != nil { |
77 | | - return err |
78 | | - } |
79 | | - |
80 | | - log.Info("reconciling notifications clusterrolebindings") |
81 | | - if err := r.reconcileNotificationsClusterRoleBinding(cr, clusterrole, sa); err != nil { |
82 | | - return err |
83 | | - } |
84 | | - |
85 | 72 | // reconcile source namespace roles & rolebindings |
86 | 73 | log.Info("reconciling notifications roles & rolebindings in source namespaces") |
87 | 74 | if err := r.reconcileNotificationsSourceNamespacesResources(cr); err != nil { |
@@ -562,129 +549,6 @@ func (r *ReconcileArgoCD) reconcileNotificationsSecret(cr *argoproj.ArgoCD) erro |
562 | 549 | return nil |
563 | 550 | } |
564 | 551 |
|
565 | | -// reconcileNotificationsClusterRoleBinding reconciles required clusterrole for notification controller when ArgoCD is cluster-scoped |
566 | | -func (r *ReconcileArgoCD) reconcileNotificationsClusterRole(cr *argoproj.ArgoCD) (*rbacv1.ClusterRole, error) { |
567 | | - |
568 | | - allowed := allowedNamespace(cr.Namespace, os.Getenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES")) |
569 | | - |
570 | | - // controller disabled, don't create resources |
571 | | - if !isNotificationsEnabled(cr) { |
572 | | - allowed = false |
573 | | - } |
574 | | - |
575 | | - policyRules := policyRuleForNotificationsController() |
576 | | - clusterRole := newClusterRole(common.ArgoCDNotificationsControllerComponent, policyRules, cr) |
577 | | - if err := applyReconcilerHook(cr, clusterRole, ""); err != nil { |
578 | | - return nil, err |
579 | | - } |
580 | | - |
581 | | - existingClusterRole := &rbacv1.ClusterRole{} |
582 | | - err := r.Get(context.TODO(), types.NamespacedName{Name: clusterRole.Name}, existingClusterRole) |
583 | | - if err != nil { |
584 | | - if !apierrors.IsNotFound(err) { |
585 | | - return nil, fmt.Errorf("failed to reconcile the cluster role for the service account associated with %s : %s", clusterRole.Name, err) |
586 | | - } |
587 | | - if !allowed { |
588 | | - // Do Nothing |
589 | | - return clusterRole, nil |
590 | | - } |
591 | | - argoutil.LogResourceCreation(log, clusterRole) |
592 | | - return clusterRole, r.Create(context.TODO(), clusterRole) |
593 | | - } |
594 | | - |
595 | | - // ArgoCD not cluster scoped, cleanup any existing resource and exit |
596 | | - if !allowed { |
597 | | - argoutil.LogResourceDeletion(log, existingClusterRole, "argocd not cluster scoped") |
598 | | - err := r.Delete(context.TODO(), existingClusterRole) |
599 | | - if err != nil { |
600 | | - if !apierrors.IsNotFound(err) { |
601 | | - return existingClusterRole, err |
602 | | - } |
603 | | - } |
604 | | - return existingClusterRole, nil |
605 | | - } |
606 | | - |
607 | | - // if the Rules differ, update the Role |
608 | | - if !reflect.DeepEqual(existingClusterRole.Rules, clusterRole.Rules) { |
609 | | - existingClusterRole.Rules = clusterRole.Rules |
610 | | - argoutil.LogResourceUpdate(log, existingClusterRole, "updating rules") |
611 | | - if err := r.Update(context.TODO(), existingClusterRole); err != nil { |
612 | | - return nil, err |
613 | | - } |
614 | | - } |
615 | | - return existingClusterRole, nil |
616 | | -} |
617 | | - |
618 | | -// reconcileNotificationsClusterRoleBinding reconciles required clusterrolebinding for notifications controller when ArgoCD is cluster-scoped |
619 | | -func (r *ReconcileArgoCD) reconcileNotificationsClusterRoleBinding(cr *argoproj.ArgoCD, role *rbacv1.ClusterRole, sa *corev1.ServiceAccount) error { |
620 | | - |
621 | | - allowed := allowedNamespace(cr.Namespace, os.Getenv("ARGOCD_CLUSTER_CONFIG_NAMESPACES")) |
622 | | - |
623 | | - // controller disabled, don't create resources |
624 | | - if !isNotificationsEnabled(cr) { |
625 | | - allowed = false |
626 | | - } |
627 | | - |
628 | | - clusterRB := newClusterRoleBindingWithname(common.ArgoCDNotificationsControllerComponent, cr) |
629 | | - clusterRB.Subjects = []rbacv1.Subject{ |
630 | | - { |
631 | | - Kind: rbacv1.ServiceAccountKind, |
632 | | - Name: sa.Name, |
633 | | - Namespace: cr.Namespace, |
634 | | - }, |
635 | | - } |
636 | | - clusterRB.RoleRef = rbacv1.RoleRef{ |
637 | | - APIGroup: rbacv1.GroupName, |
638 | | - Kind: "ClusterRole", |
639 | | - Name: role.Name, |
640 | | - } |
641 | | - |
642 | | - if err := applyReconcilerHook(cr, clusterRB, ""); err != nil { |
643 | | - return err |
644 | | - } |
645 | | - |
646 | | - existingClusterRB := &rbacv1.ClusterRoleBinding{} |
647 | | - err := r.Get(context.TODO(), types.NamespacedName{Name: clusterRB.Name}, existingClusterRB) |
648 | | - if err != nil { |
649 | | - if !apierrors.IsNotFound(err) { |
650 | | - return fmt.Errorf("failed to reconcile the cluster rolebinding for the service account associated with %s : %s", clusterRB.Name, err) |
651 | | - } |
652 | | - if !allowed { |
653 | | - // Do Nothing |
654 | | - return nil |
655 | | - } |
656 | | - argoutil.LogResourceCreation(log, clusterRB) |
657 | | - return r.Create(context.TODO(), clusterRB) |
658 | | - } |
659 | | - |
660 | | - // ArgoCD not cluster scoped, cleanup any existing resource and exit |
661 | | - if !allowed { |
662 | | - argoutil.LogResourceDeletion(log, existingClusterRB, "argocd not cluster scoped") |
663 | | - err := r.Delete(context.TODO(), existingClusterRB) |
664 | | - if err != nil { |
665 | | - if !apierrors.IsNotFound(err) { |
666 | | - return err |
667 | | - } |
668 | | - } |
669 | | - return nil |
670 | | - } |
671 | | - |
672 | | - // if subj differ, update the rolebinding |
673 | | - if !reflect.DeepEqual(existingClusterRB.Subjects, clusterRB.Subjects) { |
674 | | - existingClusterRB.Subjects = clusterRB.Subjects |
675 | | - argoutil.LogResourceUpdate(log, existingClusterRB, "updating subjects") |
676 | | - if err := r.Update(context.TODO(), existingClusterRB); err != nil { |
677 | | - return err |
678 | | - } |
679 | | - } else if !reflect.DeepEqual(existingClusterRB.RoleRef, clusterRB.RoleRef) { |
680 | | - // RoleRef can't be updated, delete the rolebinding so that it gets recreated |
681 | | - argoutil.LogResourceDeletion(log, existingClusterRB, "roleref changed, deleting rolebinding so it gets recreated") |
682 | | - _ = r.Delete(context.TODO(), existingClusterRB) |
683 | | - return fmt.Errorf("change detected in roleRef for rolebinding %s of Argo CD instance %s in namespace %s", existingClusterRB.Name, cr.Name, existingClusterRB.Namespace) |
684 | | - } |
685 | | - return nil |
686 | | -} |
687 | | - |
688 | 552 | // reconcileNotificationsSourceNamespacesResources creates role & rolebinding in target source namespaces for notifications controller |
689 | 553 | // Notifications resources are only created if target source ns is subset of apps source namespaces |
690 | 554 | func (r *ReconcileArgoCD) reconcileNotificationsSourceNamespacesResources(cr *argoproj.ArgoCD) error { |
@@ -774,7 +638,7 @@ func (r *ReconcileArgoCD) reconcileNotificationsSourceNamespacesResources(cr *ar |
774 | 638 | Namespace: sourceNamespace, |
775 | 639 | }, |
776 | 640 | RoleRef: rbacv1.RoleRef{ |
777 | | - APIGroup: v1.GroupName, |
| 641 | + APIGroup: rbacv1.GroupName, |
778 | 642 | Kind: "Role", |
779 | 643 | Name: getResourceNameForNotificationsSourceNamespaces(cr), |
780 | 644 | }, |
@@ -835,7 +699,8 @@ func (r *ReconcileArgoCD) getNotificationsCommand(cr *argoproj.ArgoCD) []string |
835 | 699 | } |
836 | 700 |
|
837 | 701 | if len(notificationsSourceNamespaces) > 0 { |
838 | | - cmd = append(cmd, "--application-namespaces", fmt.Sprint(strings.Join(notificationsSourceNamespaces, ","))) |
| 702 | + cmd = append(cmd, "--application-namespaces", strings.Join(notificationsSourceNamespaces, ",")) |
| 703 | + cmd = append(cmd, "--self-service-notification-enabled", "true") |
839 | 704 | } |
840 | 705 |
|
841 | 706 | return cmd |
|
0 commit comments