Skip to content

ytt libraries

Myks provides flexible ways to use ytt libraries in your applications and prototypes.

Environment Data Library allows you to access an environment’s known data values in an application’s data values files as a ytt library. Normally, ytt doesn’t provide a way to reference other data values, because all data values are loaded simultaneously.

During processing of an environment, myks internally produces final data values for the environment from collected data values of the parent environments. For every ytt invocation scoped to an application, myks provides a @myks library with a data.lib.yaml module which exports a struct env_data containing all final data values of the environment. Here’s how it can be used:

#@ load("@myks:data.lib.yaml", "env_data")
#@data/values
---
application:
name: #@ "MyApp-" + env_data.environment.region

The @myks library is available in every ytt invocation of an application, including the _env/ytt/ overlays of the global-ytt step, and in the environment-level Argo CD render.

In addition to the global environment data library, myks automatically includes lib directories found in application and prototype paths. This allows you to define and share reusable ytt functions or data across your project.

Myks looks for a lib directory in the following locations:

  1. Application Directories: envs/**/_apps/<app>/lib
    • Libraries specific to an application in a specific environment (or any parent environment).
  2. Prototype Directories: prototypes/<prototype>/lib
    • Libraries shared by all applications using this prototype.

Any .lib.yaml or .star files placed in these lib directories are available to be loaded in your ytt templates, overlays, and data values.

For example, if you have:

prototypes/my-app/lib/helpers.lib.yaml:

#@ def name_suffix(suffix):
#@ return "-"+suffix
#@ end

You can use it in your application’s ytt files:

#@ load("helpers.lib.yaml", "name_suffix")
apiVersion: v1
kind: ConfigMap
metadata:
name: #@ "myapp" + name_suffix("prod")

Myks collects library files in a specific order. This is important if you have data values files in these directories (which are order-sensitive) or if relying on specific file loading behavior.

The collection order is:

  1. Global Environment Data (.myks/envs/...)
  2. Application Libraries (collected from the most specific environment to the root environment)
  3. Prototype Libraries
  4. Environment Data Files