Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCP: support setting discovery resources #2434

Merged
merged 20 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,19 @@ TidbClusterSpec
<table>
<tr>
<td>
<code>discovery</code></br>
<em>
<a href="#discoveryspec">
DiscoverySpec
</a>
</em>
</td>
<td>
<p>Discovery spec</p>
</td>
</tr>
<tr>
<td>
<code>pd</code></br>
<em>
<a href="#pdspec">
Expand Down Expand Up @@ -3256,6 +3269,39 @@ string
</tr>
</tbody>
</table>
<h3 id="discoveryspec">DiscoverySpec</h3>
<p>
(<em>Appears on:</em>
<a href="#tidbclusterspec">TidbClusterSpec</a>)
</p>
<p>
<p>DiscoverySpec contains details of Discovery members</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>ResourceRequirements</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#resourcerequirements-v1-core">
Kubernetes core/v1.ResourceRequirements
</a>
</em>
</td>
<td>
<p>
(Members of <code>ResourceRequirements</code> are embedded into this type.)
</p>
</td>
</tr>
</tbody>
</table>
<h3 id="experimental">Experimental</h3>
<p>
(<em>Appears on:</em>
Expand Down Expand Up @@ -14582,6 +14628,19 @@ string
<tbody>
<tr>
<td>
<code>discovery</code></br>
<em>
<a href="#discoveryspec">
DiscoverySpec
</a>
</em>
</td>
<td>
<p>Discovery spec</p>
</td>
</tr>
<tr>
<td>
<code>pd</code></br>
<em>
<a href="#pdspec">
Expand Down
7 changes: 7 additions & 0 deletions examples/basic/tidb-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ spec:
version: v3.0.13
timezone: UTC
pvReclaimPolicy: Delete
discovery:
limits:
cpu: 250m
memory: 150Mi
requests:
cpu: 80m
memory: 50Mi
pd:
baseImage: pingcap/pd
replicas: 3
Expand Down
7 changes: 7 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ spec:
type: object
configUpdateStrategy:
type: string
discovery:
properties:
limits:
type: object
requests:
type: object
type: object
enablePVReclaim:
type: boolean
helper:
Expand Down
52 changes: 51 additions & 1 deletion pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type TidbClusterList struct {
// +k8s:openapi-gen=true
// TidbClusterSpec describes the attributes that a user creates on a tidb cluster
type TidbClusterSpec struct {
// Discovery spec
Discovery DiscoverySpec `json:"discovery,omitempty"`

// PD cluster spec
PD PDSpec `json:"pd"`

Expand Down Expand Up @@ -258,6 +261,12 @@ const (
TidbClusterReady TidbClusterConditionType = "Ready"
)

// +k8s:openapi-gen=true
// DiscoverySpec contains details of Discovery members
type DiscoverySpec struct {
corev1.ResourceRequirements `json:",inline"`
}

// +k8s:openapi-gen=true
// PDSpec contains details of PD members
type PDSpec struct {
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/manager/member/tidb_discovery_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func getTidbDiscoveryDeployment(tc *v1alpha1.TidbCluster) (*appsv1.Deployment, e
Spec: corev1.PodSpec{
ServiceAccountName: meta.Name,
Containers: []corev1.Container{{
Name: "discovery",
Name: "discovery",
Resources: controller.ContainerResource(tc.Spec.Discovery.ResourceRequirements),
shonge marked this conversation as resolved.
Show resolved Hide resolved
Command: []string{
"/usr/local/bin/tidb-discovery",
},
Expand Down
37 changes: 37 additions & 0 deletions pkg/manager/member/tidb_discovery_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
"github.com/pingcap/tidb-operator/pkg/controller"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

func TestTidbDiscoveryManager_Reconcile(t *testing.T) {
Expand Down Expand Up @@ -59,6 +61,41 @@ func TestTidbDiscoveryManager_Reconcile(t *testing.T) {
},
errOnCreateOrUpdate: false,
},
{
name: "Setting discovery resource",
prepare: func(tc *v1alpha1.TidbCluster, ctrl *controller.FakeGenericControl) {
tc.Spec.Discovery.ResourceRequirements = corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
corev1.ResourceEphemeralStorage: resource.MustParse("10Gi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
corev1.ResourceEphemeralStorage: resource.MustParse("10Gi"),
},
}
},
expect: func(deploys []appsv1.Deployment, tc *v1alpha1.TidbCluster, err error) {
g.Expect(err).To(Succeed())
g.Expect(deploys).To(HaveLen(1))
g.Expect(deploys[0].Spec.Template.Spec.Containers[0].Resources).To(Equal(corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
corev1.ResourceEphemeralStorage: resource.MustParse("10Gi"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
corev1.ResourceEphemeralStorage: resource.MustParse("10Gi"),
},
}))
g.Expect(deploys[0].Name).To((Equal("test-discovery")))
},
errOnCreateOrUpdate: false,
},
{
name: "Create or update resource error",
expect: func(deploys []appsv1.Deployment, tc *v1alpha1.TidbCluster, err error) {
Expand Down
32 changes: 18 additions & 14 deletions tests/e2e/tidbcluster/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,20 +1288,24 @@ func newTidbClusterConfig(cfg *tests.Config, ns, clusterName, password, tidbVers
BackupSecretName: fmt.Sprintf("%s-backup-secret", clusterName),
BackupName: "backup",
Resources: map[string]string{
"pd.resources.limits.cpu": "1000m",
"pd.resources.limits.memory": "2Gi",
"pd.resources.requests.cpu": "20m",
"pd.resources.requests.memory": "20Mi",
"tikv.resources.limits.cpu": "2000m",
"tikv.resources.limits.memory": "4Gi",
"tikv.resources.requests.cpu": "20m",
"tikv.resources.requests.memory": "20Mi",
"tidb.resources.limits.cpu": "2000m",
"tidb.resources.limits.memory": "4Gi",
"tidb.resources.requests.cpu": "20m",
"tidb.resources.requests.memory": "20Mi",
"tidb.initSql": strconv.Quote("create database e2e;"),
"discovery.image": cfg.OperatorImage,
"discovery.resources.limits.cpu": "1000m",
"discovery.resources.limits.memory": "2Gi",
"discovery.resources.requests.cpu": "20m",
"discovery.resources.requests.memory": "20Mi",
"pd.resources.limits.cpu": "1000m",
"pd.resources.limits.memory": "2Gi",
"pd.resources.requests.cpu": "20m",
"pd.resources.requests.memory": "20Mi",
"tikv.resources.limits.cpu": "2000m",
"tikv.resources.limits.memory": "4Gi",
"tikv.resources.requests.cpu": "20m",
"tikv.resources.requests.memory": "20Mi",
"tidb.resources.limits.cpu": "2000m",
"tidb.resources.limits.memory": "4Gi",
"tidb.resources.requests.cpu": "20m",
"tidb.resources.requests.memory": "20Mi",
"tidb.initSql": strconv.Quote("create database e2e;"),
"discovery.image": cfg.OperatorImage,
},
Args: map[string]string{},
Monitor: true,
Expand Down