Coder Social home page Coder Social logo

skarlso / crd-to-sample-yaml Goto Github PK

View Code? Open in Web Editor NEW
87.0 3.0 14.0 64.44 MB

Generate a sample YAML file from a CRD

Home Page: https://crdtoyaml.com/

License: Apache License 2.0

Go 14.28% Makefile 0.73% HTML 70.78% Dockerfile 0.08% CSS 0.57% JavaScript 13.56%
crd go golang kubernetes yaml hacktoberfest

crd-to-sample-yaml's Introduction

crd-to-sample-yaml or cty ( city )

logo

Generate a sample YAML file from a CRD definition.

Getting started

  • Prerequisites: Go installed on your machine. (Check out this link for details: https://go.dev/doc/install)
  • Clone the repository
  • Execute make build to build the binary

Now you can simply run:

cty generate -c delivery.krok.app_krokcommands

Optionally, define a URL at which a CRD is located:

cty generate -u https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-provider-aws/main/config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

cty does not support authentication modes, therefore the CRD needs to be publicly accessible.

This will result in a file similar to this:

apiVersion: delivery.krok.app/v1alpha1
kind: KrokCommand
metadata: {}
spec:
  commandHasOutputToWrite: true
  dependencies: ["string"]
  enabled: true
  image: string
  platforms: ["string"]
  readInputFromSecret:
    name: string
    namespace: string
  schedule: string
status: {}

A single file will be created containing all versions in the CRD delimited by ---.

Optionally, you can provide the flag -s which will output the generated content to stdout.

HTML output

It's possible to generate a pre-rendered HTML based output for self-hosting what the website produces online.

To get an HTML output provide the format flag like this:

cty generate -c delivery.krok.app_krokcommands --comments --format html

parsed1_cli parsed2_cli

Minimal required CRD sample

It's possible to generate a sample YAML for a CRD that will make the CRD validation pass. Meaning, it will only contain samples for fields that are actually required. All other fields will be ignored.

For example, a CRD having a single required field with an example and the rest being optional would generate something like this:

apiVersion: delivery.krok.app/v1alpha1
kind: KrokCommand
spec:
  image: "krok-hook/slack-notification:v0.0.1"

To run cty with minimal required fields, pass in --minimal to the command like this:

cty generate -c delivery.krok.app_krokcommands --comments --minimal --format html

Folder source

To parse multiple CRDs in a single folder, just pass in the whole folder like this:

cty generate -r folder

Any other flag will work as before.

WASM frontend

There is a WASM based frontend that can be started by navigating into the wasm folder and running the following make target:

make run

This will start a front-end that can be used to paste in and parse CRDs.

Shareable Link

It's possible to provide a link that can be shared using a url parameter like this:

https://crdtoyaml.com/share?url=https://raw.githubusercontent.com/Skarlso/crd-to-sample-yaml/main/sample-crd/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Will load the content, or display an appropriate error message.

Comments

Comments can be added to each line of the generated YAML content where descriptions are available. This looks something like this:

# APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
# Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
kind: AWSCluster
metadata: {}
# AWSClusterSpec defines the desired state of an EC2-based Kubernetes cluster.
spec:
  # AdditionalTags is an optional set of tags to add to AWS resources managed by the AWS provider, in addition to the ones added by default.
  additionalTags: {}
  # Bastion contains options to configure the bastion host.
  bastion:
  ...

To add comments simply run cty with:

cty generate -c sample-crd/infrastructure.cluster.x-k8s.io_awsclusters.yaml --comments

The frontend also has a checkbox to add comments to the generated yaml output.

Templated CRDs

It's possible to provide a templated CRD like this one for flux: Helm Controller.

It contains template definition like:

{{- if and .Values.installCRDs .Values.helmController.create }}

These are trimmed so that the CRD parses correctly. Any values that might be in-lined are replaced with replaced. This is done to avoid trying to parse a breaking yaml.

Things like this:

kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.15.0
  labels:
    app.kubernetes.io/component: helm-controller
    app.kubernetes.io/instance: {{ .Release.Namespace }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/part-of: flux
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
    helm.sh/chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}'
  name: helmreleases.helm.toolkit.fluxcd.io

Where some templated value isn't escaped with ' will create an invalid YAML that fails to parse.

Showcase

frontpage

Parsed Yaml output on the website:

parsed1 parsed2 parsed3

crd-to-sample-yaml's People

Contributors

ahsan-ehtesham avatar dependabot[bot] avatar playmtl avatar radzhiv25 avatar skarlso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

crd-to-sample-yaml's Issues

feat: URL to CRDs definition will ignore go-template blocks

Hi,

in helm chart templates, there are usually go-template functions or blocks, and I wish to point to the CRDs definition with go-template blocks and render yaml from this file.

for example:
https://raw.githubusercontent.com/fluxcd-community/helm-charts/main/charts/flux2/templates/helm-controller.crds.yaml

{{- if and .Values.installCRDs .Values.helmController.create }}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.15.0
  labels:
    app.kubernetes.io/component: helm-controller
...
...
...
    subresources:
      status: {}
{{- end }}

Now I getting error in UI
image
image

Shareable link

With the new wasm frontend I lost the shareable link feature. I should add that back somehow.

bug: minimal example lacks required metadata

Hi, sorry, I didn't saw it yesterday - was late:

apiVersion: cdaas.dp.db.de/v1alpha1
kind: KubernetesAgent
# All information for the provider
spec:
...

The minimal example lacks the required metadata XD. Even if it's not marked as required, name and namespace should be present.

how get those nice rendered website?

Hi,
could you provider some sample docs on how to generate those nice looking html for the crds? Is it possible to generate them as static files for use in github pages and so on?

I would like to generate static files for my crds - is this possible?

Something like

make static path/to/my/crd.yaml

feat: version command that prints the current version

Hi,
now I am trying to automate the update process of cty and there it would be great if I could check if the installed cty version is the correct one. But I didn't found any version information - so something like cty version would be great ;-)

Sorry if I have so many ideas - at the moment your tool is just the best I found for generating examples :)

Maybe I could implement this - my go is not so fluent XD

Improved Navbar

Using basic HTML and CSS
Also please consider it under hacktoberfest

Use "example" value if provided

First of all, great tool - I really like!

At the moment the generation of examples seems to use "type", or if exists "default" as example value. It would be great if it also could parse "example" and use this, if exists.

precedence should be:

  1. default
  2. example
  3. type

What do you think about this?

Feat: Add authentication option for cty to access private URLs

There is no real reason I guess for cty to NOT use authentication. I'll just add username / password / token for now. Then we can see about certificates or some such if there is a need.

The website probably will still not support it, but the command line tool's URL option should be able to.

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.