Git Product home page Git Product logo

file-to-machineconfig's Introduction

file-to-machineconfig

Simple tool to convert files to MachineConfig objects to be used with the machine-config-operator in Kubernetes/OpenShift.

NOTE: It only supports Ignition configuration specification 2.2 so far.

Features

  • Linux/OSX/Windows support (and binaries available in releases/)
  • remote path = local path if not provided
  • remote owner/group = local if not provided
  • sane defaults (...)
  • normalized parameters (...)
  • multiple labels support
  • base64 file encoded content support
  • json output
  • yaml output

To Do

  • Improve normalization and defaults
  • Multiple ignition version
  • Good code
  • Better error handling

Not working

Usage

If using Fedora/CentOS, you can use this copr, otherwise download the latest binary release:

wget -L https://github.com/e-minguez/file-to-machineconfig/releases/download/0.0.3/file-to-machineconfig-linux-amd64 && \
  mv file-to-machineconfig-linux-amd64 ./file-to-machineconfig && \
  chmod a+x ./file-to-machineconfig

Or, get the code with:

go get -u -v github.com/e-minguez/file-to-machineconfig

NOTE: This requires golang to be installed and GOPATH properly configured.

Then:

file-to-machineconfig --file /local/path/to/my/file.txt > ./my-machine-config.json

Use file-to-machineconfig --help for a more complete usage and flags.

WARNING: Review the generated output first, do not pipe the output directly to kubectl or oc!!!

Example

echo "vm.swappiness=10" > ./myswap.conf

file-to-machineconfig --file ./myswap.conf --remote /etc/sysctl.d/swappiness.conf -yaml > myswap.yaml
...[output]...
2019/11/04 14:55:40 name not provided, using '99-worker-etc-sysctl-d-swappiness-conf' as name
2019/11/04 14:55:40 labels not provided, using 'machineconfiguration.openshift.io/role: worker' by default
2019/11/04 14:55:40 filesystem not provided, using 'root' by default
2019/11/04 14:55:40 apiver not provided, using 'machineconfiguration.openshift.io/v1' by default
2019/11/04 14:55:40 user not provided, using 'edu' as the original file
2019/11/04 14:55:40 group not provided, using 'edu' as the original file
2019/11/04 14:55:40 mode not provided, using '0664' as the original file

cat ./myswap.yaml
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
  creationTimestamp: null
  labels:
    machineconfiguration.openshift.io/role: worker
  name: 99-worker-etc-sysctl-d-swappiness-conf
spec:
  config:
    ignition:
      config: {}
      security:
        tls: {}
      timeouts: {}
      version: 2.2.0
    networkd: {}
    passwd: {}
    storage:
      files:
      - contents:
          source: data:text/plain;charset=utf-8;base64,dm0uc3dhcHBpbmVzcz0xMAo=
          verification: {}
        filesystem: root
        group:
          name: edu
        mode: 436
        path: /etc/sysctl.d/swappiness.conf
        user:
          name: edu
    systemd: {}
  osImageURL: ""

Just to verify:

echo "dm0uc3dhcHBpbmVzcz0xMAo=" | base64 -d
vm.swappiness=10

file-to-machineconfig's People

Contributors

ashcrow avatar e-minguez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ashcrow

file-to-machineconfig's Issues

Add Build Info

Super neat!!
Would it be possible to add
a) build information
b) releases (pre-built binaries)

Autodiscover name doesn't work with uppercase path

file-to-machineconfig --file 30-mtu --remote /etc/NetworkManager/dispatcher.d/30-mtu
{
  "kind": "MachineConfig",
  "apiVersion": "machineconfiguration.openshift.io/v1",
  "metadata": {
    "name": "99-worker-etc-NetworkManager-dispatcher-d-30-mtu",
    "creationTimestamp": null,
    "labels": {
      "machineconfiguration.openshift.io/role": "worker"
    }

Then

$ oc create -f mc-mtu.json 
The MachineConfig "99-worker-etc-NetworkManager-dispatcher-d-30-mtu" is invalid: metadata.name: Invalid value: "99-worker-etc-NetworkManager-dispatcher-d-30-mtu": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')

Plain doesn't work

The mc controller complains about invalid url when using plain and yaml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.