Kosko Documentation

website·Indexed 33 days ago

https://kosko.dev/

A tool for managing and linting Kubernetes manifests. Features a comprehensive set of linting rules to enforce valid HPA replicas, unique container names, and required security contexts, as well as plugins for Kustomize and Helm integration. Includes an API for manifest generation, migration, and resolution.

Tokens
39.1K
Snippets
305
Records
412
Agent score
67%

What's inside Kosko

  1. Overview of the Logging library API

    The Logging library provides a set of tools for application logging, including a primary Logger class, various LogWriter implementations (such as ConsoleLogWriter and SilentLogWriter), and utility functions for logger creation and log level management.
  2. Overview of the Kosko Plugin System

    Introduced in Kosko 4.0, the plugin system allows developers to extend the functionality of Kosko by modifying manifests or implementing additional validation logic.
  3. Use SilentLogWriter to omit log output

    The SilentLogWriter class implements the LogWriter interface. It is designed to be a 'no-op' logger that omits or discards all logs passed to it, making it useful for environments where logging should be disabled without changing the application logic.
  4. Create a component with a Deployment and Service using template-deployed-service

    The template-deployed-service provides a way to create a new component that bundles both a Kubernetes Deployment and a Service together. This is managed via the default template which accepts an Options configuration object.
    // Usage of the default template
    const component = default(<Options>);
  5. Prevent missing PersistentVolumeClaim references with no-missing-pvc

    The no-missing-pvc rule ensures that all PersistentVolumeClaim (PVC) references are defined by verifying that the corresponding manifests are present.

    Default Behavior:

    • This rule is enabled by default in the recommended preset.
    • The rule is disabled if specific components are provided via the CLI.
  6. Prevent missing PersistentVolume references with the no-missing-pv rule

    The no-missing-pv rule ensures that all PersistentVolume references are defined by verifying that the corresponding manifests are present. This rule is enabled by default in the recommended preset, but it is disabled when components are specified via the CLI.
  7. Use ResolveErrorOptions to handle resolution errors

    The ResolveErrorOptions interface provides optional metadata about a resolution error, including the underlying cause, the position in the manifest where the error occurred, and the value that triggered the error.
    interface ResolveErrorOptions {
      cause?: unknown;
      position?: ManifestPosition;
      value?: unknown;
    }
  8. Use Kosko in the browser via programmatic API

    Kosko can be used in browsers using the @kosko/env and @kosko/generate packages (available since @kosko/env v2.0.0 and @kosko/generate v1.2.0).

    Key browser-specific constraints:

    1. Environment Loaders: @kosko/env has no default environment loaders in the browser; you must set them manually using dynamic imports or sync loaders.
    2. Component Resolution: You cannot use the generate function from @kosko/generate because it relies on glob, which is unavailable in browsers. Use the resolve function instead to resolve and validate components.
  9. CLIError class properties

    The CLIError class provides two optional read-only properties to provide more context about the error:

    • code: A numeric error code identifying the specific type of error.
    • output: A string containing additional output or diagnostic information related to the error.
  10. Prevent missing ServiceAccount references with no-missing-service-account

    The no-missing-service-account rule ensures that all ServiceAccount references in your manifests are actually defined. It checks for the presence of the corresponding ServiceAccount manifests. Note that the default service account in every namespace is always permitted and does not trigger this rule. This rule is enabled by default in the recommended preset, but is disabled if specific components are provided via the CLI.
  11. Use the SpawnError class to handle process execution errors

    The SpawnError class extends the base Error class and is used to encapsulate detailed information about a failed process spawn. It provides read-only properties that capture the command attempted, the arguments passed, the exit code, and the resulting standard output and error streams.
  12. Define Kubernetes manifests using JavaScript with Kosko

    Kosko allows developers to write Kubernetes manifests using JavaScript or TypeScript instead of static YAML. This enables the reuse of variables, functions, and external libraries to eliminate duplication in manifest definitions.