Skip to content

Commit

Permalink
undo small changes to old code
Browse files Browse the repository at this point in the history
Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>
  • Loading branch information
jaideepr97 committed Jan 3, 2024
1 parent 077fc9f commit b744299
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 230 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (a *ArgoCD) ApplicationInstanceLabelKey() string {
if a.Spec.ApplicationInstanceLabelKey != "" {
return a.Spec.ApplicationInstanceLabelKey
} else {
return common.AppK8sKeyInstance
return common.ArgoCDDefaultApplicationInstanceLabelKey
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/argocd_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Test_ArgoCD_ApplicationInstanceLabelKey(t *testing.T) {
cr.Spec.ApplicationInstanceLabelKey = "my.corp/instance"
assert.Equal(t, cr.ApplicationInstanceLabelKey(), "my.corp/instance")
cr = &ArgoCD{}
assert.Equal(t, cr.ApplicationInstanceLabelKey(), common.AppK8sKeyInstance)
assert.Equal(t, cr.ApplicationInstanceLabelKey(), common.ArgoCDDefaultApplicationInstanceLabelKey)
}

func Test_ResourceTrackingMethodToString(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
ArgoCDDefaultAdminPasswordNumSymbols = 0

// ArgoCDDefaultApplicationInstanceLabelKey is the default app name as a tracking label.
ArgoCDDefaultApplicationInstanceLabelKey = "app.kubernetes.io/instance"
ArgoCDDefaultApplicationInstanceLabelKey = AppK8sKeyInstance

// ArgoCDDefaultArgoImage is the ArgoCD container image to use when not specified.
ArgoCDDefaultArgoImage = "quay.io/argoproj/argocd"
Expand Down
29 changes: 29 additions & 0 deletions controllers/argocd/TOBEREMOVED_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

func makeTestReconciler(client client.Client, sch *runtime.Scheme) *ReconcileArgoCD {
return &ReconcileArgoCD{
Client: client,
Scheme: sch,
}
}

func createNamespace(r *ReconcileArgoCD, n string, managedBy string) error {
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: n}}
if managedBy != "" {
Expand Down Expand Up @@ -50,6 +57,28 @@ func createNamespaceManagedByClusterArgoCDLabel(r *ReconcileArgoCD, n string, ma
return r.Client.Create(context.TODO(), ns)
}

func stringMapKeys(m map[string]string) []string {
r := []string{}
for k := range m {
r = append(r, k)
}
sort.Strings(r)
return r
}

func merge(base map[string]string, diff map[string]string) map[string]string {
result := make(map[string]string)

for k, v := range base {
result[k] = v
}
for k, v := range diff {
result[k] = v
}

return result
}

func TestReconcileNotifications_CreateRoles(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
Expand Down
8 changes: 4 additions & 4 deletions controllers/argocd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func getCAConfigMapName(cr *argoproj.ArgoCD) string {
if len(cr.Spec.TLS.CA.ConfigMapName) > 0 {
return cr.Spec.TLS.CA.ConfigMapName
}
return argoutil.NameWithSuffix(cr.Name, common.ArgoCDCASuffix)
return nameWithSuffix(common.ArgoCDCASuffix, cr)
}

// getSCMRootCAConfigMapName will return the SCMRootCA ConfigMap name for the given ArgoCD ApplicationSet Controller.
Expand Down Expand Up @@ -292,7 +292,7 @@ func newConfigMap(cr *argoproj.ArgoCD) *corev1.ConfigMap {
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name,
Namespace: cr.Namespace,
Labels: common.DefaultLabels(cr.Name),
Labels: argoutil.LabelsForCluster(cr),
},
}
}
Expand All @@ -303,7 +303,7 @@ func newConfigMapWithName(name string, cr *argoproj.ArgoCD) *corev1.ConfigMap {
cm.ObjectMeta.Name = name

lbls := cm.ObjectMeta.Labels
lbls[common.AppK8sKeyName] = name
lbls[common.ArgoCDKeyName] = name
cm.ObjectMeta.Labels = lbls

return cm
Expand Down Expand Up @@ -363,7 +363,7 @@ func (r *ReconcileArgoCD) reconcileCAConfigMap(cr *argoproj.ArgoCD) error {
}

cm.Data = map[string]string{
corev1.TLSCertKey: string(caSecret.Data[corev1.TLSCertKey]),
common.ArgoCDKeyTLSCert: string(caSecret.Data[common.ArgoCDKeyTLSCert]),
}

if err := controllerutil.SetControllerReference(cr, cm, r.Scheme); err != nil {
Expand Down
30 changes: 15 additions & 15 deletions controllers/argocd/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"github.com/argoproj-labs/argocd-operator/pkg/argoutil"
)

var _ reconcile.Reconciler = &ArgoCDReconciler{}
var _ reconcile.Reconciler = &ReconcileArgoCD{}

func TestArgoCDReconciler_reconcileTLSCerts(t *testing.T) {
func TestReconcileArgoCD_reconcileTLSCerts(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(initialCerts(t, "root-ca.example.com"))

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestArgoCDReconciler_reconcileTLSCerts(t *testing.T) {
}
}

func TestArgoCDReconciler_reconcileTLSCerts_configMapUpdate(t *testing.T) {
func TestReconcileArgoCD_reconcileTLSCerts_configMapUpdate(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(initialCerts(t, "root-ca.example.com"))

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestArgoCDReconciler_reconcileTLSCerts_configMapUpdate(t *testing.T) {
}
}

func TestArgoCDReconciler_reconcileTLSCerts_withInitialCertsUpdate(t *testing.T) {
func TestReconcileArgoCD_reconcileTLSCerts_withInitialCertsUpdate(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD()

Expand Down Expand Up @@ -142,7 +142,7 @@ func TestArgoCDReconciler_reconcileTLSCerts_withInitialCertsUpdate(t *testing.T)
}
}

func TestArgoCDReconciler_reconcileArgoConfigMap(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap(t *testing.T) {
logf.SetLogger(ZapLogger(true))

defaultConfigMapData := map[string]string{
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap(t *testing.T) {
}
}

func TestArgoCDReconciler_reconcileEmptyArgoConfigMap(t *testing.T) {
func TestReconcileArgoCD_reconcileEmptyArgoConfigMap(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD()

Expand Down Expand Up @@ -267,7 +267,7 @@ func TestArgoCDReconciler_reconcileEmptyArgoConfigMap(t *testing.T) {
assert.NoError(t, err)
}

func TestArgoCDReconcilerCM_withRepoCredentials(t *testing.T) {
func TestReconcileArgoCDCM_withRepoCredentials(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD()
a.Spec.RepositoryCredentials = `
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestArgoCDReconcilerCM_withRepoCredentials(t *testing.T) {
}
}

func TestArgoCDReconciler_reconcileArgoConfigMap_withDisableAdmin(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withDisableAdmin(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
a.Spec.DisableAdmin = true
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_withDisableAdmin(t *testing.T)
}
}

func TestArgoCDReconciler_reconcileArgoConfigMap_withDexConnector(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withDexConnector(t *testing.T) {
logf.SetLogger(ZapLogger(true))

tests := []struct {
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_withDexConnector(t *testing.T)

}

func TestArgoCDReconciler_reconcileArgoConfigMap_withDexDisabled(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withDexDisabled(t *testing.T) {
logf.SetLogger(ZapLogger(true))

tests := []struct {
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_withDexDisabled(t *testing.T) {
}

// When dex is enabled, dexConfig should be present in argocd-cm, when disabled, it should be removed
func TestArgoCDReconciler_reconcileArgoConfigMap_dexConfigDeletedwhenDexDisabled(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_dexConfigDeletedwhenDexDisabled(t *testing.T) {
logf.SetLogger(ZapLogger(true))

tests := []struct {
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_dexConfigDeletedwhenDexDisabled
}
}

func TestArgoCDReconciler_reconcileArgoConfigMap_withKustomizeVersions(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withKustomizeVersions(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
kv := argoproj.KustomizeVersionSpec{
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_withKustomizeVersions(t *testin
}
}

func TestArgoCDReconciler_reconcileGPGKeysConfigMap(t *testing.T) {
func TestReconcileArgoCD_reconcileGPGKeysConfigMap(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD(func(a *argoproj.ArgoCD) {
a.Spec.DisableAdmin = true
Expand All @@ -628,7 +628,7 @@ func TestArgoCDReconciler_reconcileGPGKeysConfigMap(t *testing.T) {
// Currently the gpg keys configmap is empty
}

func TestArgoCDReconciler_reconcileArgoConfigMap_withResourceTrackingMethod(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withResourceTrackingMethod(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD()

Expand Down Expand Up @@ -719,7 +719,7 @@ func TestArgoCDReconciler_reconcileArgoConfigMap_withResourceTrackingMethod(t *t

}

func TestArgoCDReconciler_reconcileArgoConfigMap_withResourceInclusions(t *testing.T) {
func TestReconcileArgoCD_reconcileArgoConfigMap_withResourceInclusions(t *testing.T) {
logf.SetLogger(ZapLogger(true))
customizations := "testing: testing"
updatedCustomizations := "updated-testing: updated-testing"
Expand Down
6 changes: 3 additions & 3 deletions controllers/argocd/custommapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (r *ReconcileArgoCD) clusterResourceMapper(ctx context.Context, o client.Ob
namespacedArgoCDObject := client.ObjectKey{}

for k, v := range crbAnnotations {
if k == common.ArgoCDArgoprojKeyName {
if k == common.AnnotationName {
namespacedArgoCDObject.Name = v
} else if k == common.ArgoCDArgoprojKeyNamespace {
} else if k == common.AnnotationNamespace {
namespacedArgoCDObject.Namespace = v
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (r *ReconcileArgoCD) tlsSecretMapper(ctx context.Context, o client.Object)
if !ok {
return result
}
if owner, ok := secret.Annotations[common.ArgoCDArgoprojKeyName]; ok {
if owner, ok := secret.Annotations[common.AnnotationName]; ok {
namespacedArgoCDObject.Name = owner
namespacedArgoCDObject.Namespace = o.GetNamespace()
result = []reconcile.Request{
Expand Down
10 changes: 5 additions & 5 deletions controllers/argocd/custommapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func TestArgoCDReconciler_clusterRoleBindingMapper(t *testing.T) {
func TestReconcileArgoCD_clusterRoleBindingMapper(t *testing.T) {

type fields struct {
client client.Client
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestReconcileArgoCD_tlsSecretMapperRepoServer(t *testing.T) {
Name: "argocd-repo-server-tls",
Namespace: "argocd-operator",
Annotations: map[string]string{
common.ArgoCDArgoprojKeyName: "argocd",
common.AnnotationName: "argocd",
},
},
Type: corev1.SecretTypeTLS,
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestReconcileArgoCD_tlsSecretMapperRedis(t *testing.T) {
Name: "argocd-operator-redis-tls",
Namespace: "argocd-operator",
Annotations: map[string]string{
common.ArgoCDArgoprojKeyName: "argocd",
common.AnnotationName: "argocd",
},
},
Type: corev1.SecretTypeTLS,
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestReconcileArgoCD_tlsSecretMapperRedis(t *testing.T) {

}

func TestArgoCDReconciler_namespaceResourceMapper(t *testing.T) {
func TestReconcileArgoCD_namespaceResourceMapper(t *testing.T) {
a := makeTestArgoCD()

resObjs := []client.Object{a}
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestArgoCDReconciler_namespaceResourceMapper(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "testNamespace",
Labels: map[string]string{
common.ArgoCDArgoprojKeyManagedBy: a.Namespace,
common.ArgoCDManagedByLabel: a.Namespace,
},
},
},
Expand Down
Loading

0 comments on commit b744299

Please sign in to comment.