Skip to content

Commit 4c0648d

Browse files
committed
🎨 Add watch all ns
1 parent 01681a4 commit 4c0648d

File tree

8 files changed

+357
-22
lines changed

8 files changed

+357
-22
lines changed

DEPLOYMENT.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,45 @@ curl http://localhost:3000/health
153153
| `SLACK_TOKEN` | Slack bot token | Required |
154154
| `SLACK_DEFAULT_CHANNEL` | Default Slack channel | `#general` |
155155
| `SLACK_RATE_LIMIT` | Rate limit in ms | `1000` |
156-
| `K8S_NAMESPACES` | Comma-separated namespaces to watch | All namespaces |
156+
| `K8S_WATCH_ALL_NAMESPACES` | Watch all namespaces (true/false) | `true` |
157+
| `K8S_NAMESPACES` | Comma-separated namespaces to watch | All namespaces (when K8S_WATCH_ALL_NAMESPACES=true) |
157158
| `LOG_LEVEL` | Logging level | `info` |
158159
| `PORT` | HTTP server port | `3000` |
159160

161+
### Namespace Configuration
162+
163+
Slaking supports two modes for watching Kubernetes namespaces:
164+
165+
#### Watch All Namespaces (Default)
166+
By default, Slaking watches all namespaces in your cluster. This is the recommended configuration for most use cases.
167+
168+
```bash
169+
# Environment configuration
170+
K8S_WATCH_ALL_NAMESPACES=true
171+
# K8S_NAMESPACES can be left empty or unset
172+
```
173+
174+
**Benefits:**
175+
- Automatically picks up new namespaces
176+
- No need to maintain a list of namespaces
177+
- Works with any workload regardless of namespace
178+
- Simpler configuration
179+
180+
#### Watch Specific Namespaces Only
181+
For environments where you want to limit Slaking's scope to specific namespaces.
182+
183+
```bash
184+
# Environment configuration
185+
K8S_WATCH_ALL_NAMESPACES=false
186+
K8S_NAMESPACES=production,staging,monitoring
187+
```
188+
189+
**Use Cases:**
190+
- Multi-tenant clusters with namespace isolation
191+
- Performance optimization for large clusters
192+
- Security requirements limiting cross-namespace access
193+
- Testing in specific environments only
194+
160195
### Workload Annotations
161196

162197
Add these annotations to your Kubernetes workloads:

