Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions enforcer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,41 @@ The webhook uses `failurePolicy: Ignore` by default, meaning if the webhook fail
helm repo add robusta https://robusta-charts.storage.googleapis.com && helm repo update
```

2. **Add cluster configuration**:
2. **Configure Robusta Account Connection**:

If the enforcer is installed in the same namespace as Robusta, it will automatically detect the Robusta account settings.
The `Enforcer` needs access to your Robusta account to fetch KRR recommendations. Choose the appropriate configuration based on your setup:

If your Robusta UI sink token, is pulled from a secret (as described [here](https://docs.robusta.dev/master/setup-robusta/configuration-secrets.html#pulling-values-from-kubernetes-secrets)), you should add the same environement variable to the `Enforcer` pod as well.
#### Option A: Same Namespace as Robusta (Easiest)
If the enforcer is installed in the **same namespace as Robusta**, it will automatically detect Robusta account settings from the existing configuration.

If the `Enforcer` is installed on a different namespace, you can provide your Robusta account credentials using env variables:
**⚠️ Caveat**: If your Robusta UI token is pulled from a secret (as described [here](https://docs.robusta.dev/master/setup-robusta/configuration-secrets.html#pulling-values-from-kubernetes-secrets)), you must add the same environment variables to the enforcer pod:

Add your robusta credentials and cluster name: (`enforcer-values.yaml`)
```yaml
# enforcer-values.yaml
additionalEnvVars:
- name: TOKEN_ENV_VAR_NAME
valueFrom:
secretKeyRef:
name: robusta-secrets
key: robustaSinkToken
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refine Option A example to match actual env var names
The placeholder TOKEN_ENV_VAR_NAME may be confusing. Replace it with the concrete variable your deployment uses (e.g., ROBUSTA_UI_TOKEN or STORE_API_KEY) to ensure consistency between docs and code.

🤖 Prompt for AI Agents
In enforcer/README.md around lines 71 to 79, the example uses a placeholder
environment variable name TOKEN_ENV_VAR_NAME, which can be confusing. Replace
TOKEN_ENV_VAR_NAME with a concrete environment variable name that matches your
actual deployment, such as ROBUSTA_UI_TOKEN or STORE_API_KEY, to ensure the
documentation aligns with real usage and avoids ambiguity.


#### Option B: Different Namespace
If the enforcer is installed in a **different namespace than Robusta**, provide the Robusta credentials explicitly:

```yaml
# enforcer-values.yaml
additionalEnvVars:
- name: CLUSTER_NAME
value: my-cluster-name # should be the same as the robusta installation on this cluster
value: my-cluster-name # should match your Robusta cluster name
- name: ROBUSTA_UI_TOKEN
value: "MY ROBUSTA UI TOKEN"
# - name: ROBUSTA_UI_TOKEN # or pulled from a secret
# valueFrom:
# secretKeyRef:
# name: robusta-secrets
# key: robustaSinkToken
value: "MY_ROBUSTA_UI_TOKEN"
# OR pull from a secret:
# - name: ROBUSTA_UI_TOKEN
# valueFrom:
# secretKeyRef:
# name: robusta-secrets
# key: robustaSinkToken
Comment on lines +76 to +87
Copy link

@coderabbitai coderabbitai bot Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct environment variable names in Option B
Docs reference CLUSTER_NAME and ROBUSTA_UI_TOKEN, but the code reads ROBUSTA_ACCOUNT_ID and STORE_* variables. Confirm and align these names to avoid runtime mismatches.

🤖 Prompt for AI Agents
In enforcer/README.md between lines 85 and 96, the environment variable names in
the documentation do not match those used in the code, causing potential runtime
mismatches. Review the code to identify the exact environment variable names it
expects, such as `ROBUSTA_ACCOUNT_ID` and `STORE_*`, then update the README to
use these exact names instead of `CLUSTER_NAME` and `ROBUSTA_UI_TOKEN`. Ensure
the documentation and code use consistent environment variable names to prevent
confusion and errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arikalon1 I assume this is wrong?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

```

2. **Install with default settings**:
Expand Down
2 changes: 1 addition & 1 deletion enforcer/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
UPDATE_THRESHOLD = float(os.environ.get("UPDATE_THRESHOLD", 20.0))

SCAN_RELOAD_INTERVAL = int(os.environ.get("SCAN_RELOAD_INTERVAL", 3600))
KRR_MUTATION_MODE_DEFAULT = os.environ.get("KRR_MUTATION_MODE_DEFAULT", "enforce")
KRR_MUTATION_MODE_DEFAULT = os.environ.get("KRR_MUTATION_MODE_DEFAULT", "ignore")
REPLICA_SET_CLEANUP_INTERVAL = int(os.environ.get("REPLICA_SET_CLEANUP_INTERVAL", 600))
REPLICA_SET_DELETION_WAIT = int(os.environ.get("REPLICA_SET_DELETION_WAIT", 600))
SCAN_AGE_HOURS_THRESHOLD = int(os.environ.get("SCAN_AGE_HOURS_THRESHOLD", 360)) # 15 days
Expand Down
4 changes: 2 additions & 2 deletions helm/krr-enforcer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: krr-enforcer
description: KRR enforcer - auto apply KRR recommendations
type: application

version: 0.3.1
appVersion: 0.3.1
version: 0.3.2
appVersion: 0.3.2
9 changes: 0 additions & 9 deletions helm/krr-enforcer/templates/enforcer-cert-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ spec:
values: ["kube-system"]
EOF

# Restart the enforcer deployment to pick up new certificates (only if it exists)
echo "Checking if enforcer deployment exists..."
if kubectl get deployment ${SERVICE_NAME} -n ${NAMESPACE} >/dev/null 2>&1; then
echo "Restarting enforcer deployment..."
kubectl rollout restart deployment ${SERVICE_NAME} -n ${NAMESPACE}
else
echo "Deployment ${SERVICE_NAME} does not exist yet, skipping restart"
fi

echo "Job completed successfully!"
---
apiVersion: v1
Expand Down
5 changes: 5 additions & 0 deletions helm/krr-enforcer/templates/enforcer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
app.kubernetes.io/component: krr-enforcer
annotations:
admission.robusta.dev/krr-mutation-mode: ignore
checksum/cert: {{ .Release.Revision | toString | sha256sum }}
{{- with .Values.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -118,6 +119,10 @@ spec:
value: "/etc/webhook/certs/tls.crt"
- name: LOG_LEVEL
value: {{ .Values.logLevel | quote }}
- name: KRR_MUTATION_MODE_DEFAULT
value: {{ .Values.mutationMode | quote }}
- name: UPDATE_THRESHOLD
value: {{ .Values.updateThreshold | quote }}
{{- if .Values.certificate }}
- name: CERTIFICATE
value: {{ .Values.certificate | quote }}
Expand Down
6 changes: 5 additions & 1 deletion helm/krr-enforcer/values.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
certificate: "" # base64 encoded
logLevel: INFO

# Enforcer configuration
mutationMode: ignore # enforce or ignore - default global enforcement mode
updateThreshold: 20.0 # percentage threshold for applying resource updates

# fullImage: ~ # full image path can be used to override image.repository/image.name:image.tag

image:
repository: us-central1-docker.pkg.dev/genuine-flight-317411/devel
name: krr-enforcer
tag: 0.3.1
tag: 0.3.2
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down