Home Backend Development Golang Introducing Helm CEL: A More Expressive Way to Validate Your Helm Charts

Introducing Helm CEL: A More Expressive Way to Validate Your Helm Charts

Nov 22, 2024 pm 04:35 PM

Introducing Helm CEL: A More Expressive Way to Validate Your Helm Charts

If you've worked with Helm charts, you're probably familiar with the challenge of validating values.yaml. While Helm's built-in JSON Schema validation works, it can be cumbersome and limiting. Today, I want to introduce you to Helm CEL, a plugin that brings the power of Google's Common Expression Language (CEL) to Helm chart validation.

What is CEL?

Before diving in, let's quickly cover what CEL is. Common Expression Language (CEL) is a simple expression language created by Google that lets you write concise, powerful validation rules. It's used in Kubernetes CRD validation, Istio configuration, and many other projects in the cloud-native ecosystem.

Why Use CEL Instead of JSON Schema?

  1. More Expressive: CEL allows you to write complex validation rules in a more natural and readable way
  2. Familiar Syntax: If you're coming from programming languages like Python or JavaScript, CEL's syntax will feel natural
  3. Type-Safe: CEL provides strong type checking while remaining flexible
  4. Built for Cloud Native: CEL is already used throughout the Kubernetes ecosystem

Getting Started

First, install the plugin:

helm plugin install https://github.com/idsulik/helm-cel
Copy after login

Instead of creating a values.schema.json, you'll create a values.cel.yaml file in your chart directory. Here's a simple example:

rules:
  - expr: "has(values.service) && has(values.service.port)"
    desc: "service port is required"

  - expr: "values.service.port >= 1 && values.service.port <= 65535"
    desc: "service port must be between 1 and 65535"

  - expr: "!(has(values.replicaCount)) || values.replicaCount >= 1"
    desc: "if replicaCount is set, it must be at least 1"
Copy after login

To validate your chart:

helm cel ./mychart
Copy after login

Real-World Examples

Let's look at some common validation patterns and how they're expressed in both JSON Schema and CEL.

1. Required Fields

JSON Schema:

{
  "required": ["service"],
  "properties": {
    "service": {
      "required": ["port"],
      "properties": {
        "port": {
          "type": "integer"
        }
      }
    }
  }
}
Copy after login

CEL:

rules:
  - expr: "has(values.service) && has(values.service.port)"
    desc: "service port is required"
Copy after login

2. Conditional Requirements

JSON Schema:

{
  "if": {
    "properties": {
      "persistence": {
        "const": true
      }
    }
  },
  "then": {
    "required": ["storageClass"]
  }
}
Copy after login

CEL:

rules:
  - expr: "!has(values.persistence) || !values.persistence || has(values.storageClass)"
    desc: "storageClass is required when persistence is enabled"
Copy after login

3. Complex Validations

JSON Schema can become quite verbose for complex validations. Here's a CEL example that would be much more complicated in JSON Schema:

rules:
  - expr: |
      !has(values.resources) || 
      (!has(values.resources.limits) && !has(values.resources.requests)) ||
      (has(values.resources.limits.memory) && has(values.resources.requests.memory) &&
       int(values.resources.requests.memory) <= int(values.resources.limits.memory))
    desc: "If resources are specified, memory request must not exceed memory limit"
Copy after login

Error Messages That Make Sense

One of the best features of Helm CEL is its clear error messages. When validation fails, you get helpful output like this:

❌ Validation failed: replica count must be at least 1
   Rule: values.replicaCount >= 1
   Path: replicaCount
   Current value: 0
Copy after login

Performance Considerations

CEL expressions are compiled and evaluated efficiently. The plugin adds minimal overhead to your Helm workflow, making it suitable for both development and CI/CD pipelines.

Next Steps

  1. Install the plugin: helm plugin install https://github.com/idsulik/helm-cel
  2. Check out the GitHub repository for more examples
  3. Start writing your own validation rules!

Conclusion

Helm CEL brings a more expressive and maintainable way to validate your Helm charts. If you've ever found yourself fighting with JSON Schema or wanting more flexible validation rules, give it a try. The combination of familiar syntax, powerful expressions, and clear error messages makes it a valuable addition to any Helm user's toolkit.

What validation patterns would you like to see? Let me know in the comments below!

The above is the detailed content of Introducing Helm CEL: A More Expressive Way to Validate Your Helm Charts. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the vulnerabilities of Debian OpenSSL What are the vulnerabilities of Debian OpenSSL Apr 02, 2025 am 07:30 AM

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

Transforming from front-end to back-end development, is it more promising to learn Java or Golang? Transforming from front-end to back-end development, is it more promising to learn Java or Golang? Apr 02, 2025 am 09:12 AM

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

How to specify the database associated with the model in Beego ORM? How to specify the database associated with the model in Beego ORM? Apr 02, 2025 pm 03:54 PM

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

What libraries are used for floating point number operations in Go? What libraries are used for floating point number operations in Go? Apr 02, 2025 pm 02:06 PM

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

What is the problem with Queue thread in Go's crawler Colly? What is the problem with Queue thread in Go's crawler Colly? Apr 02, 2025 pm 02:09 PM

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

How to solve the user_id type conversion problem when using Redis Stream to implement message queues in Go language? How to solve the user_id type conversion problem when using Redis Stream to implement message queues in Go language? Apr 02, 2025 pm 04:54 PM

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

What should I do if the custom structure labels in GoLand are not displayed? What should I do if the custom structure labels in GoLand are not displayed? Apr 02, 2025 pm 05:09 PM

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...

In Go, why does printing strings with Println and string() functions have different effects? In Go, why does printing strings with Println and string() functions have different effects? Apr 02, 2025 pm 02:03 PM

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

See all articles