|
| 1 | +# Stack Concurrency Configuration |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Control the number of Stack reconciliations that run in parallel to prevent cluster overload. |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +### Via Helm Values |
| 10 | + |
| 11 | +Edit your `values.yaml` or use `--set`: |
| 12 | + |
| 13 | +```yaml |
| 14 | +operator: |
| 15 | + stackMaxConcurrent: 5 # Max 5 concurrent stack reconciliations |
| 16 | +``` |
| 17 | +
|
| 18 | +Or with Helm command: |
| 19 | +
|
| 20 | +```bash |
| 21 | +helm install operator ./helm/operator \ |
| 22 | + --set operator.stackMaxConcurrent=5 |
| 23 | +``` |
| 24 | + |
| 25 | +### Default Behavior |
| 26 | + |
| 27 | +- **Default value: `5`** (good balance for most clusters) |
| 28 | +- Set to `0` to disable the limit (unlimited concurrency) |
| 29 | + |
| 30 | +## Recommended Values |
| 31 | + |
| 32 | +| Cluster Size | Stacks | CPU | Recommended Value | |
| 33 | +|-------------|--------|-----|-------------------| |
| 34 | +| Small | 1-10 | 2-4 CPU | `2-3` | |
| 35 | +| Medium | 10-30 | 4-8 CPU | `5` | |
| 36 | +| Large | 30-100 | 8-16 CPU | `10` | |
| 37 | +| XL | 100+ | 16+ CPU | `20` | |
| 38 | + |
| 39 | +## Examples |
| 40 | + |
| 41 | +### Example 1: Small Cluster |
| 42 | + |
| 43 | +```yaml |
| 44 | +# values.yaml |
| 45 | +operator: |
| 46 | + stackMaxConcurrent: 3 |
| 47 | +``` |
| 48 | +
|
| 49 | +```bash |
| 50 | +helm upgrade operator ./helm/operator -f values.yaml |
| 51 | +``` |
| 52 | + |
| 53 | +### Example 2: Production Cluster |
| 54 | + |
| 55 | +```yaml |
| 56 | +# values-prod.yaml |
| 57 | +operator: |
| 58 | + stackMaxConcurrent: 10 |
| 59 | + enableLeaderElection: true |
| 60 | + region: "eu-west-1" |
| 61 | + env: "production" |
| 62 | +``` |
| 63 | +
|
| 64 | +```bash |
| 65 | +helm upgrade operator ./helm/operator -f values-prod.yaml |
| 66 | +``` |
| 67 | + |
| 68 | +### Example 3: Override with --set |
| 69 | + |
| 70 | +```bash |
| 71 | +helm upgrade operator ./helm/operator \ |
| 72 | + --set operator.stackMaxConcurrent=5 \ |
| 73 | + --set operator.region=us-east-1 |
| 74 | +``` |
| 75 | + |
| 76 | +## How It Works |
| 77 | + |
| 78 | +1. The Helm chart sets the `STACK_MAX_CONCURRENT` environment variable |
| 79 | +2. The operator reads this value on startup |
| 80 | +3. Stack reconciliations are limited to N concurrent executions |
| 81 | +4. Additional stacks are queued automatically by Kubernetes |
| 82 | + |
| 83 | +### Behavior |
| 84 | + |
| 85 | +**Without limit (default):** |
| 86 | +``` |
| 87 | +Stack A ──┐ |
| 88 | +Stack B ──┤ |
| 89 | +Stack C ──┼─> All processed in parallel |
| 90 | +Stack D ──┤ |
| 91 | +Stack E ──┘ |
| 92 | +``` |
| 93 | + |
| 94 | +**With limit of 5:** |
| 95 | +``` |
| 96 | +Stack A ──┐ |
| 97 | +Stack B ──┤ |
| 98 | +Stack C ──┼─> Max 5 in parallel |
| 99 | +Stack D ──┤ |
| 100 | +Stack E ──┘ |
| 101 | +Stack F ──> Queued (waiting) |
| 102 | +Stack G ──> Queued (waiting) |
| 103 | +``` |
| 104 | + |
| 105 | +## Verification |
| 106 | + |
| 107 | +Check if the environment variable is set: |
| 108 | + |
| 109 | +```bash |
| 110 | +# Get the pod name |
| 111 | +POD=$(kubectl get pods -n formance-system -l control-plane=formance-controller-manager -o jsonpath='{.items[0].metadata.name}') |
| 112 | + |
| 113 | +# Check environment variables |
| 114 | +kubectl exec -n formance-system $POD -- env | grep STACK_MAX_CONCURRENT |
| 115 | +``` |
| 116 | + |
| 117 | +Expected output: |
| 118 | +``` |
| 119 | +STACK_MAX_CONCURRENT=5 |
| 120 | +``` |
| 121 | + |
| 122 | +## Troubleshooting |
| 123 | + |
| 124 | +### Value not applied |
| 125 | + |
| 126 | +1. **Check Helm values:** |
| 127 | + ```bash |
| 128 | + helm get values operator -n formance-system |
| 129 | + ``` |
| 130 | + |
| 131 | +2. **Verify deployment:** |
| 132 | + ```bash |
| 133 | + kubectl get deployment operator-manager -n formance-system -o yaml | grep -A 2 "STACK_MAX_CONCURRENT" |
| 134 | + ``` |
| 135 | + |
| 136 | +3. **Restart pods to apply changes:** |
| 137 | + ```bash |
| 138 | + kubectl rollout restart deployment operator-manager -n formance-system |
| 139 | + ``` |
| 140 | + |
| 141 | +### Performance Issues |
| 142 | + |
| 143 | +**Too many concurrent reconciliations:** |
| 144 | +- Symptoms: High CPU/memory, slow reconciliations |
| 145 | +- Solution: Lower the value (e.g., from 10 to 5) |
| 146 | + |
| 147 | +**Too few concurrent reconciliations:** |
| 148 | +- Symptoms: Long queue times, slow stack deployments |
| 149 | +- Solution: Increase the value (e.g., from 5 to 10) |
| 150 | + |
| 151 | +## Monitoring |
| 152 | + |
| 153 | +### Check current stack status |
| 154 | + |
| 155 | +```bash |
| 156 | +# Total stacks |
| 157 | +kubectl get stacks --all-namespaces --no-headers | wc -l |
| 158 | + |
| 159 | +# Ready stacks |
| 160 | +kubectl get stacks --all-namespaces -o json | jq '[.items[] | select(.status.ready==true)] | length' |
| 161 | + |
| 162 | +# Not ready stacks (in queue or processing) |
| 163 | +kubectl get stacks --all-namespaces -o json | jq '[.items[] | select(.status.ready==false)] | length' |
| 164 | +``` |
| 165 | + |
| 166 | +### Operator logs |
| 167 | + |
| 168 | +```bash |
| 169 | +kubectl logs -n formance-system -l control-plane=formance-controller-manager -f |
| 170 | +``` |
| 171 | + |
| 172 | +## Advanced Usage |
| 173 | + |
| 174 | +### Environment-specific values |
| 175 | + |
| 176 | +```yaml |
| 177 | +# values-dev.yaml |
| 178 | +operator: |
| 179 | + stackMaxConcurrent: 2 |
| 180 | + env: "dev" |
| 181 | + |
| 182 | +# values-staging.yaml |
| 183 | +operator: |
| 184 | + stackMaxConcurrent: 5 |
| 185 | + env: "staging" |
| 186 | + |
| 187 | +# values-prod.yaml |
| 188 | +operator: |
| 189 | + stackMaxConcurrent: 10 |
| 190 | + env: "production" |
| 191 | +``` |
| 192 | +
|
| 193 | +Deploy: |
| 194 | +```bash |
| 195 | +helm upgrade operator ./helm/operator -f values-prod.yaml |
| 196 | +``` |
| 197 | + |
| 198 | +### ArgoCD / GitOps |
| 199 | + |
| 200 | +```yaml |
| 201 | +# argocd-application.yaml |
| 202 | +apiVersion: argoproj.io/v1alpha1 |
| 203 | +kind: Application |
| 204 | +metadata: |
| 205 | + name: formance-operator |
| 206 | +spec: |
| 207 | + source: |
| 208 | + helm: |
| 209 | + values: | |
| 210 | + operator: |
| 211 | + stackMaxConcurrent: 5 |
| 212 | + region: "eu-west-1" |
| 213 | + env: "production" |
| 214 | +``` |
| 215 | +
|
| 216 | +## Technical Details |
| 217 | +
|
| 218 | +### Implementation |
| 219 | +
|
| 220 | +- **Environment Variable:** `STACK_MAX_CONCURRENT` |
| 221 | +- **Read by:** `internal/resources/stacks/config.go::GetStackConcurrency()` |
| 222 | +- **Applied in:** `internal/resources/stacks/init.go` |
| 223 | +- **Uses:** Native controller-runtime `MaxConcurrentReconciles` |
| 224 | + |
| 225 | +### Source Code |
| 226 | + |
| 227 | +```go |
| 228 | +// internal/resources/stacks/config.go |
| 229 | +func GetStackConcurrency() int { |
| 230 | + if v := os.Getenv("STACK_MAX_CONCURRENT"); v != "" { |
| 231 | + if n, err := strconv.Atoi(v); err == nil && n > 0 { |
| 232 | + return n |
| 233 | + } |
| 234 | + } |
| 235 | + return 0 // Default: unlimited |
| 236 | +} |
| 237 | +``` |
| 238 | + |
| 239 | +## Related Documentation |
| 240 | + |
| 241 | +- [How to Limit Concurrent Stacks](../../docs/HOW_TO_LIMIT_CONCURRENT_STACKS.md) |
| 242 | +- [Concurrent Limit Implementation](../../CONCURRENT_LIMIT_IMPLEMENTATION.md) |
0 commit comments