I use the code-generator to produce a sample clientset for testing.
My go version is go version go1.17.5 linux/amd64
.
If I install the code-generator in this way go install k8s.io/code-generator@v0.23.2-rc.0
, then run the command like below. It seems not to work. The output packages are not existing, like below:
[root@k8s code-generator@v0.23.2-rc.0] echo $ROOT_PACKAGE
/root/go/src/github.com/resouer/k8s-controller-custom-resource
[root@k8s code-generator@v0.23.2-rc.0] echo $CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSION
samplecrd:v1
[root@k8s code-generator@v0.23.2-rc.0] bash -x ./generate-groups.sh all "$ROOT_PACKAGE/pkg/client" "$ROOT_PACKAGE/pkg/apis" "$CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSION" -h /root/go/pkg/mod/k8s.io/code-generator\@v0.23.2-rc.0/hack/boilerplate.go.txt
+ set -o errexit
+ set -o nounset
+ set -o pipefail
+ '[' 6 -lt 4 ']'
+ '[' all == --help ']'
+ GENS=all
+ OUTPUT_PKG=/root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client
+ APIS_PKG=/root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis
+ GROUPS_WITH_VERSIONS=samplecrd:v1
+ shift 4
++ dirname ./generate-groups.sh
+ cd .
+ GO111MODULE=on
+ go install k8s.io/code-generator/cmd/defaulter-gen k8s.io/code-generator/cmd/client-gen k8s.io/code-generator/cmd/lister-gen k8s.io/code-generator/cmd/informer-gen k8s.io/code-generator/cmd/deepcopy-gen
++ go env GOBIN
+ GOBIN=
++ go env GOPATH
+ gobin=/root/go/bin
+ FQ_APIS=()
+ for GVs in '${GROUPS_WITH_VERSIONS}'
+ IFS=:
+ read -r G Vs
+ for V in '${Vs//,/ }'
+ FQ_APIS+=("${APIS_PKG}/${G}/${V}")
+ '[' all = all ']'
+ echo 'Generating deepcopy funcs'
Generating deepcopy funcs
++ codegen::join , /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/deepcopy-gen --input-dirs /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 -O zz_generated.deepcopy -h /root/go/pkg/mod/k8s.io/code-generator@v0.23.2-rc.0/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating clientset for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset'
Generating clientset for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset
++ codegen::join , /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/client-gen --clientset-name versioned --input-base '' --input /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --output-package /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset -h /root/go/pkg/mod/k8s.io/code-generator@v0.23.2-rc.0/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating listers for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/listers'
Generating listers for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/listers
++ codegen::join , /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/lister-gen --input-dirs /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --output-package /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/listers -h /root/go/pkg/mod/k8s.io/code-generator@v0.23.2-rc.0/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating informers for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/informers'
Generating informers for samplecrd:v1 at /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/informers
++ codegen::join , /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/informer-gen --input-dirs /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --versioned-clientset-package /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset/versioned --listers-package /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/listers --output-package /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/informers -h /root/go/pkg/mod/k8s.io/code-generator@v0.23.2-rc.0/hack/boilerplate.go.txt
# The informers package does not exist.
[root@k8s code-generator@v0.23.2-rc.0] ls /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/informers
ls: cannot access /root/go/src/github.com/resouer/k8s-controller-custom-resource/pkg/client/informers: No such file or directory
It does not produce any error when the informers package does not exist.
However, If I install the code-generator in the directory $GOPATH/src
, and run a similar command, then it works.
ROOT_PACKAGE="github.com/resouer/k8s-controller-custom-resource"
[root@k8s src] bash -x ./k8s.io/code-generator/generate-groups.sh all "$ROOT_PACKAGE/pkg/client" "$ROOT_PACKAGE/pkg/apis" "$CUSTOM_RESOURCE_NAME:$CUSTOM_RESOURCE_VERSION" -h /root/go/src/k8s.io/code-generator/hack/boilerplate.go.txt
+ set -o errexit
+ set -o nounset
+ set -o pipefail
+ '[' 6 -lt 4 ']'
+ '[' all == --help ']'
+ GENS=all
+ OUTPUT_PKG=github.com/resouer/k8s-controller-custom-resource/pkg/client
+ APIS_PKG=github.com/resouer/k8s-controller-custom-resource/pkg/apis
+ GROUPS_WITH_VERSIONS=samplecrd:v1
+ shift 4
++ dirname ./k8s.io/code-generator/generate-groups.sh
+ cd ./k8s.io/code-generator
+ GO111MODULE=on
+ go install k8s.io/code-generator/cmd/defaulter-gen k8s.io/code-generator/cmd/client-gen k8s.io/code-generator/cmd/lister-gen k8s.io/code-generator/cmd/informer-gen k8s.io/code-generator/cmd/deepcopy-gen
++ go env GOBIN
+ GOBIN=
++ go env GOPATH
+ gobin=/root/go/bin
+ FQ_APIS=()
+ for GVs in '${GROUPS_WITH_VERSIONS}'
+ IFS=:
+ read -r G Vs
+ for V in '${Vs//,/ }'
+ FQ_APIS+=("${APIS_PKG}/${G}/${V}")
+ '[' all = all ']'
+ echo 'Generating deepcopy funcs'
Generating deepcopy funcs
++ codegen::join , github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/deepcopy-gen --input-dirs github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 -O zz_generated.deepcopy -h /root/go/src/k8s.io/code-generator/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating clientset for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset'
Generating clientset for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset
++ codegen::join , github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/client-gen --clientset-name versioned --input-base '' --input github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --output-package github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset -h /root/go/src/k8s.io/code-generator/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating listers for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/listers'
Generating listers for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/listers
++ codegen::join , github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/lister-gen --input-dirs github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --output-package github.com/resouer/k8s-controller-custom-resource/pkg/client/listers -h /root/go/src/k8s.io/code-generator/hack/boilerplate.go.txt
+ '[' all = all ']'
+ echo 'Generating informers for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/informers'
Generating informers for samplecrd:v1 at github.com/resouer/k8s-controller-custom-resource/pkg/client/informers
++ codegen::join , github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
++ local IFS=,
++ shift
++ echo github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1
+ /root/go/bin/informer-gen --input-dirs github.com/resouer/k8s-controller-custom-resource/pkg/apis/samplecrd/v1 --versioned-clientset-package github.com/resouer/k8s-controller-custom-resource/pkg/client/clientset/versioned --listers-package github.com/resouer/k8s-controller-custom-resource/pkg/client/listers --output-package github.com/resouer/k8s-controller-custom-resource/pkg/client/informers -h /root/go/src/k8s.io/code-generator/hack/boilerplate.go.txt
Compare the worked process with the not worked process, the difference as I can see are:
- The
<output-package>
and<apis-package>
paths are different, but they all point to the same directory? the absolute path is more clear. - I move the code-generator to
$GOPATH/src
, which is in the same directory as my CRD code.
So my question:
- is it mandatory to put code-generator and CRD code in the src (or the same) directory?
- cannot code-generator use absolute path for and ? or it does not mean the path to the package, it means installed package literally.
- Does the code-generator have to run from
$GOPATH/src
, like this:./k8s.io/code-generator/generate-groups.sh
? and the and must relative path based on the work directory($GOPATH/src
)?
Thanks for any help and hint.