feat: Ability to create custom labels for namespaces created with syncOptions CreateNamespace #10288
feat: Ability to create custom labels for namespaces created with syncOptions CreateNamespace #10288pasha-codefresh wants to merge 8 commits intoargoproj:masterfrom
Conversation
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Signed-off-by: pashavictorovich <pavel@codefresh.io>
|
Linked PR in GitOps engine. argoproj/gitops-engine#443 |
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10288 +/- ##
==========================================
- Coverage 45.92% 45.90% -0.02%
==========================================
Files 229 229
Lines 28278 28290 +12
==========================================
Hits 12987 12987
- Misses 13518 13530 +12
Partials 1773 1773 ☔ View full report in Codecov by Sentry. |
|
|
||
| type CreateNamespaceMetadata struct { | ||
| Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,1,opt,name=labels"` | ||
| Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,2,opt,name=annotations"` |
There was a problem hiding this comment.
Maybe better providing the name here as well?
Or even make this struct just have a ObjectMeta reference in it?
something like:
type CreateNamespaceMetadata struct {
metav1.ObjectMeta `json:"metadata"`There was a problem hiding this comment.
The name is inferred from the resource referencing the to-be-created namespace.
There was a problem hiding this comment.
As discussed a few scenarios that need to be addressed and documented:
-
ArgoCD needs to correctly maintain the namespace state as defined in the new
CreateNamespaceMetadata. This means that it needs to handle create, update and deletes. It is basically similar thing that we do during the reconciliation but with the difference that the desired state doesn't come from git in this case. -
Define what will be the behaviour if the user provides the namespace with specific state in git and also defines the Application resource with a different state. What will be the correct behaviour in this case?
-
There are some use-cases where users want to define the namespace name dynamically. Are we supporting this use-case as part of this PR?(I can't find the comment where the user asked about this feature.. Let's leave it out for now for simplification.)
Can you link those use cases? afaik the namespace names should always be taken from the resources in the sync operation. |
|
Many thanks for this enhancement. Thanks to this PR, we expect to trigger |
|
@pasha-codefresh do you still have time to move this forwards? |
|
I'd be happy to carry the torch if @pasha-codefresh doesn't have time before the cutting of 2.5 😄 |
|
@blakepettersson that would be awesome! Hoping to cut RC1 next week, but we'll see how multi-source apps goes. :-) |
|
I see that the required changes to implement this was reverted with argoproj/gitops-engine#455, why's that @leoluz @pasha-codefresh @crenshaw-dev? |
@blakepettersson That was reverted because it was breaking Argo CD build as it was introducing a breaking change. |
|
@leoluz can you give some examples on what you mean here?
|
I guess he means what should happen if the Application contains a Namespace resource for the managed namespace. Something like this: syncPolicy:
managedNamespaceMetadata:
annotations:
annotation1: x1
annotation2: y1
labels:
label1: z
label2: vtogether with: apiVersion: v1
kind: Namespace
metadata:
name: same-as-application-namespace
annotations:
annotation1: x2
annotation2: y2
annotation3: new_annotation_valueWhat values should the namespace end up with? |
Exactly. Tks for clarifying that with examples @gazab ! Another case is, the namespace resource is not provided with the application but already exists in the cluster with conflicting labels/annotations values. We need to define what would be this behaviour and document it. |
Indeed, thanks @gazab 😄. IMO at the very least there definitely should be some kind of warning if that happens. Currently when the same k8s resource is managed by two separate Argo applications a Another (complementary?) option could be to say "k8s manifest wins" (with a warning), something like
Today, if an existing k8s resource gets adopted by an ArgoCD application, it would be overwritten by whatever ArgoCD applies right? It would make sense in that case to be consistent and apply the same behaviour for namespaces as well. |
@blakepettersson the difference is that in this case it is the same actor (Argo CD Controller) conflicting with itself. The managedFields would be updated with the same manager. However, the overriding logic you described doesn't look bad and I wouldn't be opposed to that behaviour as long as it is documented. |
|
I might need another pair of eyes to check that I'm not missing something 😄 In #10672, I added some E2E test cases to verify that
I still need to add warnings and/or errors for these conflicts, that's next on my list. |
The more I'm thinking about this, the more I think we should disallow updates to namespaces given any conflict. My current line of thinking is
Thoughts on this @leoluz @crenshaw-dev @gazab? |
|
What's the downside to just silently accepting whatever is in the manifests? |
|
To be fair, I don't really see any downside apart from the fact that it may surprise some users 😄 Doing that would keep this simple, and is inline with how manifests are currently synced. |
@crenshaw-dev @blakepettersson I don't think we should do that. Existing namespaces might hold crucial labels and annotations that are necessary for the correct operation of user's clusters. Argo CD shouldn't just replace all annotations and labels as it would certainly break some k8s setups. I think it would be better continue with further discussions in @blakepettersson PR (#10672) I am closing this for now. |
This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
* namespace labels Signed-off-by: pashavictorovich <pavel@codefresh.io> * create namespace should support annotations Signed-off-by: pashavictorovich <pavel@codefresh.io> * handle also modification hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * regenerate entity on modify hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * manifests Signed-off-by: pashavictorovich <pavel@codefresh.io> * feat: enable metadata to be set on namespaces This builds upon the work that @pasha-codefresh did in #10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes #4628 Closes #6215 Closes #7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: don't always track namespaces For now, only allow namespaces managed with `managedNamespaceMetadata` to have tracking set by Argo. Ideally we'd like new namespaces to also be tracked by Argo, but there's currently an issue with a failing integration test. Also wrap error message if setting the app instance errors on the namespace. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: always return true with `hasManagedMetadata` If `hasManagedMetadata` is set, `true` should always be returned. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * docs: add clarifying docs on resource tracking Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * style: pr tweaks Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: re-add label unsetting Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * Update gitops-engine to current master Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: pashavictorovich <pavel@codefresh.io> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>
* namespace labels Signed-off-by: pashavictorovich <pavel@codefresh.io> * create namespace should support annotations Signed-off-by: pashavictorovich <pavel@codefresh.io> * handle also modification hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * regenerate entity on modify hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * manifests Signed-off-by: pashavictorovich <pavel@codefresh.io> * feat: enable metadata to be set on namespaces This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: don't always track namespaces For now, only allow namespaces managed with `managedNamespaceMetadata` to have tracking set by Argo. Ideally we'd like new namespaces to also be tracked by Argo, but there's currently an issue with a failing integration test. Also wrap error message if setting the app instance errors on the namespace. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: always return true with `hasManagedMetadata` If `hasManagedMetadata` is set, `true` should always be returned. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * docs: add clarifying docs on resource tracking Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * style: pr tweaks Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: re-add label unsetting Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * Update gitops-engine to current master Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: pashavictorovich <pavel@codefresh.io> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com>
* namespace labels Signed-off-by: pashavictorovich <pavel@codefresh.io> * create namespace should support annotations Signed-off-by: pashavictorovich <pavel@codefresh.io> * handle also modification hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * regenerate entity on modify hook Signed-off-by: pashavictorovich <pavel@codefresh.io> * manifests Signed-off-by: pashavictorovich <pavel@codefresh.io> * feat: enable metadata to be set on namespaces This builds upon the work that @pasha-codefresh did in argoproj#10288. The main differences between this PR and the previous one is that we use SSA to diff between different versions of the namespace, as well as having a slightly different API in gitops-engine for setting the namespace modifier. We now also set the ownership of the namespace in ArgoCD. Closes argoproj#4628 Closes argoproj#6215 Closes argoproj#7799 Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: don't always track namespaces For now, only allow namespaces managed with `managedNamespaceMetadata` to have tracking set by Argo. Ideally we'd like new namespaces to also be tracked by Argo, but there's currently an issue with a failing integration test. Also wrap error message if setting the app instance errors on the namespace. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: always return true with `hasManagedMetadata` If `hasManagedMetadata` is set, `true` should always be returned. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * docs: add clarifying docs on resource tracking Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * style: pr tweaks Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * fix: re-add label unsetting Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> * Update gitops-engine to current master Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com> Signed-off-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: pashavictorovich <pavel@codefresh.io> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Signed-off-by: emirot <emirot.nolan@gmail.com>
Closes #4628
Closes #6215
Closes #7799