Package: kubesplit
kubesplitWhat?Split multidoc yaml formattedkubernetesdescriptors to a set of single resource files.If you just want an opinionated yaml formatter, you can have a look atyamkix.InstallationThe pip way# Install/Updatepip3install-U--userkubesplit# Enjoykubesplit-ipath/to/yaml_file.yml-opath/to/output/directory# orcatpath/to/yaml_file.yml|kubesplit-opath/to/output/directoryThe docker way# Use latestdockerimagepulllooztra/kubesplit# Or one of the version+sha1 related tagsdockerimagepulllooztra/kubesplit:[version]-[sha1]# Enjoydockercontainerrun\-ti--rm\-v$(pwd):/code\-w/codelooztra/kubesplit\-ipath/to/yaml_file.yml\-opath/to/output/directory# orcatpath/to/yaml_file.yml|\dockercontainerrun\-ti--rm\-v$(pwd):/code\-w/codelooztra/kubesplit\-opath/to/output/directoryAll tags available athttps://cloud.docker.com/repository/docker/looztra/kubesplit/tagsUsage╰(.venv)─»kubesplit-h
usage:kubesplit[-h][-iINPUT][-tTYP]-oOUTPUT_DIR[-n][-e][-q][-f][-d][-c][-p]SplitasetofKubernetesdescriptorstoasetoffiles.Theyamlformatof
thegeneratedfilescanbetunedusingthesameparametersastheoneusedby
Yamkix.Bydefault,explicit_startis`On`,explicit_endis`Off`andarray
elementsarepushedinwardsthestartofthematchingsequence.Commentsare
preservedthankstodefaultparsingmode`rt`.

optionalarguments:-h,--helpshowthishelpmessageandexit-iINPUT,--inputINPUTthefiletoparse,orSTDINifnotspecifiedorifvalueis--tTYP,--typTYPtheyamlparsermode.Canbe`safe`or`rt`-oOUTPUT_DIR,--output-dirOUTPUT_DIRthenameoftheoutputtargetdirectory.Thetargetdirectorywillbecreatedifitdoesnotexistifit'spossible-n,--no-explicit-startbydefault,explicitstart(---)oftheyamldocis`On`,youcandisableitwiththisoption-e,--explicit-endbydefault,explicitend(...)oftheyamldocis`Off`,youcanenableitwiththisoption-q,--no-quotes-preservedbydefault,quotesarepreservedyoucandisablethiswiththisoption-f,--default-flow-styleenablethedefaultflowstyle`Off`bydefault.Indefaultflowstyle(withtyp=`rt`),mapsandlistsarewrittenlikejson-d,--no-dash-inwardsbydefault,dasharepushedinwardsuse`--no-dash-inwards`tohavethedashstartatthesequencelevel-c,--clean-output-dircleantheoutputdirectory(rmtree)ifset(defaultisFalse)-p,--no-resource-prefixbydefault,resourcefilesarenumberprefixed,youcandisablethisbehaviourwiththisflagFeaturesInvalid Kubernetes resources are ignoredEmpty resources are ignoredEach resource found in the input is stored in a file with a name reflecting the name of the resource and itskuberneteskindCluster-wide resources (namespaces, clusterroles, clusterrolebindings) are stored in the root directory of the output, namespaced resources are stored in a subdirectory named like the namespaceBy default, resources are prefixed, use--no-resource-prefixto disable order prefixesBy default, quotes are preserved, use--no-quotes-preservedto disable quotes unless needed (for boolean and numbers if they were provided in the input as for the moment Kubesplit is not aware of the fact that only kubernetes annotations and environment variables require string)By default, dash elements in list are pushed inwards, you can disable this behaviour with the-d/--no-dash-inwardsoptionComments are preservedThe output directory will be created if it doesn't exist (if the user running the command as sufficient rights)You can clean (delete files and directories existing before runningkubesplit) the output directory with the-c/--clean-output-dir(use at your own risks)ExamplesYou can find some input and output examples in thetest-assetsdirectoryValid resources, no quotes preserved╰(.venv)─»kubesplit--inputtest-assets/source/all-in-one.yml\--outputtest-assets/expected/all-in-one--no-quotes-preserved\--no-quotes-preserved\--clean-output-dir
Processing:input=test-assets/source/all-in-one.yml,output_dir=test-assets/expected/all-in-one--no-quotes-preserved,clean_output_dir=True,typ=rt,explicit_start=True,explicit_end=False,default_flow_style=False,quotes_preserved=False,dash_inwards=True,prefix_resource_files=True
Found[16]valid/[0]invalid/[0]emptyresources

