From e624a26efd7223553173c4b4526f7a4292dc3902 Mon Sep 17 00:00:00 2001 From: Siddhesh Ghadi <61187612+svghadi@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:40:06 +0530 Subject: [PATCH] refactor: Remove dead code (#979) * Remove dead code Signed-off-by: Siddhesh Ghadi * Fix import Signed-off-by: Siddhesh Ghadi * Fix imports Signed-off-by: Siddhesh Ghadi --------- Signed-off-by: Siddhesh Ghadi --- controllers/argocd/argocd_controller.go | 3 ++- controllers/argocd/role.go | 22 ++++++++++----------- controllers/argocd/role_test.go | 2 +- controllers/argocd/rolebinding.go | 4 ++-- controllers/argocd/sso.go | 9 ++++----- controllers/argocd/testing.go | 26 ------------------------- 6 files changed, 20 insertions(+), 46 deletions(-) diff --git a/controllers/argocd/argocd_controller.go b/controllers/argocd/argocd_controller.go index e03fd76f8..79e576caa 100644 --- a/controllers/argocd/argocd_controller.go +++ b/controllers/argocd/argocd_controller.go @@ -21,9 +21,10 @@ import ( "fmt" "time" - argoproj "github.com/argoproj-labs/argocd-operator/api/v1alpha1" "github.com/prometheus/client_golang/prometheus" + argoproj "github.com/argoproj-labs/argocd-operator/api/v1alpha1" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" diff --git a/controllers/argocd/role.go b/controllers/argocd/role.go index d21ffcbce..f7c162c1d 100644 --- a/controllers/argocd/role.go +++ b/controllers/argocd/role.go @@ -31,7 +31,7 @@ func newRole(name string, rules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) *v1.Ro } } -func newRoleForApplicationSourceNamespaces(name, namespace string, rules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) *v1.Role { +func newRoleForApplicationSourceNamespaces(namespace string, rules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) *v1.Role { return &v1.Role{ ObjectMeta: metav1.ObjectMeta{ Name: getRoleNameForApplicationSourceNamespaces(namespace, cr), @@ -83,7 +83,7 @@ func (r *ReconcileArgoCD) reconcileRoles(cr *argoprojv1a1.ArgoCD) error { log.Info("reconciling roles for source namespaces") policyRuleForApplicationSourceNamespaces := policyRuleForServerApplicationSourceNamespaces() // reconcile roles is source namespaces for ArgoCD Server - if _, err := r.reconcileRoleForApplicationSourceNamespaces(common.ArgoCDServerComponent, policyRuleForApplicationSourceNamespaces, cr); err != nil { + if err := r.reconcileRoleForApplicationSourceNamespaces(common.ArgoCDServerComponent, policyRuleForApplicationSourceNamespaces, cr); err != nil { return err } @@ -186,7 +186,7 @@ func (r *ReconcileArgoCD) reconcileRole(name string, policyRules []v1.PolicyRule return roles, nil } -func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name string, policyRules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) ([]*v1.Role, error) { +func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name string, policyRules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) error { var roles []*v1.Role // create policy rules for each source namespace for ArgoCD Server @@ -194,7 +194,7 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin namespace := &corev1.Namespace{} if err := r.Client.Get(context.TODO(), types.NamespacedName{Name: sourceNamespace}, namespace); err != nil { - return nil, err + return err } // do not reconcile roles for namespaces already containing managed-by label @@ -214,16 +214,16 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin log.Info(fmt.Sprintf("Reconciling role for %s", namespace.Name)) - role := newRoleForApplicationSourceNamespaces(name, namespace.Name, policyRules, cr) + role := newRoleForApplicationSourceNamespaces(namespace.Name, policyRules, cr) if err := applyReconcilerHook(cr, role, ""); err != nil { - return nil, err + return err } role.Namespace = namespace.Name existingRole := v1.Role{} err := r.Client.Get(context.TODO(), types.NamespacedName{Name: role.Name, Namespace: namespace.Name}, &existingRole) if err != nil { if !errors.IsNotFound(err) { - return nil, fmt.Errorf("failed to reconcile the role for the service account associated with %s : %s", name, err) + return fmt.Errorf("failed to reconcile the role for the service account associated with %s : %s", name, err) } } @@ -234,7 +234,7 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin if reflect.DeepEqual(existingRole, v1.Role{}) { log.Info(fmt.Sprintf("creating role %s for Argo CD instance %s in namespace %s", role.Name, cr.Name, namespace)) if err := r.Client.Create(context.TODO(), role); err != nil { - return nil, err + return err } } continue @@ -248,7 +248,7 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin // Get the latest value of namespace before updating it if err := r.Client.Get(context.TODO(), types.NamespacedName{Name: namespace.Name}, namespace); err != nil { - return nil, err + return err } // Update namespace with managed-by-cluster-argocd label namespace.Labels[common.ArgoCDManagedByClusterArgoCDLabel] = cr.Namespace @@ -259,7 +259,7 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin if !reflect.DeepEqual(existingRole.Rules, role.Rules) { existingRole.Rules = role.Rules if err := r.Client.Update(context.TODO(), &existingRole); err != nil { - return nil, err + return err } } roles = append(roles, &existingRole) @@ -269,7 +269,7 @@ func (r *ReconcileArgoCD) reconcileRoleForApplicationSourceNamespaces(name strin } } - return roles, nil + return nil } func (r *ReconcileArgoCD) reconcileClusterRole(name string, policyRules []v1.PolicyRule, cr *argoprojv1a1.ArgoCD) (*v1.ClusterRole, error) { diff --git a/controllers/argocd/role_test.go b/controllers/argocd/role_test.go index 0129048f6..61c1e13f8 100644 --- a/controllers/argocd/role_test.go +++ b/controllers/argocd/role_test.go @@ -151,7 +151,7 @@ func TestReconcileArgoCD_reconcileRoleForApplicationSourceNamespaces(t *testing. workloadIdentifier := common.ArgoCDServerComponent expectedRules := policyRuleForServerApplicationSourceNamespaces() - _, err := r.reconcileRoleForApplicationSourceNamespaces(workloadIdentifier, expectedRules, a) + err := r.reconcileRoleForApplicationSourceNamespaces(workloadIdentifier, expectedRules, a) assert.NoError(t, err) expectedName := getRoleNameForApplicationSourceNamespaces(sourceNamespace, a) diff --git a/controllers/argocd/rolebinding.go b/controllers/argocd/rolebinding.go index 3f614be64..4be09c3c0 100644 --- a/controllers/argocd/rolebinding.go +++ b/controllers/argocd/rolebinding.go @@ -243,7 +243,7 @@ func (r *ReconcileArgoCD) reconcileRoleBinding(name string, rules []v1.PolicyRul } // get expected name - roleBinding := newRoleBindingWithNameForApplicationSourceNamespaces(name, namespace.Name, cr) + roleBinding := newRoleBindingWithNameForApplicationSourceNamespaces(namespace.Name, cr) roleBinding.Namespace = namespace.Name roleBinding.RoleRef = v1.RoleRef{ @@ -324,7 +324,7 @@ func getRoleNameForApplicationSourceNamespaces(targetNamespace string, cr *argop } // newRoleBindingWithNameForApplicationSourceNamespaces creates a new RoleBinding with the given name for the source namespaces of ArgoCD Server. -func newRoleBindingWithNameForApplicationSourceNamespaces(name, namespace string, cr *argoprojv1a1.ArgoCD) *v1.RoleBinding { +func newRoleBindingWithNameForApplicationSourceNamespaces(namespace string, cr *argoprojv1a1.ArgoCD) *v1.RoleBinding { roleBinding := newRoleBindingForSupportNamespaces(cr, namespace) labels := roleBinding.ObjectMeta.Labels diff --git a/controllers/argocd/sso.go b/controllers/argocd/sso.go index b64b6145f..ee1e77122 100644 --- a/controllers/argocd/sso.go +++ b/controllers/argocd/sso.go @@ -27,11 +27,10 @@ import ( ) const ( - ssoLegalUnknown string = "Unknown" - ssoLegalSuccess string = "Success" - ssoLegalFailed string = "Failed" - illegalSSOConfiguration string = "illegal SSO configuration: " - multipleSSOConfiguration string = "multiple SSO configuration: " + ssoLegalUnknown string = "Unknown" + ssoLegalSuccess string = "Success" + ssoLegalFailed string = "Failed" + illegalSSOConfiguration string = "illegal SSO configuration: " ) var ( diff --git a/controllers/argocd/testing.go b/controllers/argocd/testing.go index ee2e190de..95c884a63 100644 --- a/controllers/argocd/testing.go +++ b/controllers/argocd/testing.go @@ -94,32 +94,6 @@ func makeTestArgoCDForKeycloak() *argoprojv1alpha1.ArgoCD { } return a } -func makeTestArgoCDForKeycloakWithDex(opts ...argoCDOpt) *argoprojv1alpha1.ArgoCD { - a := &argoprojv1alpha1.ArgoCD{ - ObjectMeta: metav1.ObjectMeta{ - Name: testArgoCDName, - Namespace: testNamespace, - }, - Spec: argoprojv1alpha1.ArgoCDSpec{ - SSO: &argoprojv1alpha1.ArgoCDSSOSpec{ - Provider: "keycloak", - Dex: &argoprojv1alpha1.ArgoCDDexSpec{ - OpenShiftOAuth: true, - Resources: makeTestDexResources(), - }, - }, - Server: argoprojv1alpha1.ArgoCDServerSpec{ - Route: argoprojv1alpha1.ArgoCDRouteSpec{ - Enabled: true, - }, - }, - }, - } - for _, o := range opts { - o(a) - } - return a -} func makeTestArgoCDWithResources(opts ...argoCDOpt) *argoprojv1alpha1.ArgoCD { a := &argoprojv1alpha1.ArgoCD{