Giter Club home page Giter Club logo

kube-code-generator's Introduction

Kube code generator

Kubernetes release

Introduction

When we speak about Kubernetes operators or controllers, normally Go code, CR, CRDs... are required. To create all the autogenerated Kubernetes Go code (Clients, helpers...) and manifests (CRD), the process is a bit painful.

This small project tries making easy this process, by creating a small layer between Kubernetes official tooling that are used to get all this autogenerated stuff, and abstract options and infer some others, making a better UX for the user.

The projects that are used under the hood are:

Why and when use this

  • You don't like, need or use kubebuilder for your CRDs.
  • You want simple tooling to generate Kubernetes CRD Go clients and manifests.
  • You like safe standards and simple things.
  • You use CRDs for more/other things than operators (e.g: generating CLIs, storing state on k8s as APIs...).
  • You don't want to do hacky and ugly stuff to start creating Kubernetes tooling.

Features

  • Small API/configuration.
  • Safe standards
  • Ready to use Docker images.
  • Generates Go code like clients and informers (Used to implement operators, CLIs...).
  • Generates CRD manifests (Used for API registration on k8s clusters).

How to use it

The easiest way is to use the provided Docker image as it has all the required upstream dependencies.

Here is an example that mounts the current directory (a Go project) and generates the Go code and the CRDs by providing the APIs input directory and the generation output directories:

docker run -it --rm -v ${PWD}:/app ghcr.io/slok/kube-code-generator \
 --apis-in ./apis \
 --go-gen-out ./gen \
 --crd-gen-out ./gen/manifests

However, the best way to know how to use it is with a full example, you have it in _example dir.

Kubernetes versions

It's suggested that if you don't have an old Kubenretes version, you try the latest kube-code-generator (latest), however the ones described on the table here are known to work correctly on the specific version.

Kubernetes Docker image
v1.30 docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.29 docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.28 docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.27 docker pull ghcr.io/slok/kube-code-generator:v0.2.0

Versions <v1.27

With the release of Kubernetes v1.30, this app was rewritten from bash hacky scripts into a proper Go application, that is easier, more extendable and safer to use.

In case you tested this new refactor and isn't working for you, Inwould suggest to try the previous versions, check the previous Readme.

kube-code-generator's People

Contributors

dependabot[bot] avatar slok 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

Watchers

 avatar  avatar  avatar  avatar  avatar

kube-code-generator's Issues

More specific docs and/or errors

Tried this out on cert-manager because I need to operate on certificate resources, but I can't tell whether I'm doing something wrong or if the code in their repo isn't as expected. If the tool would need some upstream change in cert-manager, then could it signal what that change would be? That way I could request that change or fork.

Here's the command and the output:

PROJECT_PACKAGE=github.com/jetstack/cert-manager && docker run -it --rm     -v ${PWD}:/go/src/${PROJECT_PACKAGE}    -e PROJECT_PACKAGE=${PROJECT_PACKAGE}     -e CLIENT_GENERATOR_OUT=${PROJECT_PACKAGE}/pkg/client    -e APIS_ROOT=${PROJECT_PACKAGE}/apis     -e GROUPS_VERSION="cert-manager.io:v1"     -e GENERATION_TARGETS="deepcopy,client"     quay.io/slok/kube-code-generator
go: downloading k8s.io/gengo v0.0.0-20201113003025-83324d819ded
go: downloading k8s.io/klog/v2 v2.4.0
go: downloading github.com/go-logr/logr v0.2.0
go: downloading golang.org/x/tools v0.0.0-20200616133436-c1934b75d054
go: downloading golang.org/x/mod v0.3.0
go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
Generating deepcopy funcs
Generating clientset for cert-manager.io:v1 at github.com/jetstack/cert-manager/pkg/client/clientset
F0428 15:30:22.503806     452 main.go:64] Error: Failed executing generator: some packages had errors:
errors in package "github.com/jetstack/cert-manager/pkg/client/clientset/versioned":
unable to format file "/go/src/github.com/jetstack/cert-manager/pkg/client/clientset/versioned/clientset.go" (23:6: expected 'STRING', found '-' (and 1 more errors)).

errors in package "github.com/jetstack/cert-manager/pkg/client/clientset/versioned/scheme":
unable to format file "/go/src/github.com/jetstack/cert-manager/pkg/client/clientset/versioned/scheme/register.go" (23:6: expected 'STRING', found '-' (and 1 more errors)).

errors in package "github.com/jetstack/cert-manager/pkg/client/clientset/versioned/fake":
unable to format file "/go/src/github.com/jetstack/cert-manager/pkg/client/clientset/versioned/fake/clientset_generated.go" (23:10: expected 'STRING', found '-' (and 1 more errors)).
unable to format file "/go/src/github.com/jetstack/cert-manager/pkg/client/clientset/versioned/fake/register.go" (23:6: expected 'STRING', found '-' (and 1 more errors)).

goroutine 1 [running]:
k8s.io/klog/v2.stacks(0xc000010001, 0xc0001da500, 0x42b, 0x481)
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1026 +0xb9
k8s.io/klog/v2.(*loggingT).output(0x9d31e0, 0xc000000003, 0x0, 0x0, 0xc0001cc380, 0x9ac195, 0x7, 0x40, 0x0)
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:975 +0x19b
k8s.io/klog/v2.(*loggingT).printf(0x9d31e0, 0xc000000003, 0x0, 0x0, 0x0, 0x0, 0x78a0b6, 0x9, 0xc000051630, 0x1, ...)
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:750 +0x191
k8s.io/klog/v2.Fatalf(...)
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1502
main.main()
	/go/src/k8s.io/code-generator/cmd/client-gen/main.go:64 +0x58d

goroutine 6 [chan receive]:
k8s.io/klog/v2.(*loggingT).flushDaemon(0x9d31e0)
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1169 +0x8b
created by k8s.io/klog/v2.init.0
	/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:417 +0xdf

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.