Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to ignore all volumes that are not annotated #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ verbose: "false"
victoriametrics_mode: "false"
# Auth header for mimir or cortex
scope_orgid_auth_header: ""
# Ignore non annotated pvcs
ignore_unless_annotated: "false"


# Pretty much ignore anything below here I'd say, unless you really know what you're doing. :)
Expand Down Expand Up @@ -124,6 +126,10 @@ globalEnvs:
- name: SCOPE_ORGID_AUTH_HEADER
value: "{{ .Values.scope_orgid_auth_header }}"

# Ignore volumes that are not annotated with volume.autoscaler.kubernetes.io/ignore: "false"
- name: IGNORE_UNLESS_ANNOTATED
value: "{{ .Values.ignore_unless_annotated }}"


# Additional pod annotations
podAnnotations: {}
Expand Down
9 changes: 7 additions & 2 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def detectPrometheusURL():
VERBOSE = True if getenv('VERBOSE', "false").lower() == "true" else False # If we want to verbose mode
VICTORIAMETRICS_COMPAT = True if getenv('VICTORIAMETRICS_MODE', "false").lower() == "true" else False # Whether to skip the prometheus check and assume victoriametrics
SCOPE_ORGID_AUTH_HEADER = getenv('SCOPE_ORGID_AUTH_HEADER') or '' # If we want to use Mimir or AgentMode which requires an orgid header. See: https://grafana.com/docs/mimir/latest/references/http-api/#authentication
IGNORE_UNLESS_ANNOTATED = True if getenv('IGNORE_UNLESS_ANNOTATED', "false").lower() == "true" else False # ignore non annotated PVC's



# Simple helper to pass back
Expand Down Expand Up @@ -151,6 +153,7 @@ def printHeaderAndConfiguration():
print(" VictoriaMetrics mode: {}".format("ENABLED" if VICTORIAMETRICS_COMPAT else "disabled"))
print("X-Scope-OrgID Header for Cortex: {}".format(SCOPE_ORGID_AUTH_HEADER if len(SCOPE_ORGID_AUTH_HEADER) else "disabled"))
print(" Sending notifications to Slack: {}".format("ENABLED" if len(slack.SLACK_WEBHOOK_URL) > 0 else "disabled"))
print(" Ignore non annotated pvcs: {}".format("ENABLED" if IGNORE_UNLESS_ANNOTATED else "disabled"))
if len(slack.SLACK_WEBHOOK_URL) > 0:
print(" Slack channel: {}".format(slack.SLACK_CHANNEL))
print(" Slack message prefix: {}".format(slack.SLACK_MESSAGE_PREFIX))
Expand Down Expand Up @@ -349,7 +352,7 @@ def convert_pvc_to_simpler_dict(pvc):
return_dict['scale_up_max_increment'] = SCALE_UP_MAX_INCREMENT
return_dict['scale_up_max_size'] = SCALE_UP_MAX_SIZE
return_dict['scale_cooldown_time'] = SCALE_COOLDOWN_TIME
return_dict['ignore'] = False
return_dict['ignore'] = IGNORE_UNLESS_ANNOTATED

# Override defaults with annotations on the PVC
try:
Expand Down Expand Up @@ -401,7 +404,9 @@ def convert_pvc_to_simpler_dict(pvc):
print("Could not convert scale_cooldown_time to int: {}".format(e))

try:
if 'volume.autoscaler.kubernetes.io/ignore' in pvc.metadata.annotations and pvc.metadata.annotations['volume.autoscaler.kubernetes.io/ignore'].lower() == "true":
if 'volume.autoscaler.kubernetes.io/ignore' in pvc.metadata.annotations and pvc.metadata.annotations['volume.autoscaler.kubernetes.io/ignore'].lower() == "false" and IGNORE_UNLESS_ANNOTATED:
return_dict['ignore'] = False
else if 'volume.autoscaler.kubernetes.io/ignore' in pvc.metadata.annotations and pvc.metadata.annotations['volume.autoscaler.kubernetes.io/ignore'].lower() == "true" and not IGNORE_UNLESS_ANNOTATED:
return_dict['ignore'] = True
except Exception as e:
print("Could not convert ignore to bool: {}".format(e))
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

# Check if we set on this PV we want to ignore the volume autoscaler
if pvcs_in_kubernetes[volume_description]['ignore']:
print(" IGNORING scaling this because the ignore annotation was set to true")
print(" IGNORING scaling this because the ignore annotation was set to true or ignore_unless_annotated is set to true and pvc does not have ignore=false")
print("=============================================================================================================")
continue

Expand Down