kubernetes-crd-example

module
v0.0.0-...-75be4f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2022 License: Apache-2.0

README

kubernetes-crd-example

Guide for autogeneratng client codes for Kubernetes Custom Resource Definitions (CRD)

Steps:

  • take the configuration in directory in pkg/apis/foo.com/ as template to define the new crd"

  • Disable go modules

export GO111MODULE=off
  • Download the generator repository
 go get k8s.io/code-generator
  • Download this repository
go get github.com/afarid/kubernetes-crd-example/pkg/apis/foo.com/v1
  • Run this command inside this project directory:
cd $GOPATH/src/github.com/afarid/kubernetes-crd-example
../../../k8s.io/code-generator/generate-groups.sh all "github.com/afarid/kubernetes-crd-example/pkg/clients" "github.com/afarid/kubernetes-crd-example/pkg/apis" "foo.com:v1" -h ../../../k8s.io/code-generator/hack/boilerplate.go.txt

After running the above command, you will see a new directory pkg/clients/.

  • use generated package in your code, this is an example of how to use the generated package
package main

import (
	clientset "github.com/afarid/kubernetes-crd-example/pkg/clients/clientset/versioned"
)

func main() {
	_, _ = clientset.NewForConfig(nil)
}

Directories

Path Synopsis
pkg
clients/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
clients/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
clients/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
clients/clientset/versioned/typed/foo.com/v1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
clients/clientset/versioned/typed/foo.com/v1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL