-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aylei <rayingecho@gmail.com>
- Loading branch information
Showing
37 changed files
with
2,351 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ vendor | |
tests/e2e/e2e.test | ||
.orig | ||
tkc | ||
|
||
apiserver.local.config/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2016 The Kubernetes 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. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
_ "github.com/go-openapi/loads" | ||
_ "github.com/ugorji/go/codec" | ||
"k8s.io/client-go/rest" | ||
|
||
"github.com/pingcap/tidb-operator/pkg/apiserver/cmd" | ||
"github.com/pingcap/tidb-operator/pkg/version" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth" // Enable cloud provider auth | ||
) | ||
|
||
func main() { | ||
restConfig, err := rest.InClusterConfig() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
cmd.StartApiServer(restConfig, "default", nil, nil, "Api", version.Get().GitVersion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Adding New Resources in TiDB Aggregated Apiserver | ||
|
||
> This guide shows an example about how to add new resources in TiDB Aggregated Apiserver (AA) | ||
## Project Structure | ||
|
||
```shell | ||
pkg/apiserver # package root of AA | ||
pkg/apiserver/apis # all apis of AA | ||
pkg/apiserver/apis/{group}/ # un-versioned apis of a group | ||
pkg/apiserver/apis/{group}/{version} # versiond apis of a group | ||
pkg/apiserver/apis/{group}/{version}/{kind}_types.go # type definition of a certain kind | ||
pkg/apiserver/client # generated go client | ||
pkg/apiserver/cmd # AA entrypoint | ||
pkg/apiserver/openapi # generated openapi definition | ||
pkg/apiserver/storage # kube-apiserver based storage implementation | ||
``` | ||
|
||
We will create the type definition of a versioned resource in `pkg/apiserver/apis/{group}/{version}/{kind}_types.go`. | ||
|
||
The defaults function, conversion from un-versioned to versioned, OpenAPI definition and client of the versioned resource will be generated automatically. | ||
|
||
The type definition, REST storage, defaults function, conversion from versioned to un-versioned and client of the un-versioned resources will also be generated automatically. | ||
|
||
## Foo Example | ||
|
||
Let's add a new resource `foos.v1alpha1.tidb.pingcap.com`: | ||
|
||
- `kind`: foos | ||
- `version`: v1alpha1 | ||
- `group`: tidb.pingcap.com | ||
|
||
1. Create packages: | ||
|
||
```shell | ||
$ mkdir -p pkg/apiserver/apis/tidb/v1alpha1 | ||
``` | ||
|
||
**By convention, we take the sub domain of the group name as the package name.** | ||
|
||
2. Write group name and code-generation markers for all resources under `v1alpha.tidb.pingcap.com`: | ||
|
||
`pkg/apiserver/apis/tidb/v1alpha1/doc.go` | ||
|
||
``` | ||
// +k8s:openapi-gen=true | ||
// +k8s:deepcopy-gen=package,register | ||
// +k8s:conversion-gen=github.com/pingcap/tidb-operator/pkg/apiserver/apis/tidb | ||
// +k8s:defaulter-gen=TypeMeta | ||
// +groupName=tidb.pingcap.com | ||
package v1alpha1 // import "github.com/pingcap/tidb-operator/pkg/apiserver/apis/tidb/v1alpha1" | ||
``` | ||
|
||
3. Write the type definition and code generation markers for Foo: | ||
|
||
`pkg/apiserver/apis/tidb/v1alpha1/foo_types.go`: | ||
|
||
```go | ||
// +genclient | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// Foo | ||
// +k8s:openapi-gen=true | ||
// +resource:path=foos | ||
type Foo struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec FooSpec `json:"spec,omitempty"` | ||
Status FooStatus `json:"status,omitempty"` | ||
} | ||
|
||
// FooSpec defines the desired state of Foo | ||
type FooSpec struct { | ||
Replicas int `json:"replicas,omitempty"` | ||
} | ||
|
||
// FooStatus defines the observed state of Foo | ||
type FooStatus struct { | ||
CurrentReplicas int `json:"currentReplicas,omitempty"` | ||
} | ||
``` | ||
|
||
4. Run code generation: | ||
|
||
``` | ||
./hack/code-gen.sh | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.