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

feat: Allow applications in any namespace #612

Closed

Conversation

iandelahorne
Copy link

@iandelahorne iandelahorne commented Aug 20, 2023

Add --namespaced flag, that when true will only monitor the configured namespace for applications. If it is false, then monitor all namespaces for applications.

By default this is set to true to preserve the current behavior.

fixes #601

@iandelahorne
Copy link
Author

👋 Looking for feedback on this, specifically around the default behavior of this flag. Ideally it should default to be global (i e false), but I didn't want to break compatibility without discussing it.

I suspect I will have to add documentation updates as well as RBAC and helm chart updates, happy to do so if this is something the maintainers think is a good idea.

@iandelahorne iandelahorne force-pushed the namespace-support branch 3 times, most recently from da55471 to b378e4b Compare September 3, 2023 22:45
@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2023

Codecov Report

Merging #612 (de9d4e4) into master (82d59ef) will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #612      +/-   ##
==========================================
+ Coverage   65.35%   65.48%   +0.13%     
==========================================
  Files          22       22              
  Lines        2084     2092       +8     
==========================================
+ Hits         1362     1370       +8     
  Misses        588      588              
  Partials      134      134              
Files Coverage Δ
pkg/argocd/argocd.go 66.66% <100.00%> (+0.27%) ⬆️
pkg/argocd/update.go 67.14% <100.00%> (+0.59%) ⬆️
pkg/kube/kubernetes.go 85.50% <100.00%> (+0.21%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jannfis
Copy link
Contributor

jannfis commented Sep 28, 2023

@iandelahorne Thanks a lot for your contribution, and apologies that I again haven't found the time to react timely on it.

I will try to review your PR the coming days.

Copy link
Contributor

@jannfis jannfis left a comment

Choose a reason for hiding this comment

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

First quick review, have a couple of comments.

Generally, I believe the pattern should follow a similar pattern than what Argo CD does, i.e. instead of having a bool to turn it on, give it a list of namespaces that it's allowed to dig into. Then, ignore those applications that are popping up and that are not in that namespace.

@@ -176,17 +176,16 @@ func FilterApplicationsForUpdate(apps []v1alpha1.Application, patterns []string,
var appsForUpdate = make(map[string]ApplicationImages)

for _, app := range apps {
logCtx := log.WithContext().AddField("application", app.GetName())
appNSName := fmt.Sprintf("%s/%s", app.GetNamespace(), app.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use app.QualifiedName() to get the representation of <namespace>/<name> of an app instead of rolling your own here :)

Copy link
Author

Choose a reason for hiding this comment

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

Oh nice, i'll go ahead and use those.

// Check whether application has our annotation set
annotations := app.GetAnnotations()
if _, ok := annotations[common.ImageUpdaterAnnotation]; !ok {
logCtx.Tracef("skipping app '%s' of type '%s' because required annotation is missing", app.GetName(), app.Status.SourceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this trace statement?

Copy link
Author

Choose a reason for hiding this comment

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

I honestly thought I had added it and was removing it before commiting, good catch.

continue
}

// Check for valid application type
if !IsValidApplicationType(&app) {
logCtx.Warnf("skipping app '%s' of type '%s' because it's not of supported source type", app.GetName(), app.Status.SourceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this warning statement?

@@ -198,16 +197,16 @@ func FilterApplicationsForUpdate(apps []v1alpha1.Application, patterns []string,

// Check if application carries requested label
if !matchAppLabels(app.GetName(), app.GetLabels(), appLabel) {
logCtx.Debugf("Skipping app '%s' because it does not carry requested label", app.GetName())
logCtx.Debugf("Skipping app '%s' because it does not carry requested label", appNSName)
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned earlier, you can use app.QualifiedName() here

continue
}

logCtx.Tracef("processing app '%s' of type '%v'", app.GetName(), app.Status.SourceType)
logCtx.Tracef("processing app '%s' of type '%v'", appNSName, app.Status.SourceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned earlier, you can use app.QualifiedName() here

imageList := parseImageList(annotations)
appImages := ApplicationImages{}
appImages.Application = app
appImages.Images = *imageList
appsForUpdate[app.GetName()] = appImages
appsForUpdate[appNSName] = appImages
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned earlier, you can use app.QualifiedName() here

@iandelahorne
Copy link
Author

iandelahorne commented Sep 29, 2023

Thanks for the feedback. It does sound cleaner to specify the list of namespaces or wildcard, and if none is specifed default to the current namespace. I'll take a stab at implementing that soon if that's the route you think we should go. In the meantime I addressed the most immediate PR feedback.

@villisco
Copy link

villisco commented Oct 2, 2023

This cluster role would be needed as well:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app.kubernetes.io/name: argocd-image-updater-cluster-apps
    app.kubernetes.io/instance: argocd
    app.kubernetes.io/part-of: argocd-image-updater
    app.kubernetes.io/component: controller
  annotations:
    argocd.argoproj.io/tracking-id: argocd:rbac.authorization.k8s.io/Role:argocd/argocd-image-updater-cluster-apps
  name: argocd-image-updater-cluster-apps
rules:
  - apiGroups:
      - ''
    verbs:
      - get
      - list
      - watch
    resources:
      - secrets
      - configmaps
  - apiGroups:
      - argoproj.io
    verbs:
      - get
      - list
      - update
      - patch
    resources:
      - applications
  - apiGroups:
      - ''
    verbs:
      - create
    resources:
      - events
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    app.kubernetes.io/name: argocd-image-updater-cluster-apps
    app.kubernetes.io/instance: argocd
    app.kubernetes.io/part-of: argocd-image-updater
    app.kubernetes.io/component: controller
  name: argocd-image-updater-cluster-apps
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: argocd-image-updater-cluster-apps
subjects:
  - kind: ServiceAccount
    name: argocd-image-updater
    namespace: argocd

@villisco
Copy link

villisco commented Oct 2, 2023

Hope it gets merged soon. much needed feature! :)

@villisco
Copy link

Any news on this?

iandelahorne and others added 2 commits October 31, 2023 16:31
Add `--namespaced` flag, that when true will only monitor the configured
namespace for applications. If it is false, then monitor all namespaces
for applications.

By default this is set to `true` to preserve the current behavior.

fixes argoproj-labs#611

Signed-off-by: Ian Delahorne <[email protected]>
Signed-off-by: Ian Delahorne <[email protected]>
Use `app.QualifiedName()` instead of creating a namespace/name string.
In addition, I had erroneously removed trace statements, which are now back.

Signed-off-by: Ian Delahorne <[email protected]>
@iandelahorne
Copy link
Author

@villisco Sorry for the delay, I've been busy with my day job. I'm starting to take a look at refactoring this to take a list of namespaces.

@villisco
Copy link

villisco commented Nov 4, 2023

iandelahorne

Been using this PR image and works great so far! Thank you @iandelahorne Great work! :)

@torfjor
Copy link

torfjor commented Nov 14, 2023

This PR does not address the git write back method for applications in any namespace. Application overrides are still written to the file .argocd-source-appName.yaml. Moving that file to .argocd-source-appNamespace_appName.yaml seems to make things work.

@ElanHasson
Copy link

Any updates on this one?

@iandelahorne
Copy link
Author

iandelahorne commented Dec 22, 2023 via email

@ElanHasson
Copy link

ElanHasson commented Dec 23, 2023

@iandelahorne I understand. I am happy to help in any way I can, just let me know!

I also know @renchap wants this feature as well.

@mcanevet
Copy link

mcanevet commented Jan 23, 2024

@iandelahorne any news on this?

I get this error in the logs when using this branch with git write back:

2024-01-23 11:42:32 | panic: runtime error: invalid memory address or nil pointer dereference
-- | --
2024-01-23 11:42:32 | [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc4e82d]
2024-01-23 11:42:32 |  
2024-01-23 11:42:32 | goroutine 1954 [running]:
2024-01-23 11:42:32 | github.com/argoproj/argo-cd/v2/util/git.HTTPSCreds.Environ({{0xc00178fba8, 0x6}, {0xc001649c00, 0x1a}, 0x0, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...})
2024-01-23 11:42:32 | /go/pkg/mod/github.com/argoproj/argo-cd/[email protected]/util/git/creds.go:218 +0xb6d
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/ext/git.(*nativeGitClient).runCredentialedCmd(0xc00099f9d0, {0x24afa3d?, 0xc001271f20?}, {0xc0017df2c0?, 0x6?, 0x28341b8?})
2024-01-23 11:42:32 | /src/argocd-image-updater/ext/git/client.go:595 +0x8b
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/ext/git.(*nativeGitClient).Fetch(0xc00099f9d0, {0x0?, 0x0?})
2024-01-23 11:42:32 | /src/argocd-image-updater/ext/git/client.go:332 +0x236
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesGit(0xc000eacc00, 0xc001808420, {0xc000f597d0, 0x1, 0x1}, 0x25e8610)
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/git.go:159 +0x365
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChanges(0xc000be4400?, 0xc0007b9100?, {0xc000f597d0?, 0xc001289c30?, 0xc00146b680?})
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:574 +0x5b
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesLocked(0xc001276500?, 0xc001808420?, 0x34?, {0xc000f597d0?, 0x1?, 0x1?})
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:554 +0x110
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.UpdateApplication(0xc0017dfb88, 0x19?)
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:337 +0x1fcd
2024-01-23 11:42:32 | main.runImageUpdater.func1({_, _}, {{{{0xc0011f2df0, 0xb}, {0xc000969e60, 0x14}}, {{0xc0009c2ea0, 0x26}, {0x0, 0x0}, ...}, ...}, ...})
2024-01-23 11:42:32 | /src/argocd-image-updater/cmd/run.go:322 +0x287
2024-01-23 11:42:32 | created by main.runImageUpdater
2024-01-23 11:42:32 | /src/argocd-image-updater/cmd/run.go:308 +0xa1e
2024-01-23 11:42:32 | panic: runtime error: invalid memory address or nil pointer dereference
2024-01-23 11:42:32 | [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc4e82d]
2024-01-23 11:42:32 |  
2024-01-23 11:42:32 | goroutine 2056 [running]:
2024-01-23 11:42:32 | github.com/argoproj/argo-cd/v2/util/git.HTTPSCreds.Environ({{0xc0011ec070, 0x6}, {0xc000f342a0, 0x1a}, 0x0, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...})
2024-01-23 11:42:32 | /go/pkg/mod/github.com/argoproj/argo-cd/[email protected]/util/git/creds.go:218 +0xb6d
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/ext/git.(*nativeGitClient).runCredentialedCmd(0xc0001b45b0, {0x24afa3d?, 0xc001701260?}, {0xc000ec92c0?, 0x6?, 0x28341b8?})
2024-01-23 11:42:32 | /src/argocd-image-updater/ext/git/client.go:595 +0x8b
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/ext/git.(*nativeGitClient).Fetch(0xc0001b45b0, {0x0?, 0x0?})
2024-01-23 11:42:32 | /src/argocd-image-updater/ext/git/client.go:332 +0x236
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesGit(0xc001973800, 0xc001808580, {0xc0003f1038, 0x1, 0x1}, 0x25e8610)
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/git.go:159 +0x365
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChanges(0xc000be4400?, 0xc000a3ca20?, {0xc0003f1038?, 0xc0009b5250?, 0xc0009d7680?})
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:574 +0x5b
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.commitChangesLocked(0xc001276a40?, 0xc001808580?, 0x34?, {0xc0003f1038?, 0x1?, 0x1?})
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:554 +0x110
2024-01-23 11:42:32 | github.com/argoproj-labs/argocd-image-updater/pkg/argocd.UpdateApplication(0xc000ec9b88, 0x19?)
2024-01-23 11:42:32 | /src/argocd-image-updater/pkg/argocd/update.go:337 +0x1fcd
2024-01-23 11:42:32 | main.runImageUpdater.func1({_, _}, {{{{0xc000a52950, 0xb}, {0xc000a33458, 0x14}}, {{0xc00133e660, 0x20}, {0x0, 0x0}, ...}, ...}, ...})
2024-01-23 11:42:32 | /src/argocd-image-updater/cmd/run.go:322 +0x287
2024-01-23 11:42:32 | created by main.runImageUpdater
2024-01-23 11:42:32 | /src/argocd-image-updater/cmd/run.go:308 +0xa1e

When I cherry-picked 674da709ce72e8b2c8bedd28ea59a58df0c0f127 on top of v0.12.2. It's better, but somehow it can't find the ConfigMap containing the credentials:

Could not update application spec: could not get creds for repo 'https://gitlab.com/<myorg>/<my-application-repo>.git': configmap \"argocd-cm\" not found" application=<my-application>

@iandelahorne
Copy link
Author

@mcanevet @ElanHasson Apologies for the delays and for abandoning this. I just started a new position and ArgoCD is no longer a part of my daily life. If someone else wants to take this up and move it forward, I still believe this is a valuable feature. I just can't commit currently to updating this at any point in the near future sadly.

@rossigee rossigee mentioned this pull request Jan 26, 2024
@rossigee
Copy link

Thanks @iandelahorne - I updated your PR and re-submitted it here. This PR can be closed now.

@iandelahorne
Copy link
Author

Thanks @rossigee for taking this over!

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.

Image Updater does not work with "App in any namespace" Argo configuration
8 participants