Open marcellodesales opened 2 years ago
It's not clear to me yet what ArgoCD needs to display child resources? Is it really something the operator can solve (in the CRD yaml itself, in the status subresource)?
@FxKu Digging more on github issues, It looks like it is discussed at an open ticket https://github.com/argoproj/argo-cd/issues/5082 ... t seems like we need to have labels added to the resources for tracking the relationships...
https://argo-cd.readthedocs.io/en/stable/user-guide/resource_tracking/
That would be awesome to be able to visually see those resources created by the operator as we can use additional gitops tools to manage the state of the deployments...
If it's only about labels you can configure key-value pairs that should be assigned to each resource or that should be inherited from the cluster manifest.
ArgoCD uses the metadata.ownerReference
for tracking o "sub-resources".
These are unfortunately not created by the operator as discussed in https://github.com/zalando/postgres-operator/issues/498 .
It's not clear to me yet what ArgoCD needs to display child resources? Is it really something the operator can solve (in the CRD yaml itself, in the status subresource)?
ArgoCD should ideally be aware of all resources running in the cluster if a full GitOps approach is used. That includes "child resources" of the managed resources, because those are part of the application. One instance where this is especially interesting is, seeing the StatefulSet of the PostgreSQL instance with its Pods, logs and PV(C)s. Another instance is alerting on orphaned resources (resources that are not (transitively) represented in Git).
The ownerReferences
are exactly for such heritage.
If it's only about labels you can configure key-value pairs that should be assigned to each resource or that should be inherited from the cluster manifest.
Adding labels works currently, but has some downsides which is why we (in our setup) stopped using it. And this will go away eventually with a new tracking method anyway
For reference the necessary settings to at least see the resources in ArgoCD are (Helm values):
inherited_annotations:
- argocd.argoproj.io/compare-options
- argocd.argoproj.io/sync-options
inherited_labels:
- argocd.argoproj.io/instance #This label depends on the ArgoCD installation!
The annotations will then have to be added to all postresql
resources, because the created resources will be deleted by ArgoCD otherwise. That in turn will make it impossible to remove a postresql
resource via ArgoCD…
@Wikiwix What kind of issues did you run into with label tracking?
@sagikazarmark
The addition of the necessary config
metadata:
annotations:
argocd.argoproj.io/compare-options: IgnoreExtraneous
argocd.argoproj.io/sync-options: Prune=false
means that a deletion of the postgresql
object in git will be ignored by Argo CD (as the two annotations specifically circumvent the pending deletion).
Thanks @Wikiwix ! I guess the real solution would be adding owner references.
Any update on #498 and whether it would be accepted as a change?
I'd be happy help with the implementation.
Having just tried to get ArgoCD + Zalando Postgres Operator to work smoothly together I've concluded I can't get to a perfect state but fairly close. The key thing is that I want to have the argocd.argoproj.io/compare-options: IgnoreExtraneous
annotation on all entities EXCEPT the root Postgresql manifest to ensure ArgoCD does not touch those resources. This is currently impossible to achieve with Zalando Operator without also setting the same label on the Postgresql manifest itself, and doing so causes things to break.
You can get to a somewhat decent state by configuring Postgres operator with:
custom_pod_annotations
and custom_service_annotations
set to argocd.argoproj.io/compare-options: IgnoreExtraneous
downscaler_annotations
set to - argocd.argoproj.io/compare-options
inherited_annotations
set to:
Configure ArgoCD with:
resourceTrackingMethod: annotation
Then set a suitable argocd.argoproj.io/tracking-id
annotation in your created ArgoCD Application manifest, e.g. test-db:acid.zalan.do/postgresql/postgresql:test-ns/test-db
and have the same tracking-id in your Postgresql manifest.
This causes all resources to appear in the ArgoCD UI and status is "Healthy", "Synced", "Sync OK". I'm also able to delete the ArgoCD Application and everything seems to clean up properly (possible exception here for a ControllerRevision resource that seems to have lingered around).
These are the potential caveats I see with such a setup:
argocd.argoproj.io/compare-options: IgnoreExtraneous
annotation and it is impossible to add it without also adding it in the Zalando Postgresql manifest. ArgoCD shows a "diff" for these objects when you inspect them, and this makes me think there are circumstances where ArgoCD can mess them up.inherited_annotations
list. It feels like less of a problem than the above though because they are connected to the Service which does have argocd.argoproj.io/compare-options: IgnoreExtraneous
. ArgoCD show no diff for these objects.In cases like this I think it would be immensely helpful to have something like a StatefulSet's .spec.template.metadata.annotations
on the Postgresql manifest which then applies to child resources. Right now the Postgres Operator has four options related to annotations and propagation thereof and even when setting all of them the above 5 object types still cannot get any annotations without also setting those annotations on the Postgresql manifest itself.
I've found another workaround, using https://kyverno.io/ Kyverno can patch resources in the cluster, either when they are created or using a background controller on a certain interval (default is 1 hour I believe). I've implemented a background policy that updates the ownerReferences
of StatefulSets
created by the postgres-operator
. When the policy has run ArgoCD correctly displays the link to the statefulset, and from there to the pods :tada:
Here is the ClusterPolicy and the Kyverno helm values that i've used: https://gist.github.com/c0deaddict/79054d2f0b145518d96dfb894a8a2c2c
The same trick can be used to link the other postgres-operator
created resources to the postgresql
resource. It should also be possible to create a policy that acts upon the creation of the statefulset, but I haven't yet looked into that.
Please, answer some short questions which should help us to understand your problem / question better?
Which image of the operator are you using? registry.opensource.zalan.do/acid/postgres-operator:v1.7.1
Where do you run it - cloud or metal? Kubernetes or OpenShift? AWS K8s EKS
Are you running Postgres Operator in production? yes
Type of issue? feature request
🐛 Current Implementation
postgres
, but we don't see the list of resources❓What to display the created resources?
Events section
🎉 What should we see?
🔧 Configuration Used