Skip to content

Commit 0c3235b

Browse files
committed
comment: add factory description
Signed-off-by: EunJiJung <[email protected]>
1 parent 84c55c1 commit 0c3235b

File tree

17 files changed

+1514
-24
lines changed

17 files changed

+1514
-24
lines changed

TROUBLESHOOTING_BLOG.md

Lines changed: 596 additions & 0 deletions
Large diffs are not rendered by default.

agent/agent.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,42 @@ type Agent struct {
7272
connected atomic.Bool
7373
// syncCh is not currently used
7474
syncCh chan bool
75+
/**
76+
* STREAM/CONNECTION INTERFACE ABSTRACTION DESIGN
77+
*
78+
* GOAL: Remove gRPC dependency from application layer
79+
*
80+
* Current gRPC-dependent:
81+
* remote *client.Remote → eventstreamapi.EventStream_SubscribeClient
82+
*
83+
* Proposed transport-agnostic:
84+
* transport Transport → Stream interface
85+
*
86+
* Key Interfaces:
87+
*
88+
* type Transport interface {
89+
* Connect(ctx context.Context) error
90+
* CreateStream(ctx context.Context) (Stream, error)
91+
* Close() error
92+
* }
93+
*
94+
* type Stream interface {
95+
* Send(*cloudevents.Event) error // Direct CloudEvent
96+
* Receive() (*cloudevents.Event, error) // Direct CloudEvent
97+
* Close() error
98+
* }
99+
*
100+
* Benefits:
101+
* - Application layer works with CloudEvents directly
102+
* - gRPC Protobuf conversion hidden in transport layer
103+
* - Same interface for gRPC, gRPC-WS, HTTP, Kafka
104+
* - Minimal code changes (just interface swap)
105+
*
106+
* Implementation Strategy:
107+
* 1. Keep existing gRPC logic in transport implementations
108+
* 2. Wrap current Remote/EventStream with new interfaces
109+
* 3. Move format.ToProto/FromProto to gRPC transport layer
110+
*/
75111
remote *client.Remote
76112
appManager *application.ApplicationManager
77113
projectManager *appproject.AppProjectManager

agent/connection.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ func (a *Agent) handleStreamEvents() error {
169169
return err
170170
}
171171

172+
/**
173+
* STREAM INTERFACE ABSTRACTION
174+
*
175+
* Current: EventWriter accepts gRPC stream directly
176+
* a.eventWriter = event.NewEventWriter(stream)
177+
*
178+
* Proposed: EventWriter accepts Stream interface
179+
* a.eventWriter = event.NewEventWriter(stream) // Same call, different type
180+
*
181+
* Key Change in EventWriter:
182+
* - streamWriter interface changes from gRPC-specific to CloudEvent-based
183+
* - Send(*eventstreamapi.Event) → Send(*cloudevents.Event)
184+
* - Transport layer handles Protobuf conversion internally
185+
*/
172186
a.eventWriter = event.NewEventWriter(stream)
173187
go a.eventWriter.SendWaitingEvents(a.context)
174188

docs/concepts/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The connection between an [agent](./components-terminology.md#agent) and the [pr
3939

4040
*argocd-agent* is not designed to nor does it intend to replace any existing functionality in Argo CD. Its scope is to change the way how Applications are being deployed in a multi-cluster scenario, especially when there are more than a couple of clusters involved. And the project intends to require as minimal changes to Argo CD as possible, using any out-of-the-box Argo CD installation as the ultimate target.
4141

42-
Under the hood, *argocd-agent* uses a message based protocol to establish a *bi-directional* exchange of messages. Bi-directional in this context means that both, the [principal](./components-terminology.md#principal) and the [agents](./components-terminology.md#agent) can send and receive messages simultaneously using the same connection, which is established exclusively by the agents. As of today, the underlying transport is gRPC based, but there are [plans](https://github.com/argoproj-labs/argocd-agent/issues/260) to make this extensible. The vision for this is that one could use a message bus implementation such as Kafka for the transport of messages if they wanted to.
42+
Under the hood, *argocd-agent* uses a message based protocol to establish a *bi-directional* exchange of messages. Bi-directional in this context means that both, the [principal](./components-terminology.md#principal) and the [agents](./components-terminology.md#agent) can send and receive messages simultaneously using the same connection, which is established exclusively by the agents. /* As of today, the underlying transport is gRPC based, but there are [plans](https://github.com/argoproj-labs/argocd-agent/issues/260) to make this extensible. The vision for this is that one could use a message bus implementation such as Kafka for the transport of messages if they wanted to. */
4343

4444
## Design principles
4545

@@ -59,7 +59,7 @@ There are architectural variants in which a workload cluster will be dependent u
5959

6060
**The initiating component is always the agent, not the control plane**
6161

62-
Connections are established in one direction only: from the agent to the control plane. Neither the control plane nor the agents need to know exact details about the topology of the system, as long as the agents know which control plane to connect to. In some parts of this documentation, we mention something called a _bi-directional stream_. This refers to a gRPC mechanisms where both parties may randomly transmit and receive data from its peer, all while the connection is established only in one direction.
62+
Connections are established in one direction only: from the agent to the control plane. Neither the control plane nor the agents need to know exact details about the topology of the system, as long as the agents know which control plane to connect to. /* In some parts of this documentation, we mention something called a _bi-directional stream_. This refers to a gRPC mechanisms where both parties may randomly transmit and receive data from its peer, all while the connection is established only in one direction. */
6363

6464
**Be lightweight by default but keep extensibility in mind**
6565

docs/concepts/sync-protocol.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ The protocol uses a **hub-and-spoke** architecture where:
2020
- **Principal**: Runs on the control plane, acts as the central coordination point
2121
- **Agents**: Run on workload clusters, initiate all connections to the principal
2222
- **Connections**: Always initiated by agents (never principal-to-agent)
23-
- **Streams**: Bidirectional gRPC streams over HTTP/2 (with HTTP/1.1 websocket fallback)
23+
- **Streams**: Bidirectional event streams using pluggable transports
2424

2525
```
26-
┌─────────────────┐ gRPC/HTTP2 ┌─────────────────┐
26+
┌─────────────────┐ Stream ┌─────────────────┐
2727
│ Agent 1 │──────────────────►│ Principal │
2828
│ (Workload) │ │ (Control Plane) │
2929
└─────────────────┘ └─────────────────┘
@@ -34,6 +34,18 @@ The protocol uses a **hub-and-spoke** architecture where:
3434
└─────────────────┘
3535
```
3636

37+
### Transport Options
38+
39+
**Direct Connection**:
40+
- gRPC streams over HTTP/2 (default)
41+
- WebSocket over HTTP/1.1
42+
- Server-Sent Events (SSE)
43+
44+
**Message Queue**:
45+
- Kafka topics
46+
- Redis streams
47+
- NATS messaging
48+
3749
### Protocol Stack
3850

3951
```
@@ -42,33 +54,28 @@ The protocol uses a **hub-and-spoke** architecture where:
4254
├─────────────────────────────────────┤
4355
│ CloudEvents Format │ ← Event envelope with metadata
4456
├─────────────────────────────────────┤
45-
│ gRPC Streaming │ ← Bidirectional streams
57+
│ Stream Interface │ ← Send/Receive abstraction
58+
├─────────────────────────────────────┤
59+
│ Connection interface │ ← Connection management
60+
├─────────────────────────────────────┤
61+
│ Transport Factory │ ← Transport selection (gRPC, ws, Kafka)
4662
├─────────────────────────────────────┤
47-
│ HTTP/2 (or HTTP/1+WS) │ ← Transport layer
63+
│ ┌─────────────┬─────────────────┐ │
64+
│ │ Direct │ Message Router │ │ ← Connection patterns
65+
│ │ Connection │ (Kafka, etc.) │ │
66+
│ └─────────────┴─────────────────┘ │
4867
├─────────────────────────────────────┤
4968
│ TLS + mTLS │ ← Security layer
5069
└─────────────────────────────────────┘
5170
```
5271

5372
## Communication Protocol
5473

55-
### gRPC Service Definition
56-
57-
The core communication is defined by the `EventStream` service:
58-
59-
```protobuf
60-
service EventStream {
61-
rpc Subscribe(stream Event) returns (stream Event);
62-
rpc Push(stream Event) returns (PushSummary);
63-
rpc Ping(PingRequest) returns (PongReply);
64-
}
65-
```
66-
6774
### Connection Lifecycle
6875

69-
1. **Authentication**: Agent presents JWT token with client certificate (optional)
76+
1. **Authentication**: Agent presents JWT token with transport-specific credentials
7077
2. **Authorization**: Principal validates agent identity and creates queue pair
71-
3. **Stream Establishment**: Bidirectional gRPC stream created
78+
3. **Stream Establishment**: Bidirectional event stream created using selected transport
7279
4. **Resync**: Initial synchronization based on agent mode
7380
5. **Event Processing**: Continuous bidirectional event exchange
7481
6. **Graceful Shutdown**: Connection cleanup and queue removal

docs/concepts/transport-abstraction.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ type Stream interface {
123123
```
124124

125125
### 2. Transport Factory
126+
CLI 로 --transport를 정할 때 함께 생성 됩니다.
127+
**현재 흐름:**
128+
1. Agent 시작 → gRPC 직접 연결 → 스트림 생성 → 이벤트 송수신
129+
130+
**변경 후 흐름:**
131+
1. Agent 시작 → Factory로 transport 선택 → 연결 → 스트림 생성 → 이벤트 송수신
132+
126133
```
127134
// pkg/api/eventstreamapi/factory.go
128135
func NewFactory() *Factory

docs/configuration/principal/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The recommended approach for production deployments is to use ConfigMap entries
2929
- **Command Line Flag**: `--listen-port`
3030
- **Environment Variable**: `ARGOCD_PRINCIPAL_LISTEN_PORT`
3131
- **ConfigMap Entry**: `principal.listen.port`
32-
- **Description**: Port the gRPC server will listen on
32+
- **Description**: Port the transport server will listen on
3333
- **Type**: Integer
3434
- **Default**: `8443`
3535
- **Range**: 1-65535
@@ -320,7 +320,7 @@ The recommended approach for production deployments is to use ConfigMap entries
320320
- **Command Line Flag**: `--enable-websocket`
321321
- **Environment Variable**: `ARGOCD_PRINCIPAL_ENABLE_WEBSOCKET`
322322
- **ConfigMap Entry**: *(Not available in ConfigMap)*
323-
- **Description**: Use gRPC over WebSocket to stream events to agents
323+
- **Description**: Transport protocol to use for agent communication
324324
- **Type**: Boolean
325325
- **Default**: `false`
326326
- **Example**: `"false"`

docs/features/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ argocd-agent transforms traditional multi-cluster Argo CD deployments by inverti
1919
**[Autonomous Mode](../concepts/agent-modes/autonomous.md)**: Applications are defined locally on workload clusters and synchronized back for observability. Perfect for edge deployments, air-gapped environments, or scenarios requiring local autonomy.
2020

2121
### Communication Protocol
22-
22+
# Fix)))
2323
**gRPC with CloudEvents**: Efficient bi-directional communication using industry-standard protocols. The connection model supports intermittent connectivity and automatic reconnection.
2424

2525
**mTLS Security**: All communication is secured with mutual TLS authentication. Agents authenticate to the principal using client certificates, eliminating the need for the control plane to store cluster credentials.

install/kubernetes/agent/agent-networkpolicy-redis.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@ spec:
1616
ports:
1717
- port: 6379
1818
protocol: TCP
19+
# DNS 쿼리 규칙 추가
20+
- to:
21+
- namespaceSelector:
22+
matchLabels:
23+
kubernetes.io/metadata.name: kube-system
24+
ports:
25+
- port: 53
26+
protocol: UDP
27+
- port: 53
28+
protocol: TCP
1929

install/kubernetes/argo-cd/agent-managed/kustomization.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
namespace: argocd
2+
13
resources:
24
- https://github.com/argoproj/argo-cd/manifests/cluster-install?ref=stable
35

@@ -184,3 +186,15 @@ patches:
184186
kind: ClusterRoleBinding
185187
metadata:
186188
name: argocd-applicationset-controller
189+
- target:
190+
group: networking.k8s.io
191+
version: v1
192+
kind: NetworkPolicy
193+
name: argocd-redis-network-policy
194+
patch: |-
195+
- op: add
196+
path: /spec/ingress/0/from/-
197+
value:
198+
podSelector:
199+
matchLabels:
200+
app.kubernetes.io/name: argocd-agent-agent

0 commit comments

Comments
 (0)