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
-
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.
-
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.
-
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
- Open
Makefile
in your operator project generated by
Operator-SDK or Kubebuilder.
- 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)
- 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:
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:
- Implement
timonify.Processor
interface. Place implementation in pkg/processor
. The package contains
examples for most k8s objects.
- Register your processor in the
pkg/app/app.go
- 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.