README.md

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> *"The laziest Pokémon that monitors your Kubernetes workloads while you take a nap!"*
44
5-
![Slaking Pokémon](https://www.pokemon.com/static-assets/content-assets/cms2/img/pokedex/full/289.png)
5+
<img src="https://www.pokemon.com/static-assets/content-assets/cms2/img/pokedex/full/289.png" alt="Slaking Pokémon" width="200" height="200">
66

77
```
88
╭─────────────────────────────────────────────────────────────╮
@@ -67,30 +67,45 @@ Before installing from the Helm repository, ensure the GitHub Pages repository i
6767

6868
The easiest way to deploy Slaking is using the provided Helm chart from the GitHub Pages repository:
6969

70+
#### Watch All Namespaces (Recommended)
7071
```bash
7172
# Add the Helm repository
7273
helm repo add slaking https://elementtech.github.io/slaking
7374
helm repo update
7475

75-
# Install the chart - Wake up Slaking!
76+
# Install the chart - Wake up Slaking to watch ALL namespaces!
7677
helm install slaking slaking/slaking \
7778
--namespace slaking \
7879
--create-namespace \
7980
--set env.SLACK_TOKEN="xoxb-your-token" \
80-
--set env.SLACK_DEFAULT_CHANNEL="#alerts"
81+
--set env.SLACK_DEFAULT_CHANNEL="#alerts" \
82+
--set env.K8S_WATCH_ALL_NAMESPACES="true"
83+
```
84+
85+
#### Watch Specific Namespaces Only
86+
```bash
87+
# Install the chart to watch specific namespaces only
88+
helm install slaking slaking/slaking \
89+
--namespace slaking \
90+
--create-namespace \
91+
--set env.SLACK_TOKEN="xoxb-your-token" \
92+
--set env.SLACK_DEFAULT_CHANNEL="#alerts" \
93+
--set env.K8S_WATCH_ALL_NAMESPACES="false" \
94+
--set env.K8S_NAMESPACES="production,staging,monitoring"
8195
```
8296

8397
**Alternative: Install from local chart directory (if you have the source code):**
8498
```bash
85-
# Quick deployment with automated script
99+
# Quick deployment with automated script (watches all namespaces by default)
86100
./helm-deploy.sh
87101

88102
# Manual Helm deployment from local chart
89103
helm install slaking ./charts/slaking \
90104
--namespace slaking \
91105
--create-namespace \
92106
--set env.SLACK_TOKEN="xoxb-your-token" \
93-
--set env.SLACK_DEFAULT_CHANNEL="#alerts"
107+
--set env.SLACK_DEFAULT_CHANNEL="#alerts" \
108+
--set env.K8S_WATCH_ALL_NAMESPACES="true"
94109
```
95110

96111
**Benefits of Helm deployment:**
@@ -144,6 +159,55 @@ metadata:
144159
| `slaking.max-lines` | Maximum lines per message | `10` |
145160
| `slaking.cooldown` | Cooldown period between messages (seconds) | `60` |
146161

162+
### Namespace Configuration
163+
164+
Slaking supports two modes for watching Kubernetes namespaces:
165+
166+
#### 🦥 Watch All Namespaces (Recommended)
167+
This is the default and recommended configuration. Slaking will monitor all namespaces in your cluster and only process logs from workloads that have the `slaking.enabled: "true"` annotation.
168+
169+
**Environment Configuration:**
170+
```bash
171+
# Set to watch all namespaces
172+
K8S_WATCH_ALL_NAMESPACES=true
173+
# Leave K8S_NAMESPACES empty or unset
174+
```
175+
176+
**Helm Configuration:**
177+
```bash
178+
helm install slaking slaking/slaking \
179+
--set env.K8S_WATCH_ALL_NAMESPACES="true"
180+
```
181+
182+
**Benefits:**
183+
- ✅ No need to specify namespaces manually
184+
- ✅ Automatically picks up new namespaces
185+
- ✅ Works with any workload regardless of namespace
186+
- ✅ Simpler configuration and maintenance
187+
188+
#### 🎯 Watch Specific Namespaces Only
189+
For environments where you want to limit Slaking's scope to specific namespaces (e.g., for security or performance reasons).
190+
191+
**Environment Configuration:**
192+
```bash
193+
# Disable watching all namespaces
194+
K8S_WATCH_ALL_NAMESPACES=false
195+
# Specify namespaces to watch
196+
K8S_NAMESPACES=production,staging,monitoring
197+
```
198+
199+
**Helm Configuration:**
200+
```bash
201+
helm install slaking slaking/slaking \
202+
--set env.K8S_WATCH_ALL_NAMESPACES="false" \
203+
--set env.K8S_NAMESPACES="production,staging,monitoring"
204+
```
205+
206+
**Use Cases:**
207+
- 🔒 Multi-tenant clusters where you want to isolate monitoring
208+
- 🚀 Performance optimization for large clusters
209+
- 🛡️ Security requirements that limit cross-namespace access
210+
147211
## 🎮 Installation
148212

149213
### Prerequisites
@@ -163,11 +227,13 @@ metadata:
163227
helm repo update
164228

165229
# Install with your Slack configuration - Time to wake up Slaking!
230+
# This will watch ALL namespaces by default
166231
helm install slaking slaking/slaking \
167232
--namespace slaking \
168233
--create-namespace \
169234
--set env.SLACK_TOKEN="xoxb-your-token" \
170-
--set env.SLACK_DEFAULT_CHANNEL="#alerts"
235+
--set env.SLACK_DEFAULT_CHANNEL="#alerts" \
236+
--set env.K8S_WATCH_ALL_NAMESPACES="true"
171237
```
172238

173239
2. **Alternative: Local development setup:**
@@ -180,6 +246,7 @@ metadata:
180246
# Set up environment variables
181247
cp env.example .env
182248
# Edit .env with your Slack token and other settings
249+
# By default, it will watch all namespaces
183250

184251
# Deploy using automated script
185252
./helm-deploy.sh
@@ -196,9 +263,22 @@ helm repo update
196263
# Check available versions
197264
helm search repo slaking/slaking
198265

199-
# Upgrade to latest version
266+
# Upgrade to latest version (maintains current namespace configuration)
267+
helm upgrade slaking slaking/slaking \
268+
--namespace slaking \
269+
--reuse-values
270+
271+
# Upgrade and change to watch all namespaces
272+
helm upgrade slaking slaking/slaking \
273+
--namespace slaking \
274+
--set env.K8S_WATCH_ALL_NAMESPACES="true" \
275+
--reuse-values
276+
277+
# Upgrade and change to watch specific namespaces only
200278
helm upgrade slaking slaking/slaking \
201279
--namespace slaking \
280+
--set env.K8S_WATCH_ALL_NAMESPACES="false" \
281+
--set env.K8S_NAMESPACES="production,staging" \
202282
--reuse-values
203283

204284
# Or upgrade to a specific version
@@ -234,7 +314,7 @@ npm run build
234314
- `GET /metrics` - Prometheus metrics (Slaking's stats)
235315
- `POST /config` - Update configuration
236316
- `GET /config` - Get current configuration
237-
- `GET /status` - Service status
317+
- `GET /status` - Service status (includes namespace configuration)
238318

239319
## 📊 Monitoring
240320

@@ -280,7 +360,16 @@ config:
280360
slack:
281361
defaultChannel: "#prod-alerts"
282362
kubernetes:
283-
namespaces: ["production", "staging"]
363+
# Watch all namespaces (recommended)
364+
watchAllNamespaces: true
365+
namespaces: []
366+
# OR watch specific namespaces only
367+
# watchAllNamespaces: false
368+
# namespaces: ["production", "staging"]
369+
env:
370+
SLACK_TOKEN: "xoxb-your-token"
371+
K8S_WATCH_ALL_NAMESPACES: "true"
372+
# K8S_NAMESPACES: "production,staging" # Only needed if watchAllNamespaces: false
284373
```
285374

286375
### Multi-Environment Setup

charts/slaking/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,35 @@ env:
113113
| `SLACK_TOKEN` | Slack bot token | Required |
114114
| `SLACK_DEFAULT_CHANNEL` | Default Slack channel | `#general` |
115115
| `SLACK_RATE_LIMIT` | Rate limit in ms | `1000` |
116-
| `K8S_NAMESPACES` | Comma-separated namespaces | All namespaces |
116+
| `K8S_WATCH_ALL_NAMESPACES` | Watch all namespaces (true/false) | `true` |
117+
| `K8S_NAMESPACES` | Comma-separated namespaces | All namespaces (when K8S_WATCH_ALL_NAMESPACES=true) |
117118
| `K8S_WATCH_INTERVAL` | Watch interval in ms | `30000` |
118119
| `LOG_LEVEL` | Logging level | `info` |
119120
| `METRICS_PORT` | Metrics port | `9090` |
120121
| `PORT` | HTTP port | `3000` |
121122
| `NODE_ENV` | Environment | `production` |
122123

124+
### Namespace Configuration
125+
126+
The chart supports two modes for watching Kubernetes namespaces:
127+
128+
#### Watch All Namespaces (Default)
129+
By default, the chart watches all namespaces in your cluster:
130+
131+
```bash
132+
helm install slaking ./ \
133+
--set env.K8S_WATCH_ALL_NAMESPACES="true"
134+
```
135+
136+
#### Watch Specific Namespaces Only
137+
To limit monitoring to specific namespaces:
138+
139+
```bash
140+
helm install slaking ./ \
141+
--set env.K8S_WATCH_ALL_NAMESPACES="false" \
142+
--set env.K8S_NAMESPACES="production,staging,monitoring"
143+
```
144+
123145
### Advanced Configuration
124146

125147
#### Horizontal Pod Autoscaler
@@ -236,7 +258,10 @@ config:
236258
slack:
237259
defaultChannel: "#prod-alerts"
238260
kubernetes:
239-
namespaces: ["production", "staging"]
261+
watchAllNamespaces: true
262+
namespaces: []
263+
env:
264+
K8S_WATCH_ALL_NAMESPACES: "true"
240265
```
241266

242267
**values-staging.yaml:**
@@ -249,7 +274,11 @@ config:
249274
slack:
250275
defaultChannel: "#staging-alerts"
251276
kubernetes:
277+
watchAllNamespaces: false
252278
namespaces: ["staging"]
279+
env:
280+
K8S_WATCH_ALL_NAMESPACES: "false"
281+
K8S_NAMESPACES: "staging"
253282
```
254283

255284
**values-development.yaml:**
@@ -261,9 +290,13 @@ config:
261290
slack:
262291
defaultChannel: "#dev-logs"
263292
kubernetes:
293+
watchAllNamespaces: false
264294
namespaces: ["development"]
265295
logging:
266296
level: "debug"
297+
env:
298+
K8S_WATCH_ALL_NAMESPACES: "false"
299+
K8S_NAMESPACES: "development"
267300
```
268301

269302
## Upgrading

charts/slaking/values.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ config:
105105
retryDelay: 5000
106106
kubernetes:
107107
namespaces: []
108+
watchAllNamespaces: true
108109
watchInterval: 30000
109110
logBufferSize: 100
110111
maxLogLines: 10
@@ -137,13 +138,14 @@ config:
137138

138139
# Environment variables
139140
env:
140-
SLACK_TOKEN: ""
141-
SLACK_DEFAULT_CHANNEL: ""
142-
SLACK_RATE_LIMIT: ""
143-
K8S_NAMESPACES: ""
144-
K8S_WATCH_INTERVAL: ""
145-
LOG_LEVEL: ""
146-
METRICS_PORT: ""
141+
# SLACK_TOKEN: ""
142+
# SLACK_DEFAULT_CHANNEL: ""
143+
# SLACK_RATE_LIMIT: ""
144+
# K8S_NAMESPACES: ""
145+
# K8S_WATCH_ALL_NAMESPACES: "true"
146+
# K8S_WATCH_INTERVAL: ""
147+
# LOG_LEVEL: ""
148+
# METRICS_PORT: ""
147149
PORT: "3000"
148150
NODE_ENV: "production"
149151
CONFIG_PATH: "/app/config/config.json"

env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ SLACK_DEFAULT_CHANNEL=#general
44
SLACK_RATE_LIMIT=1000
55

66
# Kubernetes Configuration
7-
K8S_NAMESPACES=default,production,staging
7+
# Option 1: Watch all namespaces (recommended for most use cases)
8+
K8S_WATCH_ALL_NAMESPACES=true
9+
# K8S_NAMESPACES= # Leave empty when watching all namespaces
10+
11+
# Option 2: Watch specific namespaces only
12+
# K8S_WATCH_ALL_NAMESPACES=false
13+
# K8S_NAMESPACES=default,production,staging
14+
815
K8S_WATCH_INTERVAL=30000
916

1017
# Logging Configuration

helm-deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ env:
104104
SLACK_DEFAULT_CHANNEL: "${SLACK_DEFAULT_CHANNEL:-#general}"
105105
SLACK_RATE_LIMIT: "${SLACK_RATE_LIMIT:-1000}"
106106
K8S_NAMESPACES: "${K8S_NAMESPACES:-}"
107+
K8S_WATCH_ALL_NAMESPACES: "${K8S_WATCH_ALL_NAMESPACES:-true}"
107108
K8S_WATCH_INTERVAL: "${K8S_WATCH_INTERVAL:-30000}"
108109
LOG_LEVEL: "${LOG_LEVEL:-info}"
109110
METRICS_PORT: "${METRICS_PORT:-9090}"
@@ -122,6 +123,7 @@ config:
122123
rateLimit: ${SLACK_RATE_LIMIT:-1000}
123124
kubernetes:
124125
namespaces: ${K8S_NAMESPACES:-[]}
126+
watchAllNamespaces: ${K8S_WATCH_ALL_NAMESPACES:-true}
125127
watchInterval: ${K8S_WATCH_INTERVAL:-30000}
126128
logging:
127129
level: "${LOG_LEVEL:-info}"

0 commit comments

Comments
 (0)