argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
16.45k stars 4.97k forks source link

App names with non-alphanumeric characters in position 63 break syncs due to invalid label name #18237

Closed RobinsonZ closed 1 week ago

RobinsonZ commented 2 weeks ago

Checklist:

Describe the bug

When using annotation+label tracking method, app names with more than 63 characters are truncated to 63 characters. If the 63rd character is a hyphen, then the label value is invalid and the sync fails with the following error:

Failed sync attempt to a3e64b7ba2ba8ddc3d5878bc6aa2e116d29e0a50: one or more objects failed to apply, reason: ConfigMap "test" is invalid: metadata.labels: Invalid value: "the-very-suspicious-name-with-precisely-sixty-three-characters-": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?') (retried 1 times).

I believe the issue is in this code:

https://github.com/argoproj/argo-cd/blob/2b89d6c2220160a55dd71b1f2b57f4744decf210/util/argo/resource_tracking.go#L156-L158

To Reproduce

  1. Set application.resourceTrackingMethod: annotation+label in argocd-cm
  2. Create an application with a name that has a hyphen as its 63rd character, e.g. the-very-suspicious-name-with-precisely-sixty-three-characters-with-hyphen, containing any resources
  3. Attempt to sync the app

Expected behavior

The application syncs normally.

Screenshots

image image

Version

argocd: v2.10.5+335875d
  BuildDate: 2024-03-28T16:12:55Z
  GitCommit: 335875d13e018bed6e03873f4742582582964745
  GitTreeState: clean
  GoVersion: go1.21.8
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.11.0-rc2+24ef777
  BuildDate: 2024-04-15T19:43:50Z
  GitCommit: 24ef7775e79a6ec20b441544aacf8d9d727a676f
  GitTreeState: clean
  GoVersion: go1.21.9
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.2.1 2023-10-19T20:13:51Z
  Helm Version: v3.14.3+gf03cc04
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0

Logs

N/A

jannfis commented 2 weeks ago

This seems to be a duplicate of https://github.com/argoproj/argo-cd/issues/10110

RobinsonZ commented 2 weeks ago

Thanks for the catch - see my comment on #18256.