Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Update #11

Merged
merged 7 commits into from Jul 16, 2020
Merged

Update #11

merged 7 commits into from Jul 16, 2020

Conversation

OmerKahani
Copy link
Contributor

@OmerKahani OmerKahani commented Jul 11, 2020

Refactor the create application method so it will also do update and delete.

Not sure about the name of the function, does doing delete in an apply function is ok?

@@ -111,21 +145,30 @@ func (r *ApplicationSetReconciler) createApplications(ctx context.Context, appli
})

if err != nil {
log.Error(err, fmt.Sprintf("failed to get Application %s resource for applicationSet %s", app.Name, applicationSetInfo.Name))
log.Error(err, fmt.Sprintf("failed to CreateOrUpdate Application %s resource for applicationSet %s", app.Name, applicationSetInfo.Name))
Copy link
Member

Choose a reason for hiding this comment

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

We should add action in the log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

func (r *ApplicationSetReconciler) getApplications(ctx context.Context, applicationSetInfo argoprojiov1alpha1.ApplicationSet) ([]argov1alpha1.Application, error) {
// Delete apps that are not in m[string]bool
Copy link
Member

Choose a reason for hiding this comment

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

I think we should separate out this function , delete application shouldn't exists in apply function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return ctrl.Result{}, err
}
r.createOrUpdateInCluster(ctx, applicationSetInfo, desiredApplications)
r.deleteInCluster(ctx, applicationSetInfo, desiredApplications)
Copy link
Member

Choose a reason for hiding this comment

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

Should we have some if conditions, like if finalizers is set , we should delete this cluster?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is what you meant, we definitely will want to add a finalizer to ApplicationSets, and if deleting the appset we must cleanup all Applications before removing that finalizer. Deletion cleanup should probably be a separate PR. I can try to find some time for this one this week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function deletes old applications from the cluster (deleted record from a list)

Deletion of ApplicationSets is implemented with owner reference so the Kubernetes GC will catch it and delete the applications

Copy link
Contributor Author

Choose a reason for hiding this comment

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

going over the proposal, every application should have resources-finalizer.argocd.argoproj.io entry in metadata.finalizers - Added it, thanks!

Do we also want to support the option to delete a record from a list / directory from git, and not run the finalizers in the application (something like kubectl delete app NAME --cascade=false) ?

Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to support the option to delete a record from a list / directory from git, and not run the finalizers in the application (something like kubectl delete app NAME --cascade=false) ?

I think we don't need to implement this for now

Copy link
Contributor

Choose a reason for hiding this comment

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

this function deletes old applications from the cluster (deleted record from a list)

Deletion of ApplicationSets is implemented with owner reference so the Kubernetes GC will catch it and delete the applications

My mistake, forgot about that!

Copy link
Member

@xianlubird xianlubird left a comment

Choose a reason for hiding this comment

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

Should we have some if conditions, like if finalizers is set , we should delete this cluster?

})

if err != nil {
log.Error(err, fmt.Sprintf("failed to get Application %s resource for applicationSet %s", app.Name, applicationSetInfo.Name))
log.Error(err, fmt.Sprintf("failed to CreateOrUpdate Application %s resource for applicationSet %s", app.Name, applicationSet.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion for using logrus and structured logging:

Define a logger with context within your loop:

appLog := log.WithFields(log.Fields{"app": app.Name, "appSet": applicationSet.Name})

Then use appLog within the loop.

appLog.WithError(err).Error("failed to CreateOrUpdate Application")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added thanks!

return ctrl.Result{}, err
}
r.createOrUpdateInCluster(ctx, applicationSetInfo, desiredApplications)
r.deleteInCluster(ctx, applicationSetInfo, desiredApplications)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is what you meant, we definitely will want to add a finalizer to ApplicationSets, and if deleting the appset we must cleanup all Applications before removing that finalizer. Deletion cleanup should probably be a separate PR. I can try to find some time for this one this week.

Copy link
Member

@xianlubird xianlubird left a comment

Choose a reason for hiding this comment

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

@dgoodwin WDYT?

@dgoodwin
Copy link
Contributor

LGTM. I'll merge it in.

@dgoodwin dgoodwin merged commit f1d1c9e into argoproj:master Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants