Skip to content

Commit 0433a07

Browse files
chetan-rnsjgwest
authored andcommitted
feat: add support for destination based mapping (#2087)
* feat: add support for destination based mapping Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> * generate bundle manifests Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> * fix lint Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> * address coderabbit review comments Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> * generate bundle Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> * augment the agent clusterrole only for cluster scoped instances Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com> --------- Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
1 parent bb6ae3a commit 0433a07

12 files changed

Lines changed: 547 additions & 16 deletions

File tree

api/v1beta1/argocd_types.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,9 @@ type PrincipalSpec struct {
12861286

12871287
// JWT defines the JWT options for the Principal component.
12881288
JWT *PrincipalJWTSpec `json:"jwt,omitempty"`
1289+
1290+
// DestinationBasedMapping is the flag to enable destination based mapping for the Principal component.
1291+
DestinationBasedMapping *bool `json:"destinationBasedMapping,omitempty"`
12891292
}
12901293

12911294
type PrincipalServerSpec struct {
@@ -1381,6 +1384,10 @@ type AgentSpec struct {
13811384
// Enabled is the flag to enable the Agent component during Argo CD installation. (optional, default `false`)
13821385
Enabled *bool `json:"enabled,omitempty"`
13831386

1387+
// AllowedNamespaces is a list of additional namespaces the agent is allowed to
1388+
// manage applications in. Supports glob patterns.
1389+
AllowedNamespaces []string `json:"allowedNamespaces,omitempty"`
1390+
13841391
// Creds is the credential identifier for the agent authentication
13851392
Creds string `json:"creds,omitempty"`
13861393

@@ -1404,6 +1411,32 @@ type AgentSpec struct {
14041411

14051412
// TLS defines the TLS options for the Agent component.
14061413
TLS *AgentTLSSpec `json:"tls,omitempty"`
1414+
1415+
// DestinationBasedMapping defines the options for destination based mapping for the Agent component.
1416+
DestinationBasedMapping *DestinationBasedMappingSpec `json:"destinationBasedMapping,omitempty"`
1417+
}
1418+
1419+
type DestinationBasedMappingSpec struct {
1420+
// Enabled is the flag to enable destination based mapping for the Agent component.
1421+
Enabled *bool `json:"enabled,omitempty"`
1422+
1423+
// CreateNamespace enables automatic creation of target namespaces on the managed cluster
1424+
// when destination-based mapping is enabled.
1425+
CreateNamespace *bool `json:"createNamespace,omitempty"`
1426+
}
1427+
1428+
func (d *DestinationBasedMappingSpec) IsEnabled() bool {
1429+
if d == nil {
1430+
return false
1431+
}
1432+
return d.Enabled != nil && *d.Enabled
1433+
}
1434+
1435+
func (d *DestinationBasedMappingSpec) IsCreateNamespaceEnabled() bool {
1436+
if d == nil || !d.IsEnabled() || d.CreateNamespace == nil {
1437+
return false
1438+
}
1439+
return *d.CreateNamespace
14071440
}
14081441

14091442
type AgentClientSpec struct {

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/manifests/argocd-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ metadata:
257257
capabilities: Deep Insights
258258
categories: Integration & Delivery
259259
certified: "false"
260-
createdAt: "2026-02-19T21:46:43Z"
260+
createdAt: "2026-02-23T10:26:04Z"
261261
description: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.
262262
operators.operatorframework.io/builder: operator-sdk-v1.35.0
263263
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4

bundle/manifests/argoproj.io_argocds.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11358,6 +11358,13 @@ spec:
1135811358
description: Agent defines configurations for the Agent component
1135911359
of Argo CD Agent.
1136011360
properties:
11361+
allowedNamespaces:
11362+
description: |-
11363+
AllowedNamespaces is a list of additional namespaces the agent is allowed to
11364+
manage applications in. Supports glob patterns.
11365+
items:
11366+
type: string
11367+
type: array
1136111368
client:
1136211369
description: Client defines the client options for the Agent
1136311370
component.
@@ -11392,6 +11399,20 @@ spec:
1139211399
description: Creds is the credential identifier for the agent
1139311400
authentication
1139411401
type: string
11402+
destinationBasedMapping:
11403+
description: DestinationBasedMapping defines the options for
11404+
destination based mapping for the Agent component.
11405+
properties:
11406+
createNamespace:
11407+
description: |-
11408+
CreateNamespace enables automatic creation of target namespaces on the managed cluster
11409+
when destination-based mapping is enabled.
11410+
type: boolean
11411+
enabled:
11412+
description: Enabled is the flag to enable destination
11413+
based mapping for the Agent component.
11414+
type: boolean
11415+
type: object
1139511416
enabled:
1139611417
description: Enabled is the flag to enable the Agent component
1139711418
during Argo CD installation. (optional, default `false`)
@@ -11600,6 +11621,10 @@ spec:
1160011621
description: Auth is the authentication method for the Principal
1160111622
component.
1160211623
type: string
11624+
destinationBasedMapping:
11625+
description: DestinationBasedMapping is the flag to enable
11626+
destination based mapping for the Principal component.
11627+
type: boolean
1160311628
enabled:
1160411629
description: Enabled is the flag to enable the Principal component
1160511630
during Argo CD installation. (optional, default `false`)

config/crd/bases/argoproj.io_argocds.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11347,6 +11347,13 @@ spec:
1134711347
description: Agent defines configurations for the Agent component
1134811348
of Argo CD Agent.
1134911349
properties:
11350+
allowedNamespaces:
11351+
description: |-
11352+
AllowedNamespaces is a list of additional namespaces the agent is allowed to
11353+
manage applications in. Supports glob patterns.
11354+
items:
11355+
type: string
11356+
type: array
1135011357
client:
1135111358
description: Client defines the client options for the Agent
1135211359
component.
@@ -11381,6 +11388,20 @@ spec:
1138111388
description: Creds is the credential identifier for the agent
1138211389
authentication
1138311390
type: string
11391+
destinationBasedMapping:
11392+
description: DestinationBasedMapping defines the options for
11393+
destination based mapping for the Agent component.
11394+
properties:
11395+
createNamespace:
11396+
description: |-
11397+
CreateNamespace enables automatic creation of target namespaces on the managed cluster
11398+
when destination-based mapping is enabled.
11399+
type: boolean
11400+
enabled:
11401+
description: Enabled is the flag to enable destination
11402+
based mapping for the Agent component.
11403+
type: boolean
11404+
type: object
1138411405
enabled:
1138511406
description: Enabled is the flag to enable the Agent component
1138611407
during Argo CD installation. (optional, default `false`)
@@ -11589,6 +11610,10 @@ spec:
1158911610
description: Auth is the authentication method for the Principal
1159011611
component.
1159111612
type: string
11613+
destinationBasedMapping:
11614+
description: DestinationBasedMapping is the flag to enable
11615+
destination based mapping for the Principal component.
11616+
type: boolean
1159211617
enabled:
1159311618
description: Enabled is the flag to enable the Principal component
1159411619
during Argo CD installation. (optional, default `false`)

controllers/argocdagent/agent/deployment.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"reflect"
2222
"strconv"
23+
"strings"
2324

2425
appsv1 "k8s.io/api/apps/v1"
2526
corev1 "k8s.io/api/core/v1"
@@ -329,6 +330,18 @@ func buildAgentContainerEnv(cr *argoproj.ArgoCD) []corev1.EnvVar {
329330
Name: EnvArgoCDAgentEnableResourceProxy,
330331
Value: "true",
331332
},
333+
{
334+
Name: EnvArgoCDAgentDestinationBasedMap,
335+
Value: getAgentDestinationBasedMapping(cr),
336+
},
337+
{
338+
Name: EnvArgoCDAgentCreateNamespace,
339+
Value: getAgentCreateNamespace(cr),
340+
},
341+
{
342+
Name: EnvArgoCDAgentAllowedNamespaces,
343+
Value: getAgentAllowedNamespaces(cr),
344+
},
332345
{
333346
Name: EnvRedisPassword,
334347
ValueFrom: &corev1.EnvVarSource{
@@ -373,6 +386,9 @@ const (
373386
EnvRedisPassword = "REDIS_PASSWORD"
374387
AgentRedisPasswordKey = "admin.password"
375388
AgentRedisSecretnameSuffix = "redis-initial-password" // #nosec G101
389+
EnvArgoCDAgentDestinationBasedMap = "ARGOCD_AGENT_DESTINATION_BASED_MAPPING"
390+
EnvArgoCDAgentCreateNamespace = "ARGOCD_AGENT_CREATE_NAMESPACE"
391+
EnvArgoCDAgentAllowedNamespaces = "ARGOCD_AGENT_ALLOWED_NAMESPACES"
376392
)
377393

378394
// Logging Configuration
@@ -383,6 +399,33 @@ func getAgentLogLevel(cr *argoproj.ArgoCD) string {
383399
return "info"
384400
}
385401

402+
func getAgentDestinationBasedMapping(cr *argoproj.ArgoCD) string {
403+
if hasAgent(cr) {
404+
dm := cr.Spec.ArgoCDAgent.Agent.DestinationBasedMapping
405+
if dm != nil && dm.IsEnabled() {
406+
return "true"
407+
}
408+
}
409+
return "false"
410+
}
411+
412+
func getAgentCreateNamespace(cr *argoproj.ArgoCD) string {
413+
if hasAgent(cr) {
414+
dm := cr.Spec.ArgoCDAgent.Agent.DestinationBasedMapping
415+
if dm != nil && dm.IsCreateNamespaceEnabled() {
416+
return "true"
417+
}
418+
}
419+
return "false"
420+
}
421+
422+
func getAgentAllowedNamespaces(cr *argoproj.ArgoCD) string {
423+
if hasAgent(cr) && len(cr.Spec.ArgoCDAgent.Agent.AllowedNamespaces) > 0 {
424+
return strings.Join(cr.Spec.ArgoCDAgent.Agent.AllowedNamespaces, ",")
425+
}
426+
return ""
427+
}
428+
386429
func getAgentLogFormat(cr *argoproj.ArgoCD) string {
387430
if hasAgent(cr) && cr.Spec.ArgoCDAgent.Agent.LogFormat != "" {
388431
return cr.Spec.ArgoCDAgent.Agent.LogFormat

0 commit comments

Comments
 (0)