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

fix: apply ssa namespace twice #537

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

blakepettersson
Copy link
Member

In argoproj/argo-cd#13965, upgrading to client-go 0.26 uncovered an issue with existing namespaces not preserving labels and annotations when converting an existing namespace to use managedNamespaceMetadata.

From 0.26 up, in order to preserve the existing behaviour what we need to do is to first apply the existing namespace with SSA and its preexisting labels and annotations. This also needs to be applied with another manager than the default one.

After that initial apply, we proceed as normal with a ServerSideApply. This is a one-time thing for any existing namespace; we check if we need to perform this action by detecting if there is a preexisting SSA annotation on the namespace.

nsSpec := &v1.Namespace{TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: kube.NamespaceKind}, ObjectMeta: metav1.ObjectMeta{Name: t.liveObj.GetName(), Annotations: t.liveObj.GetAnnotations(), Labels: t.liveObj.GetLabels(), Namespace: t.liveObj.GetNamespace()}}
liveCopy, err := kube.ToUnstructured(nsSpec)

message, err = sc.resourceOps.ApplyResource(context.TODO(), liveCopy, dryRunStrategy, force, validate, serverSideApply, "argocd-controller-tmp")
Copy link
Member Author

Choose a reason for hiding this comment

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

argocd-controller-tmp is a placeholder name, but the idea is that in order to preserve existing metadata we need to apply the namespace with a separate manager before using managedNamespaceMetadata on said namespace.

@sonarcloud
Copy link

sonarcloud bot commented Aug 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (f15cf61) 54.63% compared to head (0115c94) 54.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #537   +/-   ##
=======================================
  Coverage   54.63%   54.64%           
=======================================
  Files          41       41           
  Lines        4638     4652   +14     
=======================================
+ Hits         2534     2542    +8     
- Misses       1908     1912    +4     
- Partials      196      198    +2     
Files Coverage Δ
pkg/sync/sync_context.go 73.81% <62.50%> (-0.27%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 17, 2023
This requires argoproj/gitops-engine#537. This is more or less similar
to argoproj#13965, with the difference that this is _only_ upgrading dependencies
and does not require any changes in the usage of
`managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 17, 2023
This requires argoproj/gitops-engine#537. This is more or less similar
to argoproj#13965, with the difference that this is _only_ upgrading dependencies
and does not require any changes in the usage of
`managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 18, 2023
This requires argoproj/gitops-engine#537. This builds upon argoproj#13965,
with the difference that this does not require any changes in the usage
of `managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 18, 2023
This requires argoproj/gitops-engine#537. This builds upon argoproj#13965,
with the difference that this does not require any changes in the usage
of `managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 18, 2023
This requires argoproj/gitops-engine#537. This builds upon argoproj#13965,
with the difference that this does not require any changes in the usage
of `managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 19, 2023
This requires argoproj/gitops-engine#537. This builds upon argoproj#13965,
with the difference that this does not require any changes in the usage
of `managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 19, 2023
This requires argoproj/gitops-engine#537. This builds upon argoproj#13965,
with the difference that this does not require any changes in the usage
of `managedNamespaceMetadata`.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Aug 19, 2023
Use argoproj/gitops-engine#537 version of gitops-engine, which preserves
the intended behaviour; which is that an existing namespace can be
"adopted" when using `managedNamespaceMetadata` without removing existing
labels and annotations.

Signed-off-by: Blake Pettersson <[email protected]>
pkg/sync/sync_context.go Outdated Show resolved Hide resolved
pkg/sync/sync_context.go Outdated Show resolved Hide resolved
blakepettersson added a commit to blakepettersson/argo-cd that referenced this pull request Sep 19, 2023
This is based on argoproj#13965, which this time hopefully has been updated
and merged correctly to a currentish version of argo-cd.

The main difference here is that the gitops version is based upon
argoproj/gitops-engine#537, which should maintain pre-existing
labels and annotations.

Signed-off-by: Blake Pettersson <[email protected]>
blakepettersson and others added 4 commits October 14, 2023 00:14
In argoproj/argo-cd#13965, upgrading to client-go 0.26 uncovered an
issue with existing namespaces not preserving labels and annotations
when converting an existing namespace to use `managedNamespaceMetadata`.

From 0.26 up, in order to preserve the existing behaviour what we need
to do is to first apply the existing namespace with SSA and its
preexisting labels and annotations. This also needs to be applied with
another manager than the default one.

After that initial apply, we proceed as normal with a ServerSideApply.
This is a one-time thing for any existing namespace; we check if we need
to perform this action by detecting if there is a preexisting SSA
annotation on the namespace.

Signed-off-by: Blake Pettersson <[email protected]>
Signed-off-by: Blake Pettersson <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
Signed-off-by: Blake Pettersson <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
Signed-off-by: Blake Pettersson <[email protected]>
Signed-off-by: Blake Pettersson <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Oct 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

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

Successfully merging this pull request may close these issues.

None yet

2 participants