Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Improve user experience in the Butane command-line utility

Do you like sugar with your Butane?

May 16, 2024
Steven Presti
Related topics:
ContainersDeveloper toolsLinux
Related products:
Red Hat OpenShift

    Butane (formerly the Fedora CoreOS Config Transpiler, or FCCT) is a command-line utility that is used to generate human readable configuration into Ignition configuration files. Butane is an open source repo maintained by CoreOS, and contributed to and enhanced by many. If you take a look at the Butane repo and look in the Config folder, you can almost see some of the stakeholders. These are configurations which are used to target different platforms (i.e., FCOS, Flatcar Container Linux, Red Hat OpenShift, etc.) Each of these configurations will have a stable and experimental phase that also targets stable and experimental specs of Ignition. I would describe these as levers that a contributor can exercise to impact the functionality they want to expose to the end users of these target platforms.

    What do we mean by sugar?

    So what is this sugar, and why do we want it? With the primary focus of Butane being the translation of something that is easily understood to something that is more specific and less easily understood, honestly, you could view all of Butane as some form of sugar. I like to think of it as magic dust we use to make the user experience more enjoyable by reducing the amount of effort it takes to do common tasks. Sugar typically impacts all target platforms, and is added to the experimental spec, which gets stabilized eventually.

    Example use case

    As a user, if I want to create a file which is nested in a few directories (i.e.: /foo/bar/directory/myfile.txt) with a specific permission set, I do not want to have to describe each independent folder the file is nested in (i.e.: /foo, /foo/bar, /foo/bar/directory). Currently in Butane, you would have:

    variant: fcos
    version: 1.6.0-experimental
    storage:
      files:
        - path: /foo/bar/directory/myfile.txt
          user:
            name: builder
          contents:
            inline: my content!
      directories:
        - path: /foo/bar/directory/
          user:
            name: builder
          group:
            name: builder
        - path: /foo/bar
          user:
            name: builder
          group:
            name: builder
        - path: /foo
          user:
            name: builder
          group:
            name: builder
    

    As you can see in this example Config, there is already a lot of bloating and potential surface area that could expose the user to user error and large Butane files.

    Steps to add sugar

    UX changes

    The first thing you want to do is decide what type of user experience you want to provide the consumer. So looking at this and the problem provided, we know we want to eliminate the need to add configuration for the individual directories. We want some magical dust to be able to interpret what the user wants. Since the issue stems from the file being in a nested directory, lets look at a file's fields.

    Find what part of the translation is too bitter

    Looking at the latest spec, we can see that we have already defined a custom translator for file and registered it here. Initially, since we are adding sugar to files, you might think that our work belongs in the custom translator of files. However, since our sugar is going to be expanding directories, we need to place our sugar at a point in translation which the sugar can interact both with files and directories. Since we know we need to interact with both files and directories we can look at our schema, and find the earliest struct which contains and knows about both of them. In this case storage knows about both of them; you can see that here.

    Add some sugar!

     

    Info alert: Note

    At this point, please know that the following code is condensed and summarized to reduce bloating. I will try and focus on the important bits.

    Now that we know our storage struct is too bitter, we can go about adding the sugar to make it oh-so-sweet. To do this, we can create a custom translator similar to the custom file translator found here, but in this case storage will register the custom file translator as well. To do this, understand we are creating a map from Butane's struct to Ignition's. And we now have the chance to make changes to the outputted Ignition config. So our signature will look like this:

    func translateStorage(from Storage, options common.TranslateOptions) (to types.Storage, tm translate.TranslationSet, r report.Report) 
    

    Now we start defining our translator, we are translating from YAML to JSON.

    tr := translate.NewTranslator("yaml", "json", options)
    

    And we have some pre-existing custom translators that we can register like this:

    ...
    tr.AddCustomTranslator(translateDirectory)
    ...
    

    Now we can start translating from the Butane structs to Ignition. So looking at our storage struct we can see all the fields we need to add translation for. To do this, we start adding field by field, declaring the top most field our prefix:

    ...
    tm, r = translate.Prefixed(tr, "directories", &from.Directories, &to.Directories)
    translate.MergeP(tr, tm, &r, "disks", &from.Disks, &to.Disks)
    ...
    }
    

    Awesome! We are now at the point where our translator should handle all the requirements for converting from YAML to JSON between Butane and Ignition. The last part is adding our sugar.

    To do this, we can now work against the from object and iterate through our files. While iterating through the files, our sugar will look at the parent to see if action is required.

    Once we have decided that a file has directories that need to be expanded, we can then:

    // For each directory that needs to be expanded based off parent and file path
    // We create the Ignition struct of the directory
    renderedDir := types.Directory {
                        Node: types.Node{
                            Path:  dir,
                            Group: types.NodeGroup{ID: file.Group.ID, Name: file.Group.Name},
                            User:  types.NodeUser{ID: file.User.ID, Name: file.User.Name},
                        },
                        DirectoryEmbedded1: types.DirectoryEmbedded1{
                            Mode: file.Parent.Mode,
                        },
                    }
    // Append it to the return object `to`
    to.Directories = append(to.Directories, renderedDir)
    }
    

    Lastly, we need to do some housekeeping and update our report by associating all these directories to a context path by having a line similar to the following:

    tm.AddFromCommonSource(yamlPath, path.New("json", "directories"), to.Directories)
    

    Finally, we have created sugar and a custom translator. Now, let's register it.

    In the main translate function, we can register our custom translator like so:

    tr.AddCustomTranslator(translateStorage) 
    

    We can see this code work by creating some tests similar to the directory tests here.

    Updating documentation

    Ensuring that the documentation accurately reflects the changes made to Butane's functionality is crucial for maintaining clarity and transparency. You can see the long list of documentation here. This is every platform Config type that Butane supports. They are subsets of functionality but as a result they have a large overlap of documentation. Thankfully we don't need to manually update the docs on each of these targets, there is automation built in!

    1. Update the docs related to the struct

    Begin by including your new fields within the structured documentation file, accessible here. As these additions are in the file, navigate to this specific section within and add something like the following:

    - name: files
      children:
        - name: contents
          children:
            - name: source
              transforms:
                - regex: "Supported schemes are .* haven't been modified."
                  replacement: 'Only the [`data`](https://tools.ietf.org/html/rfc2397) scheme is supported.'
                  if:
                    - variant: openshift
        - name: mode
          use: mode
        - name: parent
          after: $
          desc: The parent directory for the specified file. By declaring a parent, directories from the parent to the file's target destination are automatically created.
          children:
            - name: path
              desc: The path of the directory within the file's 'path'.
            - name: mode
              desc: Directory modes are set to 0755 as a default if not specified, and the directory does not exist prior to the specified file.
    

    Once you've updated the YAML file, execute the ./generate command from the root directory of the Butane repository. This action triggers the automatic regeneration of all platform configuration documents, ensuring that they are synchronized with the latest information.

    2. Update examples in examples.md

    Finish the documentation update process by adding examples to the examples.md file. Here, you can include a a demonstration of the new sugar. Provide clear instructions and examples to assist users in understanding and using the sugar.

    Final thoughts

    The concept of sugar in Butane is as varied and nuanced as the use cases it addresses. It can be as simple as adding a touch of convenience to a common task, or as complex as restructuring core functionalities. Understanding its potential and implications can empower us to enhance Butane's day-to-day user experience significantly.

    Related Posts

    • How to customize Fedora CoreOS for dedicated workloads with OSTree

    • How to run containerized workloads securely and at scale with Fedora CoreOS

    • How the new RHEL 9.2 improves the developer experience

    • 3 steps toward improving container security

    • Improving user experience for mobile APIs using the cloud

    • What's new for developers in Red Hat OpenShift 4.15

    Recent Posts

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    What’s up next?

    Convert CentOS Linux to RHEL share and feature image

    Convert2RHEL is a command-line utility that can streamline your migration path from CentOS Linux 7 to a fully supported Red Hat Enterprise Linux (RHEL) operating system. This cheat sheet outlines how to convert your CentOS Linux instance to RHEL in just 7 steps.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.