╰(.venv)─»tree--dirsfirsttest-assets/expected/all-in-one--no-quotes-preserved
test-assets/expected/all-in-one--no-quotes-preserved
├──apps-demo
│└──05--rolebinding--example-ns-demo-developer-binding.yml
├──apps-integration
│└──05--rolebinding--example-ns-integration-developer-binding.yml
├──ingress-controllers
│├──03--serviceaccount--traefik-ingress-controller.yml
│├──11--configmap--traefik-conf.yml
│├──12--persistentvolumeclaim--traefik-acme.yml
│├──20--deployment--traefik-ingress-controller.yml
│├──30--service--traefik-ingress-endpoint.yml
│├──30--service--traefik-web-ui.yml
│└──31--ingress--traefik-web-ui.yml
├──00--namespace--apps-demo.yml
├──00--namespace--apps-integration.yml
├──00--namespace--ingress-controllers.yml
├──01--clusterrole--example-node-viewer.yml
├──01--clusterrole--example-traefik-ingress-controller.yml
├──02--clusterrolebinding--example-node-viewer-developer.yml
└──02--clusterrolebinding--example-traefik-ingress-controller.yml3directories,16filesValid resources, no prefix, no quotes preserved╰(.venv)─»kubesplit--inputtest-assets/source/all-in-one.yml\--outputtest-assets/expected/all-in-one--no-quotes-preserved--no-resource-prefix\--no-quotes-preserved\--no-resource-prefix\--clean-output-dir
Processing:input=test-assets/source/all-in-one.yml,output_dir=test-assets/expected/all-in-one--no-quotes-preserved--no-resource-prefix,clean_output_dir=True,typ=rt,explicit_start=True,explicit_end=False,default_flow_style=False,quotes_preserved=False,dash_inwards=True,prefix_resource_files=False
Found[16]valid/[0]invalid/[0]emptyresources

╰(.venv)─»tree--dirsfirsttest-assets/expected/all-in-one--no-quotes-preserved--no-resource-prefix
test-assets/expected/all-in-one--no-quotes-preserved--no-resource-prefix
├──apps-demo
│└──rolebinding--example-ns-demo-developer-binding.yml
├──apps-integration
│└──rolebinding--example-ns-integration-developer-binding.yml
├──ingress-controllers
│├──configmap--traefik-conf.yml
│├──deployment--traefik-ingress-controller.yml
│├──ingress--traefik-web-ui.yml
│├──persistentvolumeclaim--traefik-acme.yml
│├──serviceaccount--traefik-ingress-controller.yml
│├──service--traefik-ingress-endpoint.yml
│└──service--traefik-web-ui.yml
├──clusterrolebinding--example-node-viewer-developer.yml
├──clusterrolebinding--example-traefik-ingress-controller.yml
├──clusterrole--example-node-viewer.yml
├──clusterrole--example-traefik-ingress-controller.yml
├──namespace--apps-demo.yml
├──namespace--apps-integration.yml
└──namespace--ingress-controllers.yml3directories,16filesMixed content : valid, invalid and empty resources, no quotes preserved╰(.venv)─»kubesplit--inputtest-assets/source/mixed-content-valid-invalid-and-empty-resources.yml\--outputtest-assets/expected/mixed-content-valid-invalid-and-empty-resources--no-quotes-preserved\--no-quotes-preserved\--clean-output-dir
Processing:input=test-assets/source/mixed-content-valid-invalid-and-empty-resources.yml,output_dir=test-assets/expected/mixed-content-valid-invalid-and-empty-resources--no-quotes-preserved,clean_output_dir=True,typ=rt,explicit_start=True,explicit_end=False,default_flow_style=False,quotes_preserved=False,dash_inwards=True,prefix_resource_files=True
Found[2]valid/[1]invalid/[1]emptyresources

