Giter Site home page Giter Site logo

crd's Introduction

crd

准备工作

生成

cd 到$GOPATH/src

  • ./deepcopy-gen --go-header-file crd/boilerplate.go.txt --input-dirs crd/pkg/apis/foo/v1 --output-package crd/pkg/client
  • ./client-gen --go-header-file crd/boilerplate.go.txt --input-dirs crd/pkg/apis/foo/v1 --output-package crd/pkg/client
  • ./lister-gen --go-header-file crd/boilerplate.go.txt --input-dirs crd/pkg/apis/foo/v1 --output-package crd/pkg/lister
  • ./informer-gen --go-header-file crd/boilerplate.go.txt --input-dirs crd/pkg/apis/foo/v1 --output-package crd/pkg/informer

成果

├── boilerplate.go.txt
├── code-generator-1.16
│   ├── client-gen
│   ├── deepcopy-gen
│   ├── informer-gen
│   └── lister-gen
├── go.mod
├── go.sum
├── pkg
│   ├── apis
│   │   └── foo
│   │       ├── register.go
│   │       └── v1
│   │           ├── deepcopy_generated.go
│   │           ├── doc.go
│   │           ├── register.go
│   │           └── types.go
│   ├── client
│   │   └── internalclientset
│   │       ├── clientset.go
│   │       ├── doc.go
│   │       ├── fake
│   │       │   ├── clientset_generated.go
│   │       │   ├── doc.go
│   │       │   └── register.go
│   │       └── scheme
│   │           ├── doc.go
│   │           └── register.go
│   ├── informer
│   │   └── externalversions
│   │       ├── factory.go
│   │       ├── foo
│   │       │   ├── interface.go
│   │       │   └── v1
│   │       │       ├── hellotype.go
│   │       │       └── interface.go
│   │       ├── generic.go
│   │       └── internalinterfaces
│   │           └── factory_interfaces.go
│   └── lister
│       └── foo
│           └── v1
│               ├── expansion_generated.go
│               └── hellotype.go
└── README.md

17 directories, 28 files

FAQ

  1. why need boilerplate.go.txt ? code-generator的client-gen, deepcopy-gen, lister-gen, informer-gen在启动的时候默认会读取$Projetc/hack目录下的boilerplate.go.txt文件,因此在上述的准备工作中把code-generator/hack/boilerplate.go.txt文件copy到了当前目录下,并在生成模块,通过--go-header-file指定了boilerplate.go.txt文件位置。 同样也可以参考https://github.com/kubernetes/sample-controller中的hack/update-codegen.sh脚本里面也有类似的说明。

    F1223 11:22:28.005533    6641 deepcopy.go:131] Failed loading boilerplate: open k8s.io/code-generator/hack/boilerplate.go.txt: no such file or directory
    goroutine 1 [running]:
    k8s.io/klog/v2.stacks(0xc00000e001, 0xc000218000, 0x99, 0xe9)
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1026 +0xb9
    k8s.io/klog/v2.(*loggingT).output(0x99c620, 0xc000000003, 0x0, 0x0, 0xc00010f960, 0x9776b5, 0xb, 0x83, 0x0)
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:975 +0x19b
    k8s.io/klog/v2.(*loggingT).printf(0x99c620, 0xc000000003, 0x0, 0x0, 0x0, 0x0, 0x78a150, 0x1e, 0xc000042990, 0x1, ...)
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:750 +0x191
    k8s.io/klog/v2.Fatalf(...)
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1502
    k8s.io/gengo/examples/deepcopy-gen/generators.Packages(0xc00010f8f0, 0xc00007ef00, 0x76774c, 0x6, 0xc00010f8f0)
        D:/go/pkg/mod/k8s.io/[email protected]/examples/deepcopy-gen/generators/deepcopy.go:131 +0x135
    k8s.io/gengo/args.(*GeneratorArgs).Execute(0xc00007ef00, 0xc00003de38, 0x76774c, 0x6, 0x795040, 0x0, 0x0)
        D:/go/pkg/mod/k8s.io/[email protected]/args/args.go:206 +0x1a9
    main.main()
        D:/go/src/github.com/kubernetes/code-generator/cmd/deepcopy-gen/main.go:77 +0x4ce
    
    goroutine 6 [chan receive]:
    k8s.io/klog/v2.(*loggingT).flushDaemon(0x99c620)
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:1169 +0x8b
    created by k8s.io/klog/v2.init.0
        D:/go/pkg/mod/k8s.io/klog/[email protected]/klog.go:417 +0xdf
    
  2. why code-generator binary can't be put in crd project ?

    if code-generator binary is in crd project, when you exec the binary like this:

    [root@main crd]# ./deepcopy-gen --go-header-file ./boilerplate.go.txt --input-dirs pkg/apis/foo/v1 --output-package pkg/client
      F1223 14:29:16.195241    3092 main.go:82] Error: Failed making a parser: unable to add directory "pkg/apis/foo/v1": unable to import "pkg/apis/foo/v1": go/build: importGo pkg/apis/foo/v1: exit status 1
      can't load package: package pkg/apis/foo/v1: malformed module path "pkg/apis/foo": missing dot in first path element
    
    or
    
    [root@main crd]# ./deepcopy-gen --go-header-file crd/boilerplate.go.txt --input-dirs crd/pkg/apis/foo/v1 --output-package crd/pkg/client
    F1223 14:26:26.236143   28472 main.go:82] Error: Failed making a parser: unable to add directory "crd/pkg/apis/foo/v1": unable to import "crd/pkg/apis/foo/v1": go/build: importGo crd/pkg/apis/foo/v1: exit status 1
    can't load package: package crd/pkg/apis/foo/v1: malformed module path "crd/pkg/apis/foo": missing dot in first path element
    

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.