Table of Contents generated with DocToc
environment:ubuntu 14.04 golang:1.7.1
k8s rebase to 1.5.1
代码 rebase 工作,解决冲突
这部分的东西也可以参考 kubernetes/Makefile 和 kubernetes/Makefile.generated_files 文件。
reference: api_changes.md
如果修改了 api 相关的代码,则需要重新生成 conversion 文件和 deepcopy 文件:
- pkg/api//conversion_generated.go
- pkg/apis/extensions//conversion_generated.go
- <path_to_versioned_api>/zz_generated.deepcopy.go
执行:
hack/update-codegen.sh
如果修改了 api 相关的代码,可能会涉及到 Protobuf IDL 和 marshallers,所以需要重新生成 protobuf objects
执行:
hack/update-generated-protobuf.sh
如果修改了 api 相关的代码,还需要重新生成 json (un)marshaling 代码
- pkg/api//types.generated.go
- pkg/apis/extensions//types.generated.go
执行:
hack/update-codecgen.sh
godep restore 的原理:将 <project_dir>/Godeps/Godeps.json 文件中指定的包通过 go get -d -v 来下载到 GOPATH 路径下。
所以,这里的步骤如下:
首先需要利用上游的 Godeps.json 来做 Godep restore。这一步将上游利用到的 package 全都下载到 GOPATH 路径下:
godep restore
然后,如果我们的代码用到了新的 package,我们也需要将这些 package 下载到 GOPATH 路径下:
go get -v xxxx/yyyy
# 由于我们接下来会做 godep save,所以不需要执行 godep update xxxx/yyyy 来更新 Godeps.json 文件。
godep save 的原理:在未指定包名的情况下,godep 会自动扫描当前目录所属包中 import 的所有外部依赖库(非系统库),并将这些依赖库代码拷贝(更新)到 vendor/ 目录下,然后将这些依赖库的当前对应的 revision(commit id)记录到 Godeps/Godeps.json 文件中。
这里执行:
hack/godep-save.sh
hack/build-go.sh
其实就是 make 命令。
单元测试最好在 linux 系统下跑(此时也需要在 linux 环境下做编译),如果在 mac 上跑,会出现比较多的问题:比如 shell 命令格式不兼容或者不一样,linux 上有的一些功能组件(apparmor、cgroup等) mac 上没有。
hack/test-go.sh
其实就是 make test 命令。
serialization_proto_test.go
测试不通过:
- 要么我们添加的 api 代码不对:重新查看和修改代码
- 没有重新生成 protobuf objects:重新执行 ### 重新生成 protobuf objects
修改好之后,可单独进行测试:
godep go test ./pkg/api
TestPidListerFailure
(in oom_linux_test.go
)测试不通过:很有可能是 linux 上未安装/启动 cgroup 服务。
TestCompatibility_v1_Scheduler
(in compatibility_test.go
)测试不通过:有可能是我们添加了新的 Predicate(in k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
),而没有在 k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/compatibility_test.go
中添加相关的测试代码。
curl -L https://github.com/coreos/etcd/releases/download/v3.0.15/etcd-v3.0.15-linux-amd64.tar.gz -o etcd-v3.0.15-linux-amd64.tar.gz
tar -xzvf etcd-v3.0.15-linux-amd64.tar.gz -C /usr/local/
ln -s /usr/local/etcd-v3.0.15-linux-amd64/etcd /usr/local/bin/etcd
ln -s /usr/local/etcd-v3.0.15-linux-amd64/etcdctl /usr/local/bin/etcdctl
ulimit -n 4096
./hack/test-integration.sh
其实就是 make test-integration 命令。
reference:
- https://github.com/kubernetes/community/blob/master/contributors/devel/e2e-tests.md
- https://github.com/kubernetes/kubernetes/tree/master/build
Note:
End-to-end (e2e) tests for Kubernetes provide a mechanism to test end-to-end behavior of the system, and is the last signal to ensure end user operations match developer specifications.
用 rebase 后新版本创建一个至少4个节点的 k8s 集群。
可以用 hack/e2e.go
来创建 k8s 集群,也可以自己手动创建一个 k8s 集群。
go run hack/e2e.go -v --build
在 master 机器上跑,最好是并行测试(加上 GINKGO_PARALLEL=y),速度快:
# Run all tests in parallel
GINKGO_PARALLEL=y KUBERNETES_PROVIDER=caicloud-baremetal go run hack/e2e.go --v --test
Note:
如果部署的 k8s 是已 https 访问,而证书又是自签证书,可能会出现如下问题:
Jan 21 01:33:48.277: INFO: Unexpected error listing nodes: Get https://192.168.16.37/api/v1/nodes?fieldSelector=spec.unschedulable%3Dfalse&resourceVersion=0: x509: certificate signed by unknown authority
那么,解决办法如下:
# 通过 kubectl config get-clusters 获取 cluster_name
# 在 master 上执行如下命令,~/.kube/config 也会被自动更新
kubectl config set-cluster <cluster name> --insecure-skip-tls-verify=true --server=https://<server_ip:port>
上面的这个命令和每次执行 kubectl
时加上参数 --insecure-skip-tls-verify=true
的效果时一样的。
根据 e2e 测试的结果修改 bug 吧。