Skip to content

v0.23.0

Choose a tag to compare

@arnarg arnarg released this 14 Oct 16:39
· 15 commits to main since this release

New Features

Object Transforms, reimagined: transform parts of resources - @Mewp #109

The object transform mechanism has been completely reworked and is far more powerful now. Instead of a list of rules with a rewrite function, objectTransforms is an attrset where each transform can act on a whole resource or on just a part of it:

{
  nixidy.objectTransforms = {
    # Match objects, then update a part of them.
    fix-store = {
      match.kind = "ExternalSecret";
      update.spec.secretStoreRef = {
        kind = "ClusterSecretStore";
        name = "foo";
      };
    };

    # Target a specific path inside every matched resource. List elements
    # are iterated, so this rewrites every container in every Deployment:
    add-tty = {
      match.kind = "Deployment";
      transforms.tty = {
        path = [ "spec" "template" "spec" "containers" ];
        update.tty = true;
      };
    };

    # Setting a part to null removes the attribute.
    drop-foo-label = {
      path = [ "metadata" "labels" "foo" ];
      replace = null;
    };
  };
}

Each transform sets exactly one of replace (swap the value or the whole object, returning null drops it), update (recursively merge into the old value), or transforms (nested transforms, scoped to what the outer transform matched and nestable arbitrarily deep). Plain values are accepted anywhere a function is, so replace = { ... }; and update.metadata.labels.foo = "bar"; both work without writing old: ... lambdas.

The match selector has also grown up: it now uses ordinary attribute paths (metadata.labels."app.kubernetes.io/name"), searches list elements for a match (e.g. spec.containers.envFrom.secretRef.name = "foo" matches any pod container referencing that secret), and accepts lists of values for OR-matching (namespace = [ "foo" "bar" ]).

Runtime stages (previously postProcess rules inside objectTransforms) have moved to their own nixidy.postProcessors option, environment-wide or per-application, with the same stdin to stdout contract, confirmation prompt, and NIXIDY_POST_PROCESS_APPROVE / NIXIDY_SKIP_POST_PROCESS behaviour as before:

{
  nixidy.postProcessors.encrypt-secrets = {
    match.kind = "SopsSecret";
    runtimeInputs = [ pkgs.sops ];
    command = "sops --encrypt --input-type yaml --output-type yaml /dev/stdin";
  };
}

See the rewritten Object Transforms documentation and the new Post-processing page.

CRD option types now validate your values - #56

The CRD resource options generators now fold JSON Schema validation keywords into the generated option types: minimum/maximum (inclusive and exclusive), multipleOf, minLength/maxLength, and scalar enum values. Out-of-bounds resource values are rejected at evaluation time by both the file and value backends, so a typo like replicas = 0 against a schema requiring at least 1 fails at build instead of at apply:

error: A definition for option '...' is not of type 'integer (minimum 1)'.

Breaking Changes

  • objectTransforms is now an attrset of transforms instead of a list of rules. The rewrite key is gone; use replace or update instead. Runtime stages moved to the new postProcessors option with command instead of postProcess. Rules run in attribute-name order (env first, then app scope). #109
  • The post-process multi-document assertion is stricter. A build error is now raised when a post-processor matches only some objects of a multi-document file, a case that was previously undefined. Post-processed files must be single-object. #102

Improvements

  • Build module split into a pure layout seam + emitters. The monolithic modules/build.nix was restructured into modules/build/ as a functional-core pipeline: a pure layout.nix that turns each application into a list of FileSpec (exposed as the internal config.build.layout), with render.nix, emit-environment.nix and apply.nix consuming it. No public API change, but switch and apply now post-process identical file sets by construction, and an application whose name is overridden no longer fails to build. #102 @sini