1. 程式人生 > >kubernetes 程式碼編譯包 undefined: "k8s.io/kubernetes/pkg/generated/openapi".GetOpenAPIDefinitions 的解決辦法

kubernetes 程式碼編譯包 undefined: "k8s.io/kubernetes/pkg/generated/openapi".GetOpenAPIDefinitions 的解決辦法

今天編譯kubernetes某個具體的組建的時候 包了這個錯,報錯詳情如下

➜  kube-apiserver git:(v1.11.2-custom) ✗ go run apiserver.go 
# k8s.io/kubernetes/cmd/kube-apiserver/app
app/server.go:436:70: undefined: "k8s.io/kubernetes/pkg/generated/openapi".GetOpenAPIDefinitions

檢視這個目錄存在的

➜  kubernetes git:(v1.11.2-custom) ✗ ls -l pkg/generated/openapi         
total 24
-rw-r--r--  1 xinzhiyun  staff  3309  8 13 18:23 BUILD
-rw-r--r--  1 xinzhiyun  staff  2128  8 13 18:23 def.bzl
-rw-r--r--  1 xinzhiyun  staff   621  8 13 17:35 doc.go

確實沒有相關的函式GetOpenAPIDefinitions

檢視Makefile的內容

➜  kubernetes git:(v1.11.2-custom) ✗ cat Makefile | grep generated_files
all: generated_files
verify: verify_generated_files
quick-verify: verify_generated_files
update: generated_files
check test: generated_files
test-integration: generated_files
test-e2e: ginkgo generated_files
test-e2e-node: ginkgo generated_files
test-cmd: generated_files
# generated using generated_files.
vet: generated_files
$(filter-out %$(EXCLUDE_TARGET),$(notdir $(abspath $(wildcard cmd/*/)))): generated_files
#   make generated_files
.PHONY: generated_files
generated_files:
generated_files:
	$(MAKE) -f Makefile.generated_files 
[email protected]
CALLED_FROM_MAIN_MAKEFILE=1 # make verify_generated_files .PHONY: verify_generated_files verify_generated_files: verify_generated_files: $(MAKE) -f Makefile.generated_files [email protected] CALLED_FROM_MAIN_MAKEFILE=1

發現需要執行該命令make generated_files

➜  kubernetes git:(v1.11.2-custom) ✗ make generated_files
+++ [1209 17:07:02] Building go targets for darwin/amd64:
    ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
+++ [1209 17:07:12] Building go targets for darwin/amd64:
    ./vendor/k8s.io/code-generator/cmd/defaulter-gen
+++ [1209 17:07:18] Building go targets for darwin/amd64:
    ./vendor/k8s.io/code-generator/cmd/conversion-gen
+++ [1209 17:07:25] Building go targets for darwin/amd64:
    ./vendor/k8s.io/code-generator/cmd/openapi-gen
+++ [1209 17:07:32] Building go targets for darwin/amd64:
    ./vendor/github.com/jteeuwen/go-bindata/go-bindata

執行之後
檢視是否生成新檔案

➜  kubernetes git:(v1.11.2-custom) ✗ ls -l pkg/generated/openapi
total 24
-rw-r--r--  1 xinzhiyun  staff  3309  8 13 18:23 BUILD
-rw-r--r--  1 xinzhiyun  staff  2128  8 13 18:23 def.bzl
-rw-r--r--  1 xinzhiyun  staff   621  8 13 17:35 doc.go
-rw-r--r--  1 xinzhiyun  staff     0 12  9 17:07 zz_generated.openapi.go

果然有新檔案生成zz_generated.openapi.go

然後重新編譯就可以了