Skip to content

Commit

Permalink
Sync pd and tikv configmap in controller
Browse files Browse the repository at this point in the history
Signed-off-by: Aylei <rayingecho@gmail.com>
  • Loading branch information
aylei committed Dec 13, 2019
1 parent f15bd40 commit 98c61ee
Show file tree
Hide file tree
Showing 17 changed files with 643 additions and 132 deletions.
10 changes: 9 additions & 1 deletion manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,11 @@ spec:
target store.
format: int64
type: integer
max-store-down-time: {}
max-store-down-time:
description: MaxStoreDownTime is the max duration after
which a store will be considered to be down if it hasn't
reported heartbeats.
type: string
merge-schedule-limit:
description: MergeScheduleLimit is the max coexist merge
schedules.
Expand Down Expand Up @@ -994,6 +998,8 @@ spec:
description: TsoSaveInterval is the interval to save timestamp.
type: string
type: object
configUpdateStrategy:
type: string
replicas:
format: int32
type: integer
Expand Down Expand Up @@ -2192,6 +2198,8 @@ spec:
type: integer
type: object
type: object
configUpdateStrategy:
type: string
maxFailoverCount:
format: int32
type: integer
Expand Down
17 changes: 15 additions & 2 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

52 changes: 3 additions & 49 deletions pkg/apis/pingcap/v1alpha1/pd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
package v1alpha1

import (
"fmt"
"strconv"
"time"

"github.com/pingcap/log"
"github.com/pingcap/pd/pkg/metricutil"
"github.com/pingcap/pd/pkg/typeutil"
Expand Down Expand Up @@ -101,13 +97,13 @@ type PDConfig struct {
Replication *PDReplicationConfig `toml:"replication,omitempty" json:"replication,omitempty"`

// +optional
Namespace map[string]PDNamespaceConfig `json:"namespace,omitempty"`
Namespace map[string]PDNamespaceConfig `toml:"namespace,omitempty" json:"namespace,omitempty"`

// +optional
PDServerCfg *PDServerConfig `toml:"pd-server,omitempty" json:"pd-server,omitempty"`

// +optional
ClusterVersion string `json:"cluster-version,omitempty"`
ClusterVersion string `toml:"cluster-version,omitempty" json:"cluster-version,omitempty"`

// QuotaBackendBytes Raise alarms when backend size exceeds the given quota. 0 means use the default quota.
// the default size is 2GB, the maximum is 8GB.
Expand Down Expand Up @@ -250,7 +246,7 @@ type PDScheduleConfig struct {
// MaxStoreDownTime is the max duration after which
// a store will be considered to be down if it hasn't reported heartbeats.
// +optional
MaxStoreDownTime Duration `toml:"max-store-down-time,omitempty" json:"max-store-down-time,omitempty"`
MaxStoreDownTime string `toml:"max-store-down-time,omitempty" json:"max-store-down-time,omitempty"`
// LeaderScheduleLimit is the max coexist leader schedules.
// +optional
LeaderScheduleLimit *uint64 `toml:"leader-schedule-limit,omitempty" json:"leader-schedule-limit,omitempty"`
Expand Down Expand Up @@ -369,45 +365,3 @@ type PDServerConfig struct {
// +optional
UseRegionStorage *bool `toml:"use-region-storage,omitempty" json:"use-region-storage,string,omitempty"`
}

// Duration is a wrapper of time.Duration for TOML and JSON.
// Copied from pingcap typeutil, add marshal to TOML support
type Duration struct {
time.Duration
}

// NewDuration creates a Duration from time.Duration.
func NewDuration(duration time.Duration) Duration {
return Duration{Duration: duration}
}

// MarshalJSON returns the duration as a JSON string.
func (d *Duration) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
}

// UnmarshalJSON parses a JSON string into the duration.
func (d *Duration) UnmarshalJSON(text []byte) error {
s, err := strconv.Unquote(string(text))
if err != nil {
return err
}
duration, err := time.ParseDuration(s)
if err != nil {
return err
}
d.Duration = duration
return nil
}

// UnmarshalText parses a TOML string into the duration.
func (d *Duration) UnmarshalText(text []byte) error {
var err error
d.Duration, err = time.ParseDuration(string(text))
return err
}

// MarshalText marshal duration to a TOML string
func (d *Duration) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, d.String())), nil
}
16 changes: 16 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ func (tc *TidbCluster) TiDBConfigUpdateStrategy() ConfigUpdateStrategy {
return s
}

func (tc *TidbCluster) PDConfigUpdateStrategy() ConfigUpdateStrategy {
s := tc.Spec.PD.ConfigUpdateStrategy
if string(s) == "" {
s = ConfigUpdateStrategyInPlace
}
return s
}

func (tc *TidbCluster) TiKVConfigUpdateStrategy() ConfigUpdateStrategy {
s := tc.Spec.TiKV.ConfigUpdateStrategy
if string(s) == "" {
s = ConfigUpdateStrategyInPlace
}
return s
}

func (tc *TidbCluster) PDIsAvailable() bool {
lowerLimit := tc.Spec.PD.Replicas/2 + 1
if int32(len(tc.Status.PD.Members)) < lowerLimit {
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ type PDSpec struct {
Service *ServiceSpec `json:"service,omitempty"`
StorageClassName string `json:"storageClassName,omitempty"`

// +optional
ConfigUpdateStrategy ConfigUpdateStrategy `json:"configUpdateStrategy,omitempty"`

// Config is the Configuration of pd-servers
Config *PDConfig `json:"config,omitempty"`
}
Expand All @@ -200,6 +203,9 @@ type TiKVSpec struct {
StorageClassName string `json:"storageClassName,omitempty"`
MaxFailoverCount int32 `json:"maxFailoverCount,omitempty"`

// +optional
ConfigUpdateStrategy ConfigUpdateStrategy `json:"configUpdateStrategy,omitempty"`

// Config is the Configuration of tikv-servers
Config *TiKVConfig `json:"config,omitempty"`
}
Expand Down
17 changes: 0 additions & 17 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.

2 changes: 2 additions & 0 deletions pkg/controller/tidbcluster/tidb_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func NewController(
svcControl,
podControl,
certControl,
typedControl,
setInformer.Lister(),
svcInformer.Lister(),
podInformer.Lister(),
Expand All @@ -140,6 +141,7 @@ func NewController(
setControl,
svcControl,
certControl,
typedControl,
setInformer.Lister(),
svcInformer.Lister(),
podInformer.Lister(),
Expand Down
Loading

0 comments on commit 98c61ee

Please sign in to comment.