[zh-cn] sync comments in /examples/examples_test.go
This commit is contained in:
@@ -61,7 +61,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/capabilities"
|
"k8s.io/kubernetes/pkg/capabilities"
|
||||||
"k8s.io/kubernetes/pkg/registry/batch/job"
|
"k8s.io/kubernetes/pkg/registry/batch/job"
|
||||||
|
|
||||||
// initialize install packages
|
// 初始化安装包
|
||||||
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
_ "k8s.io/kubernetes/pkg/apis/apps/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
|
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/batch/install"
|
_ "k8s.io/kubernetes/pkg/apis/batch/install"
|
||||||
@@ -77,18 +77,18 @@ var (
|
|||||||
serializer runtime.SerializerInfo
|
serializer runtime.SerializerInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestGroup contains GroupVersion to uniquely identify the API
|
// TestGroup 包含 GroupVersion 以唯一地标识该 API
|
||||||
type TestGroup struct {
|
type TestGroup struct {
|
||||||
externalGroupVersion schema.GroupVersion
|
externalGroupVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupVersion makes copy of schema.GroupVersion
|
// GroupVersion 制作 schema.GroupVersion 的副本
|
||||||
func (g TestGroup) GroupVersion() *schema.GroupVersion {
|
func (g TestGroup) GroupVersion() *schema.GroupVersion {
|
||||||
copyOfGroupVersion := g.externalGroupVersion
|
copyOfGroupVersion := g.externalGroupVersion
|
||||||
return ©OfGroupVersion
|
return ©OfGroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Codec returns the codec for the API version to test against
|
// Codec 为要测试的 API 版本返回编解码器
|
||||||
func (g TestGroup) Codec() runtime.Codec {
|
func (g TestGroup) Codec() runtime.Codec {
|
||||||
if serializer.Serializer == nil {
|
if serializer.Serializer == nil {
|
||||||
return legacyscheme.Codecs.LegacyCodec(g.externalGroupVersion)
|
return legacyscheme.Codecs.LegacyCodec(g.externalGroupVersion)
|
||||||
@@ -136,7 +136,7 @@ func getCodecForObject(obj runtime.Object) (runtime.Codec, error) {
|
|||||||
return group.Codec(), nil
|
return group.Codec(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Codec used for unversioned types
|
// 还未版本化的类别所用的 Codec
|
||||||
if legacyscheme.Scheme.Recognizes(kind) {
|
if legacyscheme.Scheme.Recognizes(kind) {
|
||||||
serializer, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
serializer, ok := runtime.SerializerInfoForMediaType(legacyscheme.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -160,7 +160,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
AllowPodAffinityNamespaceSelector: true,
|
AllowPodAffinityNamespaceSelector: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable CustomPodDNS for testing
|
// 为测试启用 CustomPodDNS
|
||||||
// feature.DefaultFeatureGate.Set("CustomPodDNS=true")
|
// feature.DefaultFeatureGate.Set("CustomPodDNS=true")
|
||||||
switch t := obj.(type) {
|
switch t := obj.(type) {
|
||||||
case *api.ConfigMap:
|
case *api.ConfigMap:
|
||||||
@@ -230,7 +230,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
// handle clusterIPs, logic copied from service strategy
|
// 处理几个 ClusterIP,根据服务策略进行逻辑复制
|
||||||
if len(t.Spec.ClusterIP) > 0 && len(t.Spec.ClusterIPs) == 0 {
|
if len(t.Spec.ClusterIP) > 0 && len(t.Spec.ClusterIPs) == 0 {
|
||||||
t.Spec.ClusterIPs = []string{t.Spec.ClusterIP}
|
t.Spec.ClusterIPs = []string{t.Spec.ClusterIP}
|
||||||
}
|
}
|
||||||
@@ -258,8 +258,8 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
if t.Namespace == "" {
|
if t.Namespace == "" {
|
||||||
t.Namespace = api.NamespaceDefault
|
t.Namespace = api.NamespaceDefault
|
||||||
}
|
}
|
||||||
// Job needs generateSelector called before validation, and job.Validate does this.
|
// Job 需要在校验前调用 generateSelector,然后 job.Validate 执行校验。
|
||||||
// See: https://github.com/kubernetes/kubernetes/issues/20951#issuecomment-187787040
|
// 请参阅:https://github.com/kubernetes/kubernetes/issues/20951#issuecomment-187787040
|
||||||
t.ObjectMeta.UID = types.UID("fakeuid")
|
t.ObjectMeta.UID = types.UID("fakeuid")
|
||||||
if strings.Index(t.ObjectMeta.Name, "$") > -1 {
|
if strings.Index(t.ObjectMeta.Name, "$") > -1 {
|
||||||
t.ObjectMeta.Name = "skip-for-good"
|
t.ObjectMeta.Name = "skip-for-good"
|
||||||
@@ -315,13 +315,13 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
}
|
}
|
||||||
errors = policy_validation.ValidatePodDisruptionBudget(t)
|
errors = policy_validation.ValidatePodDisruptionBudget(t)
|
||||||
case *rbac.ClusterRole:
|
case *rbac.ClusterRole:
|
||||||
// clusterole does not accept namespace
|
// ClusterRole 不接受名字空间
|
||||||
errors = rbac_validation.ValidateClusterRole(t)
|
errors = rbac_validation.ValidateClusterRole(t)
|
||||||
case *rbac.ClusterRoleBinding:
|
case *rbac.ClusterRoleBinding:
|
||||||
// clusterolebinding does not accept namespace
|
// ClusterRoleBinding 不接受名字空间
|
||||||
errors = rbac_validation.ValidateClusterRoleBinding(t)
|
errors = rbac_validation.ValidateClusterRoleBinding(t)
|
||||||
case *storage.StorageClass:
|
case *storage.StorageClass:
|
||||||
// storageclass does not accept namespace
|
// StorageClass 不接受名字空间
|
||||||
errors = storage_validation.ValidateStorageClass(t)
|
errors = storage_validation.ValidateStorageClass(t)
|
||||||
default:
|
default:
|
||||||
errors = field.ErrorList{}
|
errors = field.ErrorList{}
|
||||||
@@ -330,8 +330,8 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walks inDir for any json/yaml files. Converts yaml to json, and calls fn for
|
// 遍历 inDir 目录查找所有 json/yaml 文件。将 yaml 转换为 json,
|
||||||
// each file found with the contents in data.
|
// 并根据 data 中的内容找到的每个文件来调用 fn。
|
||||||
func walkConfigFiles(inDir string, t *testing.T, fn func(name, path string, data [][]byte)) error {
|
func walkConfigFiles(inDir string, t *testing.T, fn func(name, path string, data [][]byte)) error {
|
||||||
return filepath.Walk(inDir, func(path string, info os.FileInfo, err error) error {
|
return filepath.Walk(inDir, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -352,7 +352,7 @@ func walkConfigFiles(inDir string, t *testing.T, fn func(name, path string, data
|
|||||||
|
|
||||||
var docs [][]byte
|
var docs [][]byte
|
||||||
if ext == ".yaml" {
|
if ext == ".yaml" {
|
||||||
// YAML can contain multiple documents.
|
// YAML 可以包含多个文档。
|
||||||
splitter := yaml.NewYAMLReader(bufio.NewReader(bytes.NewBuffer(data)))
|
splitter := yaml.NewYAMLReader(bufio.NewReader(bytes.NewBuffer(data)))
|
||||||
for {
|
for {
|
||||||
doc, err := splitter.Read()
|
doc, err := splitter.Read()
|
||||||
@@ -366,7 +366,7 @@ func walkConfigFiles(inDir string, t *testing.T, fn func(name, path string, data
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s: %v", path, err)
|
return fmt.Errorf("%s: %v", path, err)
|
||||||
}
|
}
|
||||||
// deal with "empty" document (e.g. pure comments)
|
// 处理 "空白" 文档(例如纯注释)
|
||||||
if string(out) != "null" {
|
if string(out) != "null" {
|
||||||
docs = append(docs, out)
|
docs = append(docs, out)
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,7 @@ func walkConfigFiles(inDir string, t *testing.T, fn func(name, path string, data
|
|||||||
func TestExampleObjectSchemas(t *testing.T) {
|
func TestExampleObjectSchemas(t *testing.T) {
|
||||||
initGroups()
|
initGroups()
|
||||||
|
|
||||||
// Please help maintain the alphabeta order in the map
|
// 请帮助保持映射图中的 alphabeta 顺序
|
||||||
cases := map[string]map[string][]runtime.Object{
|
cases := map[string]map[string][]runtime.Object{
|
||||||
"admin": {
|
"admin": {
|
||||||
"namespace-dev": {&api.Namespace{}},
|
"namespace-dev": {&api.Namespace{}},
|
||||||
@@ -691,7 +691,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note a key in the following map has to be complete relative path
|
// 请注意,以下映射中的某个键必须是完整的相对路径
|
||||||
filesIgnore := map[string]map[string]bool{
|
filesIgnore := map[string]map[string]bool{
|
||||||
"audit": {
|
"audit": {
|
||||||
"audit-policy": true,
|
"audit-policy": true,
|
||||||
@@ -705,7 +705,7 @@ func TestExampleObjectSchemas(t *testing.T) {
|
|||||||
tested := 0
|
tested := 0
|
||||||
numExpected := 0
|
numExpected := 0
|
||||||
path := dir
|
path := dir
|
||||||
// Test if artifacts do exist
|
// 测试这些工件是否存在
|
||||||
for name := range expected {
|
for name := range expected {
|
||||||
fn := path + "/" + name
|
fn := path + "/" + name
|
||||||
_, err1 := os.Stat(fn + ".yaml")
|
_, err1 := os.Stat(fn + ".yaml")
|
||||||
|
|||||||
Reference in New Issue
Block a user