diff --git a/docs/api-references/docs.md b/docs/api-references/docs.md index a69a46c90c..fd08c0cc12 100644 --- a/docs/api-references/docs.md +++ b/docs/api-references/docs.md @@ -705,6 +705,19 @@ TidbClusterSpec + + + +
+discovery
+ + +DiscoverySpec + + +
+

Discovery spec

+
pd
@@ -3256,6 +3269,39 @@ string
+

DiscoverySpec

+

+(Appears on: +TidbClusterSpec) +

+

+

DiscoverySpec contains details of Discovery members

+

+ + + + + + + + + + + + + +
FieldDescription
+ResourceRequirements
+ + +Kubernetes core/v1.ResourceRequirements + + +
+

+(Members of ResourceRequirements are embedded into this type.) +

+

Experimental

(Appears on: @@ -14582,6 +14628,19 @@ string +discovery
+ + +DiscoverySpec + + + + +

Discovery spec

+ + + + pd
diff --git a/examples/basic/tidb-cluster.yaml b/examples/basic/tidb-cluster.yaml index d83cbdb360..dd33bbff84 100644 --- a/examples/basic/tidb-cluster.yaml +++ b/examples/basic/tidb-cluster.yaml @@ -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 diff --git a/manifests/crd.yaml b/manifests/crd.yaml index c24c303ee8..6d5c88ce1c 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -334,6 +334,13 @@ spec: type: object configUpdateStrategy: type: string + discovery: + properties: + limits: + type: object + requests: + type: object + type: object enablePVReclaim: type: boolean helper: diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go index 77dcd3688f..f2f6092e27 100644 --- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go +++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go @@ -40,6 +40,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.CommonConfig": schema_pkg_apis_pingcap_v1alpha1_CommonConfig(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.ComponentSpec": schema_pkg_apis_pingcap_v1alpha1_ComponentSpec(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.ConfigMapRef": schema_pkg_apis_pingcap_v1alpha1_ConfigMapRef(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.DiscoverySpec": schema_pkg_apis_pingcap_v1alpha1_DiscoverySpec(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.Experimental": schema_pkg_apis_pingcap_v1alpha1_Experimental(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.ExternalEndpoint": schema_pkg_apis_pingcap_v1alpha1_ExternalEndpoint(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.FileLogConfig": schema_pkg_apis_pingcap_v1alpha1_FileLogConfig(ref), @@ -1212,6 +1213,49 @@ func schema_pkg_apis_pingcap_v1alpha1_ConfigMapRef(ref common.ReferenceCallback) } } +func schema_pkg_apis_pingcap_v1alpha1_DiscoverySpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "DiscoverySpec contains details of Discovery members", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "limits": { + SchemaProps: spec.SchemaProps{ + Description: "Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/apimachinery/pkg/api/resource.Quantity"), + }, + }, + }, + }, + }, + "requests": { + SchemaProps: spec.SchemaProps{ + Description: "Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/apimachinery/pkg/api/resource.Quantity"), + }, + }, + }, + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/api/resource.Quantity"}, + } +} + func schema_pkg_apis_pingcap_v1alpha1_Experimental(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -7879,6 +7923,12 @@ func schema_pkg_apis_pingcap_v1alpha1_TidbClusterSpec(ref common.ReferenceCallba Description: "TidbClusterSpec describes the attributes that a user creates on a tidb cluster", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "discovery": { + SchemaProps: spec.SchemaProps{ + Description: "Discovery spec", + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.DiscoverySpec"), + }, + }, "pd": { SchemaProps: spec.SchemaProps{ Description: "PD cluster spec", @@ -8051,7 +8101,7 @@ func schema_pkg_apis_pingcap_v1alpha1_TidbClusterSpec(ref common.ReferenceCallba }, }, Dependencies: []string{ - "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.HelperSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.PDSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.PumpSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TLSCluster", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiCDCSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiDBSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiFlashSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiKVSpec", "k8s.io/api/core/v1.Affinity", "k8s.io/api/core/v1.Toleration"}, + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.DiscoverySpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.HelperSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.PDSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.PumpSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TLSCluster", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiCDCSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiDBSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiFlashSpec", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiKVSpec", "k8s.io/api/core/v1.Affinity", "k8s.io/api/core/v1.Toleration"}, } } diff --git a/pkg/apis/pingcap/v1alpha1/types.go b/pkg/apis/pingcap/v1alpha1/types.go index d7d438e974..1e60ab6d09 100644 --- a/pkg/apis/pingcap/v1alpha1/types.go +++ b/pkg/apis/pingcap/v1alpha1/types.go @@ -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"` @@ -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 { diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go index e660420b9c..b81294b521 100644 --- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go @@ -870,6 +870,23 @@ func (in *DataResourceList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DiscoverySpec) DeepCopyInto(out *DiscoverySpec) { + *out = *in + in.ResourceRequirements.DeepCopyInto(&out.ResourceRequirements) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DiscoverySpec. +func (in *DiscoverySpec) DeepCopy() *DiscoverySpec { + if in == nil { + return nil + } + out := new(DiscoverySpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Experimental) DeepCopyInto(out *Experimental) { *out = *in @@ -6481,6 +6498,7 @@ func (in *TidbClusterRef) DeepCopy() *TidbClusterRef { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TidbClusterSpec) DeepCopyInto(out *TidbClusterSpec) { *out = *in + in.Discovery.DeepCopyInto(&out.Discovery) in.PD.DeepCopyInto(&out.PD) in.TiDB.DeepCopyInto(&out.TiDB) in.TiKV.DeepCopyInto(&out.TiKV) diff --git a/pkg/manager/member/tidb_discovery_manager.go b/pkg/manager/member/tidb_discovery_manager.go index f362724093..39393aae8d 100644 --- a/pkg/manager/member/tidb_discovery_manager.go +++ b/pkg/manager/member/tidb_discovery_manager.go @@ -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), Command: []string{ "/usr/local/bin/tidb-discovery", }, diff --git a/pkg/manager/member/tidb_discovery_manager_test.go b/pkg/manager/member/tidb_discovery_manager_test.go index 20ce8dfa59..26630ab860 100644 --- a/pkg/manager/member/tidb_discovery_manager_test.go +++ b/pkg/manager/member/tidb_discovery_manager_test.go @@ -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) { @@ -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) { diff --git a/tests/e2e/tidbcluster/tidbcluster.go b/tests/e2e/tidbcluster/tidbcluster.go index 41db578df1..8e3cd87694 100644 --- a/tests/e2e/tidbcluster/tidbcluster.go +++ b/tests/e2e/tidbcluster/tidbcluster.go @@ -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,