╰(.venv)─»tree--dirsfirsttest-assets/expected/mixed-content-valid-invalid-and-empty-resources--no-quotes-preserved
test-assets/expected/mixed-content-valid-invalid-and-empty-resources--no-quotes-preserved
├──akira
│└──25--replicaset--bididididi.yml
└──yolo└──25--replicaset--frontend.yml2directories,2filesUse casesWith Kustomizekustomizebuildoverlays/prod|kubesplit-q-i--ogenerated/prodWith Helmhelmtemplate--namespacetarget-ns--valuesconfig.ymlmy-chart|kubesplit-q-i--ogenerated/prodTo preserve or not to preserve quotes?Quotes preservedmeans : if there were quotes in the input, they will also be present in the output, and it will be the same type (single/double) of quotesQuotes not preservedmeans :if quotes are not necessary (aroundpurestrings), they will be removedif quotes are present around booleans and numbers, they will be converted to default (single quotes)if quotes are not present around booleans and numbers, there will be no quotes in the output tooNote: there is no option for the moment to force the usage of double quotes when-q/--no-quotes-preservedis used.Quotes preserved (default behaviour)With input :---apiVersion:extensions/v1beta1# with commentkind:ReplicaSetmetadata:name:tnamenamespace:tnsannotations:string_no_quotes:frontendstring_single_quotes:'frontend'string_double_quotes:"frontend"boolean_no_quotes:trueboolean_single_quotes:'true'boolean_double_quotes:"true"number_no_quotes:1number_single_quotes:'1'number_double_quotes:"1"the ouput will be the same as the input :---apiVersion:extensions/v1beta1# with commentkind:ReplicaSetmetadata:name:tnamenamespace:tnsannotations:string_no_quotes:frontendstring_single_quotes:'frontend'string_double_quotes:"frontend"boolean_no_quotes:trueboolean_single_quotes:'true'boolean_double_quotes:"true"number_no_quotes:1number_single_quotes:'1'number_double_quotes:"1"Quotes not preserved (using-q/--no-quotes-preserved)With input :---apiVersion:extensions/v1beta1# with commentkind:ReplicaSetmetadata:name:tnamenamespace:tnsannotations:string_no_quotes:frontendstring_single_quotes:'frontend'string_double_quotes:"frontend"boolean_no_quotes:trueboolean_single_quotes:'true'boolean_double_quotes:"true"number_no_quotes:1number_single_quotes:'1'number_double_quotes:"1"the ouput will be :---apiVersion:extensions/v1beta1# with commentkind:ReplicaSetmetadata:name:tnamenamespace:tnsannotations:string_no_quotes:frontendstring_single_quotes:frontendstring_double_quotes:frontendboolean_no_quotes:trueboolean_single_quotes:'true'boolean_double_quotes:'true'number_no_quotes:1number_single_quotes:'1'number_double_quotes:'1'Note:kubesplitis not fullyKubernetesaware for the moment, so it does not try to enforce this behaviour only on string sensiblekubernetesresource fields (.metadata.annotationsand.spec.containers.environmentvalues)TODOProvide an option to enforce the quote type (by default, with--no-quotes-preservedboolean and integers are forced with single quotes) Hint =>https://stackoverflow.com/questions/56588374/when-using-ruamel-yaml-and-preserve-quotes-true-is-there-a-way-to-force-roundtri/56592388#56592388Contribute# Setup a local virtual env (needed once)python3-mvenv.venv# Activatesource.venv/bin/activate.fish# <= adjust# Install requirementspipinstall-rrequirements_dev.txt# Run locallypython-mkubesplit-h# All make targetsmake# Tests anyone?maketest# hack hack# push PRCreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.Kubesplit uses the awesomeruamel.yamlpython lib.Dependencies scanned byPyUp.io