Skip to content

Commit

Permalink
Add unit test for argocd nodeplacement
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <[email protected]>
  • Loading branch information
Rizwana777 committed Jul 24, 2024
1 parent b4e2574 commit 45cad9e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
3 changes: 1 addition & 2 deletions controllers/argocd_metrics_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
is "gotest.tools/assert/cmp"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -349,7 +348,7 @@ func TestReconciler_add_dashboard(t *testing.T) {

// Need to create one configmap to test update existing versus create
cm := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: "gitops-overview",
Namespace: dashboardNamespace,
},
Expand Down
2 changes: 0 additions & 2 deletions controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance
}

func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipelinesv1alpha1.GitopsService, reqLogger logr.Logger) (reconcile.Result, error) {

defaultArgoCDInstance, err := argocd.NewCR(common.ArgoCDInstanceName, serviceNamespace)
if err != nil {
return reconcile.Result{}, err
Expand Down Expand Up @@ -423,7 +422,6 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
}
} else {
changed := false

if existingArgoCD.Spec.ApplicationSet != nil {
if existingArgoCD.Spec.ApplicationSet.Resources == nil {
existingArgoCD.Spec.ApplicationSet.Resources = defaultArgoCDInstance.Spec.ApplicationSet.Resources
Expand Down
63 changes: 59 additions & 4 deletions controllers/gitopsservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
resourcev1 "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -93,6 +92,62 @@ func TestImageFromEnvVariable(t *testing.T) {

}

func TestReconcileDefaultForArgoCDNodeplacement(t *testing.T) {
logf.SetLogger(argocd.ZapLogger(true))
s := scheme.Scheme
addKnownTypesToScheme(s)

var err error

gitopsService := &pipelinesv1alpha1.GitopsService{
ObjectMeta: v1.ObjectMeta{
Name: serviceName,
},
Spec: pipelinesv1alpha1.GitopsServiceSpec{
NodeSelector: map[string]string{
"foo": "bar",
},
},
}

fakeClient := fake.NewFakeClient(gitopsService)
reconciler := newReconcileGitOpsService(fakeClient, s)

existingArgoCD := &argoapp.ArgoCD{
ObjectMeta: v1.ObjectMeta{
Name: serviceNamespace,
Namespace: serviceNamespace,
},
Spec: argoapp.ArgoCDSpec{
Server: argoapp.ArgoCDServerSpec{
Route: argoapp.ArgoCDRouteSpec{
Enabled: true,
},
},
ApplicationSet: &argoapp.ArgoCDApplicationSet{},
SSO: &argoapp.ArgoCDSSOSpec{
Provider: "dex",
Dex: &argoapp.ArgoCDDexSpec{
Config: "test-config",
},
},
},
}

err = fakeClient.Create(context.TODO(), existingArgoCD)
assertNoError(t, err)

_, err = reconciler.Reconcile(context.TODO(), newRequest("test", "test"))
assertNoError(t, err)

// verify whether existingArgoCD NodePlacement is updated when user is patching nodePlacement through GitopsService CR
err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: common.ArgoCDInstanceName, Namespace: serviceNamespace},
existingArgoCD)
assertNoError(t, err)
assert.Check(t, existingArgoCD.Spec.NodePlacement != nil)
assert.DeepEqual(t, existingArgoCD.Spec.NodePlacement.NodeSelector, gitopsService.Spec.NodeSelector)
}

// If the DISABLE_DEFAULT_ARGOCD_INSTANCE is set, ensure that the default ArgoCD instance is not created.
func TestReconcileDisableDefault(t *testing.T) {

Expand Down Expand Up @@ -553,14 +608,14 @@ func TestReconcile_VerifyResourceQuotaDeletionForUpgrade(t *testing.T) {

// Create namespace object for default ArgoCD instance and set resource quota to it.
defaultArgoNS := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: serviceNamespace,
},
}
fakeClient.Create(context.TODO(), defaultArgoNS)

dummyResourceObj := &corev1.ResourceQuota{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: fmt.Sprintf("%s-compute-resources", serviceNamespace),
Namespace: serviceNamespace,
},
Expand Down Expand Up @@ -613,7 +668,7 @@ func TestReconcile_InfrastructureNode(t *testing.T) {
s := scheme.Scheme
addKnownTypesToScheme(s)
gitopsService := &pipelinesv1alpha1.GitopsService{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: serviceName,
},
Spec: pipelinesv1alpha1.GitopsServiceSpec{
Expand Down

0 comments on commit 45cad9e

Please sign in to comment.