Skip to content

Feature Request: Add yaml.decode / yaml.encode to Lua helper functions #667

@kahirokunn

Description

@kahirokunn

Summary

Please add native YAML support to Sveltos Lua: yaml.decode(string) and yaml.encode(table).

Motivation

We want to use a kubeconfig stored in a Kubernetes Secret as the source and parse it directly in Lua without converting to JSON first. Native YAML I/O would simplify scripts, improve readability, and remove external conversion steps.

Example

-- Extract current cluster server URL and CA data from a kubeconfig YAML.
local function extract_kubeconfig_info(kubeconfig_yaml)
  local cfg = yaml.decode(kubeconfig_yaml)
  local current = cfg["current-context"]

  local function get_cluster_by_name(name)
    for _, c in ipairs(cfg.clusters or {}) do
      if c.name == name then return c.cluster end
    end
  end

  for _, ctx in ipairs(cfg.contexts or {}) do
    if ctx.name == current and ctx.context and ctx.context.cluster then
      local cl = get_cluster_by_name(ctx.context.cluster)
      if cl then
        return {
          server = cl.server,
          ca_data = cl["certificate-authority-data"],
        }
      end
    end
  end

  -- Not found
  return { server = nil, ca_data = nil }
end

-- usage:
-- local info = extract_kubeconfig_info(kubeconfig_yaml)
-- return info

Expected Behavior

  • yaml.decode/encode available in the Lua runtime
  • Handles single and multi‑document YAML

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions