code-generator

root@ubuntu:~/controller101# bash hack/k8s/update-generated.sh 
Generating deepcopy funcs
F0708 14:32:21.192292   11530 main.go:82] Error: Failed making a parser: unable to add directory "pkg/apis/cloudnative/v1alpha1": unable to import "pkg/apis/cloudnative/v1alpha1": package pkg/apis/cloudnative/v1alpha1 is not in GOROOT (/usr/local/go/src/pkg/apis/cloudnative/v1alpha1)
root@ubuntu:~/controller101# find  /opt/gopath/src  -name code-generator
/opt/gopath/src/k8s.io/code-generator
/opt/gopath/src/k8s.io/kubernetes/vendor/k8s.io/code-generator
/opt/gopath/src/k8s.io/kubernetes/staging/src/k8s.io/code-generator
/opt/gopath/src/github.com/kata-containers/runtime.bak/vendor/k8s.io/kubernetes/staging/src/k8s.io/code-generator
/opt/gopath/src/github.com/kata-containers/runtime/vendor/k8s.io/kubernetes/staging/src/k8s.io/code-generator
/opt/gopath/src/github.com/kubeedge/vendor/k8s.io/code-generator
/opt/gopath/src/github.com/kubeedge/LICENSES/vendor/k8s.io/code-generator
root@ubuntu:~/controller101# rm  -rf /opt/gopath/src/k8s.io/code-generator
root@ubuntu:~/controller101# bash hack/k8s/update-generated.sh 
Generating deepcopy funcs
F0708 14:37:59.244411   16836 main.go:82] Error: Failed making a parser: unable to add directory "pkg/apis/cloudnative/v1alpha1": unable to import "pkg/apis/cloudnative/v1alpha1": package pkg/apis/cloudnative/v1alpha1 is not in GOROOT (/usr/local/go/src/pkg/apis/cloudnative/v1alpha1)
root@ubuntu:~/controller101# GO111MODULE=off bash hack/k8s/update-generated.sh 
cmd/defaulter-gen/main.go:48:2: cannot find package "github.com/spf13/pflag" in any of:
        /usr/local/go/src/github.com/spf13/pflag (from $GOROOT)
        /opt/gopath/src/github.com/spf13/pflag (from $GOPATH)
cmd/defaulter-gen/main.go:53:2: cannot find package "k8s.io/code-generator/cmd/defaulter-gen/args" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/defaulter-gen/args (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/defaulter-gen/args (from $GOPATH)
cmd/defaulter-gen/main.go:54:2: cannot find package "k8s.io/code-generator/pkg/util" in any of:
        /usr/local/go/src/k8s.io/code-generator/pkg/util (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/pkg/util (from $GOPATH)
cmd/defaulter-gen/main.go:49:2: cannot find package "k8s.io/gengo/args" in any of:
        /usr/local/go/src/k8s.io/gengo/args (from $GOROOT)
        /opt/gopath/src/k8s.io/gengo/args (from $GOPATH)
cmd/defaulter-gen/main.go:50:2: cannot find package "k8s.io/gengo/examples/defaulter-gen/generators" in any of:
        /usr/local/go/src/k8s.io/gengo/examples/defaulter-gen/generators (from $GOROOT)
        /opt/gopath/src/k8s.io/gengo/examples/defaulter-gen/generators (from $GOPATH)
cmd/defaulter-gen/main.go:51:2: cannot find package "k8s.io/klog" in any of:
        /usr/local/go/src/k8s.io/klog (from $GOROOT)
        /opt/gopath/src/k8s.io/klog (from $GOPATH)
cmd/client-gen/main.go:28:2: cannot find package "k8s.io/code-generator/cmd/client-gen/args" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/client-gen/args (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/client-gen/args (from $GOPATH)
cmd/client-gen/main.go:29:2: cannot find package "k8s.io/code-generator/cmd/client-gen/generators" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/client-gen/generators (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/client-gen/generators (from $GOPATH)
cmd/lister-gen/main.go:29:2: cannot find package "k8s.io/code-generator/cmd/lister-gen/args" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/lister-gen/args (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/lister-gen/args (from $GOPATH)
cmd/lister-gen/main.go:24:2: cannot find package "k8s.io/code-generator/cmd/lister-gen/generators" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/lister-gen/generators (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/lister-gen/generators (from $GOPATH)
cmd/informer-gen/main.go:29:2: cannot find package "k8s.io/code-generator/cmd/informer-gen/args" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/informer-gen/args (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/informer-gen/args (from $GOPATH)
cmd/informer-gen/main.go:24:2: cannot find package "k8s.io/code-generator/cmd/informer-gen/generators" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/informer-gen/generators (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/informer-gen/generators (from $GOPATH)
cmd/deepcopy-gen/main.go:54:2: cannot find package "k8s.io/code-generator/cmd/deepcopy-gen/args" in any of:
        /usr/local/go/src/k8s.io/code-generator/cmd/deepcopy-gen/args (from $GOROOT)
        /opt/gopath/src/k8s.io/code-generator/cmd/deepcopy-gen/args (from $GOPATH)
cmd/deepcopy-gen/main.go:51:2: cannot find package "k8s.io/gengo/examples/deepcopy-gen/generators" in any of:
        /usr/local/go/src/k8s.io/gengo/examples/deepcopy-gen/generators (from $GOROOT)
        /opt/gopath/src/k8s.io/gengo/examples/deepcopy-gen/generators (from $GOPATH)
root@ubuntu:~/controller101# bash hack/k8s/update-generated.sh 
Generating deepcopy funcs
F0708 14:39:04.639219   18016 main.go:82] Error: Failed making a parser: unable to add directory "pkg/apis/cloudnative/v1alpha1": unable to import "pkg/apis/cloudnative/v1alpha1": package pkg/apis/cloudnative/v1alpha1 is not in GOROOT (/usr/local/go/src/pkg/apis/cloudnative/v1alpha1)

原来是update-generated.sh 改动了

root@ubuntu:~/controller101# vi  hack/k8s/update-generated.sh 
#!/usr/bin/env bash

# Copyright © 2019 The controller101 Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" 
  pkg/generated 
  pkg/apis 
  "cloudnative:v1alpha1" 
  --output-base "$(dirname ${BASH_SOURCE})/../../../../../" 
  --go-header-file ${SCRIPT_ROOT}/hack/k8s/boilerplate.go.txt
root@ubuntu:~/controller101# cat hack/k8s/update-generated.sh 
#!/usr/bin/env bash

# Copyright © 2019 The controller101 Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" 
  github.com/cloud-native-taiwan/controller101/pkg/generated 
  github.com/cloud-native-taiwan/controller101/pkg/apis 
  "cloudnative:v1alpha1" 
  --output-base "$(dirname ${BASH_SOURCE})/../../../../../" 
  --go-header-file ${SCRIPT_ROOT}/hack/k8s/boilerplate.go.txtroot
root@ubuntu:~/controller101# bash hack/k8s/update-generated.sh 
Generating deepcopy funcs
Generating clientset for cloudnative:v1alpha1 at github.com/cloud-native-taiwan/controller101/pkg/generated/clientset
Generating listers for cloudnative:v1alpha1 at github.com/cloud-native-taiwan/controller101/pkg/generated/listers
Generating informers for cloudnative:v1alpha1 at github.com/cloud-native-taiwan/controller101/pkg/generated/informers
原文地址:https://www.cnblogs.com/dream397/p/14986068.html