Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#133 from lhb008/zh
Browse files Browse the repository at this point in the history
翻译1.5.1 A Brief Aside: What's the rest of this stuff?
  • Loading branch information
mergify[bot] committed Jul 30, 2020
2 parents ce0b8cd + 4fa0c50 commit e79896c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
26 changes: 10 additions & 16 deletions docs/book/src/cronjob-tutorial/other-api-files.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# A Brief Aside: What's the rest of this stuff?
# 简要说明: 剩下文件的作用?

If you've taken a peek at the rest of the files in the
[`api/v1/`](https://sigs.k8s.io/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/api/v1)
directory, you might have noticed two additional files beyond
`cronjob_types.go`: `groupversion_info.go` and `zz_generated.deepcopy.go`.
如果你在 [`api/v1/`](https://sigs.k8s.io/kubebuilder/docs/book/src/cronjob-tutorial/testdata/project/api/v1) 目录下看到了其他文件,
你可能会注意到除了 `cronjob_types.go` 这个文件外,还有两个文件:`groupversion_info.go``zz_generated.deepcopy.go`

Neither of these files ever needs to be edited (the former stays the same
and the latter is autogenerated), but it's useful to know what's in them.

虽然这些文件都不需要编辑(前者保持原样,而后者是自动生成的),但是如果知道这些文件的内容,那么将是非常有用的。

## `groupversion_info.go`

`groupversion_info.go` contains common metadata about the group-version:
`groupversion_info.go` 包含了关于 group-version 的一些元数据:

{{#literatego ./testdata/project/api/v1/groupversion_info.go}}

## `zz_generated.deepcopy.go`

`zz_generated.deepcopy.go` contains the autogenerated implementation of
the aforementioned `runtime.Object` interface, which marks all of our root
types as representing Kinds.
`zz_generated.deepcopy.go` 包含了前述 `runtime.Object` 接口的自动实现,这些实现标记了代表 `Kinds` 的所有根类型。

The core of the `runtime.Object` interface is a deep-copy method,
`DeepCopyObject`.
`runtime.Object` 接口的核心是一个深拷贝方法,即 `DeepCopyObject`

The `object` generator in controller-tools also generates two other handy
methods for each root type and all its sub-types: `DeepCopy` and
`DeepCopyInto`.
controller-tools 中的 `object` 生成器也能够为每一个根类型以及其子类型生成另外两个易用的方法:`DeepCopy`
`DeepCopyInto`
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ limitations under the License.
*/
// +kubebuilder:docs-gen:collapse=Apache License

/*
First, we have some *package-level* markers that denote that there are
Kubernetes objects in this package, and that this package represents the group
`batch.tutorial.kubebuilder.io`. The `object` generator makes use of the
former, while the latter is used by the CRD generator to generate the right
metadata for the CRDs it creates from this package.
/*
首先,我们有一些*包*级别的标记的标记,表示存在这个包中的 Kubernetes 对象,并且这个包表示 `batch.tutorial.kubebuilder.io` 组。`object` 生成器使用前者,而后者是由 CRD 生成器来生成的,它会从这个包创建 CRD 的元数据。
*/

// Package v1 contains API Schema definitions for the batch v1 API group
// v1 包含了 batch v1 API 这个组的 API Schema 定义。
// +kubebuilder:object:generate=true
// +groupName=batch.tutorial.kubebuilder.io
package v1
Expand All @@ -33,18 +29,17 @@ import (
)

/*
Then, we have the commonly useful variables that help us set up our Scheme.
Since we need to use all the types in this package in our controller, it's
helpful (and the convention) to have a convenient method to add all the types to
some other `Scheme`. SchemeBuilder makes this easy for us.
然后,我们有一些常见且常用的变量来帮助我们设置我们的 Scheme 。因为我们需要在这个包的 controller 中用到所有的类型,
用一个方便的方法给其他 `Scheme` 来添加所有的类型,是非常有用的(而且也是一种惯例)。SchemeBuilder 能够帮助我们轻松的实现这个事情。
*/

var (
// GroupVersion is group version used to register these objects
// GroupVersion 是用来注册这些对象的 group version
GroupVersion = schema.GroupVersion{Group: "batch.tutorial.kubebuilder.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder 被用来给 GroupVersionKind scheme 添加 go 类型。
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
// AddToScheme group-version 中的类型添加到指定的 scheme 中。
AddToScheme = SchemeBuilder.AddToScheme
)

0 comments on commit e79896c

Please sign in to comment.