Why does Helm Charts interpret 0777 as 511?
It took me quite some time to debug it.
In my values.yaml file, I had a variable called customScriptDefaultMode, which was set to 0777.
File: values.yaml
customScriptDefaultMode: 0777
customScripts:
hello.sh: |
#!/bin/bash
echo hello world
Then, in my templates, I tried to use that value for the defaultMode of a volume. Here's the code:
File: templates/deployment.yaml
{{- if .Values.customScripts }}
- name: custom-scripts
configMap:
name: {{ include "airflow.fullname" . }}-custom-scripts
defaultMode: {{ .Values.customScriptDefaultMode }}
{{- end }}
When I ran helm template . to render the template, I expected to see 0777. However, what I got was 511. Here's the relevant part of the output:
---
volumes:
- name: airflow-config
configMap:
name: airflow
- name: custom-scripts
configMap:
name: airflow-custom-scripts
defaultMode: 511
My expectation was:
---
volumes:
- name: airflow-config
configMap:
name: airflow
- name: custom-scripts
configMap:
name: airflow-custom-scripts
defaultMode: 0777
Naturally, I was confused and frustrated. I searched the internet for an explanation and found a Stack Overflow post that shed some light on the issue. According to one of the answers, if an argument is a string and starts with "0x", "0b", or "0", it is interpreted as a hexadecimal, binary, or octal string, respectively.
So, in my case, "0777" is being treated as an octal string. And since "0777" in octal is equivalent to "511" in decimal, that's what we get.
But here's the catch: if we put 0777 in single quotes ('0777'), it will be treated as a string, not a number. And that can cause issues because the defaultMode in Kubernetes specs must be a number.
ValidationError(Deployment.spec.template.spec.volumes[1].configMap.defaultMode): invalid type for io.k8s.api.core.v1.ConfigMapVolumeSource.defaultMode: got "string", expected "integer"
So, the correct way to set the defaultMode in Helm templates is to use double quotes ("0777"). This way, it will be treated as a number, not a string 🤯.
# Wrong 🛑
customScriptDefaultMode: 0777
# Wrong 🛑
customScriptDefaultMode: '0777'
# Correct ✅
customScriptDefaultMode: "0777"
References
Related Posts
Spark on Kubernetes tại Fossil 🤔
Hành trình chuyển đổi Apache Spark từ AWS EMR sang Kubernetes tại Fossil Data Platform. Tìm hiểu kiến trúc hệ thống với Spark Operator, Spark Submit Worker, và Spark Jobs UI. Bài viết chia sẻ chi tiết về lý do migration, kiến trúc microservices, GitOps workflow, và các tối ưu hóa performance trên Kubernetes production environment.
Spark on Kubernetes - better handling for node shutdown
Spark 3.1 on the Kubernetes project is now officially declared as production-ready and Generally Available. Spot instances in Kubernetes can cut your bill by up to 70-80% if you are willing to trade in reliability. The new feature - SPIP: Add better handling for node shutdown (SPARK-20624) was implemented to deal with the problem of losing an executor when working with spot nodes - the need to recompute the shuffle or cached data.
ClickHouse Rust UDFs
In Data Platform System with ClickHouse, rather than extracting data from ClickHouse for processing in external systems, we can perform transformations directly within ClickHouse itself. ClickHouse can call any external executable program or script to process data. My idea is using custom **User-Defined Functions (UDFs) written in Rust** to handle data transformations between tables.
ReplicatedReplacingMergeTree
Learn how to set up and manage ReplicatedReplacingMergeTree in ClickHouse on Kubernetes. This comprehensive guide covers cluster setup with ClickHouse Operator, data replication, performance tuning, and best practices for high availability deployments.