Skip to content

Commit

Permalink
refactor: Remove dead code (#979)
Browse files Browse the repository at this point in the history
* Remove dead code

Signed-off-by: Siddhesh Ghadi <[email protected]>

* Fix import

Signed-off-by: Siddhesh Ghadi <[email protected]>

* Fix imports

Signed-off-by: Siddhesh Ghadi <[email protected]>

---------

Signed-off-by: Siddhesh Ghadi <[email protected]>
  • Loading branch information
svghadi authored Aug 29, 2023
1 parent e49612a commit e624a26
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 46 deletions.
3 changes: 2 additions & 1 deletion controllers/argocd/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 11 additions & 11 deletions controllers/argocd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -186,15 +186,15 @@ 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
for _, sourceNamespace := range cr.Spec.SourceNamespaces {

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
Expand All @@ -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)
}
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/argocd/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions controllers/argocd/rolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions controllers/argocd/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
26 changes: 0 additions & 26 deletions controllers/argocd/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e624a26

Please sign in to comment.