Skip to content

ITD27M01/timonify

Repository files navigation

Timonify

CLI that creates Timoni modules from kubernetes manifests.

Timonify reads a list of supported k8s objects from stdin and converts it to a timoni module. Designed to generate modules for k8s operators but not limited to.

Literally based on Helmify code.

Currently under heavy development, expect things to break =)

Usage

  1. As pipe:

    cat my-app.yaml | timonify mymodule

    Will create 'mymodule' directory with Timoni module from yaml file with k8s objects.

    awk 'FNR==1 && NR!=1  {print "---"}{print}' /<my_directory>/*.yaml | timonify mymodule

    Will create 'mymodule' directory with Timoni module from all yaml files in <my_directory> directory.

  2. From filesystem:

    timonify -f /my_directory/my-app.yaml mymodule

    Will create 'mymodule' directory with Timoni module from my_directory/my-app.yaml.

    timonify -f /my_directory mymodule

    Will create 'mymodule' directory with Timoni module from all yaml files in <my_directory> directory.

    timonify -f /my_directory -r mymodule

    Will create 'mymodule' directory with Timoni module from all yaml files in <my_directory> directory recursively.

    timonify -f ./first_dir -f ./second_dir/my_deployment.yaml -f ./third_dir  mymodule

    Will create 'mymodule' directory with Timoni module from multiple directories and files.

  3. From kustomize output:

    kustomize build <kustomize_dir> | timonify mymodule

    Will create 'mymodule' directory with Timoni module from kustomize output.

Integrate to your Operator-SDK/Kubebuilder project

  1. Open Makefile in your operator project generated by Operator-SDK or Kubebuilder.
  2. Add these lines to Makefile:
  • With operator-sdk version < v1.23.0
    TIMONIFY = $(shell pwd)/bin/timonify
    timonify:
    	$(call go-get-tool,$(TIMONIFY),github.com/syndicut/timonify/cmd/timonify@latest)
    
    timoni: manifests kustomize timonify
    	$(KUSTOMIZE) build config/default | $(TIMONIFY)
  • With operator-sdk version >= v1.23.0
    TIMONIFY ?= $(LOCALBIN)/timonify
    
    .PHONY: timonify
    timonify: $(TIMONIFY) ## Download timonify locally if necessary.
    $(TIMONIFY): $(LOCALBIN)
    	test -s $(LOCALBIN)/timonify || GOBIN=$(LOCALBIN) go install github.com/syndicut/timonify/cmd/timonify@latest
        
    timoni: manifests kustomize timonify
    	$(KUSTOMIZE) build config/default | $(TIMONIFY)
  1. Run make timoni in project root. It will generate timoni module with name 'timoni' in 'timoni' directory.

Install

go install github.com/syndicut/timonify/cmd/timonify@latest

Status

Supported k8s resources:

  • Deployment

TODO resources (not supported yet):

  • DaemonSet, StatefulSet
  • Job, CronJob
  • Service, Ingress
  • PersistentVolumeClaim
  • RBAC (ServiceAccount, (cluster-)role, (cluster-)roleBinding)
  • configs (ConfigMap, Secret)
  • webhooks (cert, issuer, ValidatingWebhookConfiguration)
  • custom resource definitions (CRD)

Known issues

  • Timonify will not overwrite timoni.cue file if presented. Done on purpose.
  • Timonify will not delete existing template files, only overwrite.
  • Timonify overwrites templates and values files on every run. This means that all your manual changes in timoni template files will be lost on the next run.

Develop

To support a new type of k8s object template:

  1. Implement timonify.Processor interface. Place implementation in pkg/processor. The package contains examples for most k8s objects.
  2. Register your processor in the pkg/app/app.go
  3. Add relevant input sample to test_data/kustomize.output.

Run

Clone repo and execute command:

cat test_data/k8s-operator-kustomize.output | go run ./cmd/timonify mymodule

Will generate mymodule Timoni module form file test_data/k8s-operator-kustomize.output representing typical operator kustomize output.

Test

For manual testing, run program with debug output:

cat test_data/k8s-operator-kustomize.output | go run ./cmd/timonify -vv mymodule

Then inspect logs and generated module in ./timoni directory.

To execute tests, run:

go test ./...

Beside unit-tests, project contains e2e test pkg/app/app_e2e_test.go. It's a go test, which uses test_data/* to generate a module in temporary directory. Then runs timoni mod lint to check if generated module is valid.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages