Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reconcilation logic if spec.ApplicationSet is removed #670

Open
wants to merge 57 commits into
base: master
Choose a base branch
from

Conversation

rishabh625
Copy link
Contributor

@rishabh625 rishabh625 commented Jun 2, 2022

Signed-off-by: rishabh625 [email protected]

What type of PR is this?

Uncomment only one /kind line, and delete the rest.
For example, > /kind bug would simply become: /kind bug

/kind bug
/kind chore
/kind cleanup
/kind failing-test
/kind enhancement
/kind documentation
/kind code-refactoring

/kind bug

What does this PR do / why we need it:
This PR deletes application set resources if disabled.

Have you updated the necessary documentation?

  • Documentation update is required by this PR.
  • Documentation has been updated.

Which issue(s) this PR fixes:

Fixes #627
Fixes #628

How to test changes / Special notes to the reviewer:

@@ -1092,8 +1092,31 @@ func (r *ReconcileArgoCD) setResourceWatches(bldr *builder.Builder, clusterResou
},
}

// Add new predicate to delete Notifications Resources. The predicate watches the Argo CD CR for changes to the `.spec.Notifications.Enabled`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comments to modify Notifications as ApplicationSet. To be changed in multiple places, please take care

@@ -454,3 +470,45 @@ func setAppSetLabels(obj *metav1.ObjectMeta) {
obj.Labels["app.kubernetes.io/part-of"] = "argocd-applicationset"
obj.Labels["app.kubernetes.io/component"] = "controller"
}

//deleteApplicationSetResources ... Triggers reconcillation of application set resources,logic for deletion of applicationset is in reconcile methods this method triggers the cleanup of resources using the reconcilation logic as CR changes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If please fix the below in comments.

  1. Provide space after //
  2. remove ...
  3. typo in reconciliation

May be
// deleteApplicationSetResources triggers the cleanup of application set resources.


if cr.Spec.ApplicationSet == nil {
log.Info(fmt.Sprintf("Deleting Deployment %s as applicationset is disabled", existing.Name))
return r.Client.Delete(context.TODO(), existing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I removed the applicationSet entry from Argo CD CR, controller crashed with the below error. I edited the Argo CD CR to remove the .spec.applicationSet entry.

1.6542400631086211e+09	INFO	controller_argocd	reconciling ApplicationSet deployment
E0603 12:37:43.108966   18003 runtime.go:78] Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)
goroutine 506 [running]:
k8s.io/apimachinery/pkg/util/runtime.logPanic({0x237e8a0?, 0x3477f10})
	/Users/aveerama/go/src/github.com/iam-veeramalla/argocd-operator/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:74 +0x86
k8s.io/apimachinery/pkg/util/runtime.HandleCrash({0x0, 0x0, 0x8?})
	/Users/aveerama/go/src/github.com/iam-veeramalla/argocd-operator/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go:48 +0x75
panic({0x237e8a0, 0x3477f10})
	/usr/local/go/src/runtime/panic.go:838 +0x207
github.com/argoproj-labs/argocd-operator/controllers/argocd.getArgoApplicationSetCommand(0xc000b80000)
	/Users/aveerama/go/src/github.com/iam-veeramalla/argocd-operator/controllers/argocd/applicationset.go:47 +0x285
github.com/argoproj-labs/argocd-operator/controllers/argocd.applicationSetContainer(_)
	/Users/aveerama/go/src/github.com/iam-veeramalla/argocd-operator/controllers/argocd/applicationset.go:190 +0x152

Copy link
Collaborator

@iam-veeramalla iam-veeramalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operator Crashed when ApplicationSet entry is removed from CR. I followed below steps

Created the Argo CD CR using

apiVersion: argoproj.io/v1alpha1
kind: ArgoCD
metadata:
  name: example-argocd
  labels:
    example: ingress
spec:
  applicationSet: {}
  server:
    grpc:
      ingress:
        enabled: true
    ingress:
      enabled: true
    insecure: true

After a while(once all the resources are created), I removed the entry for ApplicationSet from CR using oc edit

Please add steps to reproduce or test the PR in the description section.

@iam-veeramalla iam-veeramalla self-assigned this Jun 3, 2022
@rishabh625
Copy link
Contributor Author

Sure will look at all Thanks @iam-veeramalla

Comment on lines 498 to 541
func TestReconcileApplicationSet_DeleteDeployment(t *testing.T) {
logf.SetLogger(ZapLogger(true))
a := makeTestArgoCD()
a.Spec.ApplicationSet = &v1alpha1.ArgoCDApplicationSet{}
r := makeTestReconciler(t, a)
a.Spec.ApplicationSet = nil
checkdeployment := &appsv1.Deployment{}
assert.Error(t, r.Client.Get(
context.TODO(),
types.NamespacedName{
Name: "argocd-applicationset-controller",
Namespace: a.Namespace,
},
checkdeployment))
assert.Equal(t, checkdeployment.Name, "")
checkrole := &v1.Role{}
assert.Error(t, r.Client.Get(
context.TODO(),
types.NamespacedName{
Name: "argocd-applicationset-controller",
Namespace: a.Namespace,
},
checkrole))
assert.Equal(t, checkrole.Name, "")

checksa := &corev1.ServiceAccount{}
assert.Error(t, r.Client.Get(
context.TODO(),
types.NamespacedName{
Name: "argocd-applicationset-controller",
Namespace: a.Namespace,
},
checksa))
assert.Equal(t, checksa.Name, "")
checkroleBinding := &v1.RoleBinding{}
assert.Error(t, r.Client.Get(
context.TODO(),
types.NamespacedName{
Name: "argocd-applicationset-controller",
Namespace: a.Namespace,
},
checkroleBinding))
assert.Equal(t, checkroleBinding.Name, "")
}
Copy link
Collaborator

@jaideepr97 jaideepr97 Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishabh625
are these resources actually getting created in the first place? I don't see a call to reconcile these resources
I think we should make sure to first check that the resources exist and before setting a.spec.applicationset to nil in order to be sure the test is accurate and that resources are in fact being deleted as expected

@jaideepr97
Copy link
Collaborator

@rishabh625
I think the nil pointer reference @iam-veeramalla mentioned is coming from here https://github.com/argoproj-labs/argocd-operator/pull/670/files#diff-547555dfe97d80ddf6097444f1cc82263cce61c48fbb67f6bb8e08c657873bc6L46
we should check if cr.spec.applicationset != nil first

@rishabh625
Copy link
Contributor Author

@rishabh625 I think the nil pointer reference @iam-veeramalla mentioned is coming from here https://github.com/argoproj-labs/argocd-operator/pull/670/files#diff-547555dfe97d80ddf6097444f1cc82263cce61c48fbb67f6bb8e08c657873bc6L46 we should check if cr.spec.applicationset != nil first

thanks @jaideepr97 will look into this, was waiting for discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants