Skip to content

Commit

Permalink
Remove third-party type definition from config types (#1362)
Browse files Browse the repository at this point in the history
* Remove thirdparty depedencies in config types

Signed-off-by: Aylei <rayingecho@gmail.com>

* re-generate code

Signed-off-by: Aylei <rayingecho@gmail.com>
  • Loading branch information
aylei authored and shuijing198799 committed Dec 19, 2019
1 parent 35db292 commit 2996b69
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ require (
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/pingcap/advanced-statefulset v0.1.0
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 // indirect
github.com/pingcap/errors v0.11.0
github.com/pingcap/kvproto v0.0.0-20190516013202-4cf58ad90b6c
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd
github.com/pingcap/pd v2.1.17+incompatible
github.com/pingcap/tidb v2.1.0-beta+incompatible
github.com/prometheus/client_golang v0.9.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@ github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/kvproto v0.0.0-20190516013202-4cf58ad90b6c h1:pY/MQQ5UajEHfSnQS8rFAM9gw9bBKzqBl414cdfhpRQ=
github.com/pingcap/kvproto v0.0.0-20190516013202-4cf58ad90b6c/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY=
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+8794bFHY1bPrmu6bTalpssCrGg=
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/pd v2.1.17+incompatible h1:mpfJYffRC14jeAfiq0jbHkqXVc8ZGNV0Lr2xG1sJslw=
github.com/pingcap/pd v2.1.17+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
github.com/pingcap/tidb v2.1.0-beta+incompatible h1:SQUmscnvvjHLjaIycQqtHujBahUnlKwTz6dQQhqgGSc=
Expand Down
57 changes: 54 additions & 3 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,28 @@ spec:
disable-timestamp:
description: Disable automatic timestamps in output.
type: boolean
file: {}
file:
properties:
filename:
description: Log filename, leave empty to disable file
log.
type: string
log-rotate:
description: Is log rotate enabled.
type: boolean
max-backups:
description: Maximum number of old log files to retain.
format: int32
type: integer
max-days:
description: Max log keep days, default is never deleting.
format: int32
type: integer
max-size:
description: Max size for a single file, in MB.
format: int32
type: integer
type: object
format:
description: Log format. one of json, text, or console.
type: string
Expand All @@ -789,7 +810,15 @@ spec:
type: string
log-level:
type: string
metric: {}
metric:
properties:
address:
type: string
interval:
type: string
job:
type: string
type: object
name:
type: string
namespace:
Expand Down Expand Up @@ -1101,7 +1130,28 @@ spec:
expensive-threshold:
format: int32
type: integer
file: {}
file:
properties:
filename:
description: Log filename, leave empty to disable file
log.
type: string
log-rotate:
description: Is log rotate enabled.
type: boolean
max-backups:
description: Maximum number of old log files to retain.
format: int32
type: integer
max-days:
description: Max log keep days, default is never deleting.
format: int32
type: integer
max-size:
description: Max size for a single file, in MB.
format: int32
type: integer
type: object
format:
description: Log format. one of json, text, or console.
type: string
Expand Down Expand Up @@ -1440,6 +1490,7 @@ spec:
concurrent-send-snap-limit:
format: int32
type: integer
coprocessor: {}
end-point-batch-row-limit:
format: int32
type: integer
Expand Down
98 changes: 91 additions & 7 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.

66 changes: 54 additions & 12 deletions pkg/apis/pingcap/v1alpha1/pd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
package v1alpha1

import (
"github.com/pingcap/log"
"github.com/pingcap/pd/pkg/metricutil"
"github.com/pingcap/pd/pkg/typeutil"
"strconv"
"strings"
)

// Maintain a copy of PDConfig to make it more friendly with the kubernetes API:
Expand Down Expand Up @@ -88,7 +87,7 @@ type PDConfig struct {
TsoSaveInterval string `toml:"tso-save-interval,omitempty" json:"tso-save-interval,omitempty"`

// +optional
Metric *metricutil.MetricConfig `toml:"metric,omitempty" json:"metric,omitempty"`
Metric *PDMetricConfig `toml:"metric,omitempty" json:"metric,omitempty"`

// +optional
Schedule *PDScheduleConfig `toml:"schedule,omitempty" json:"schedule,omitempty"`
Expand Down Expand Up @@ -160,7 +159,7 @@ type PDLogConfig struct {
DisableTimestamp *bool `toml:"disable-timestamp,omitempty" json:"disable-timestamp,omitempty"`
// File log config.
// +optional
File log.FileLogConfig `toml:"file,omitempty" json:"file,omitempty"`
File *FileLogConfig `toml:"file,omitempty" json:"file,omitempty"`
// Development puts the logger in development mode, which changes the
// behavior of DPanicLevel and takes stacktraces more liberally.
// +optional
Expand Down Expand Up @@ -192,7 +191,7 @@ type PDReplicationConfig struct {
// For example, ["zone", "rack"] means that we should place replicas to
// different zones first, then to different racks if we don't have enough zones.
// +optional
LocationLabels typeutil.StringSlice `toml:"location-labels,omitempty" json:"location-labels,omitempty"`
LocationLabels StringSlice `toml:"location-labels,omitempty" json:"location-labels,omitempty"`
// StrictlyMatchLabel strictly checks if the label of TiKV is matched with LocaltionLabels.
// +optional
StrictlyMatchLabel *bool `toml:"strictly-match-label,omitempty" json:"strictly-match-label,string,omitempty"`
Expand All @@ -203,22 +202,22 @@ type PDReplicationConfig struct {
type PDNamespaceConfig struct {
// LeaderScheduleLimit is the max coexist leader schedules.
// +optional
LeaderScheduleLimit *uint64 `json:"leader-schedule-limit,omitempty"`
LeaderScheduleLimit *uint64 `json:"leader-schedule-limit,omitempty" toml:"leader-schedule-limit,omitempty"`
// RegionScheduleLimit is the max coexist region schedules.
// +optional
RegionScheduleLimit *uint64 `json:"region-schedule-limit,omitempty"`
RegionScheduleLimit *uint64 `json:"region-schedule-limit,omitempty" toml:"region-schedule-limit,omitempty"`
// ReplicaScheduleLimit is the max coexist replica schedules.
// +optional
ReplicaScheduleLimit *uint64 `json:"replica-schedule-limit,omitempty"`
ReplicaScheduleLimit *uint64 `json:"replica-schedule-limit,omitempty" toml:"replica-schedule-limit,omitempty"`
// MergeScheduleLimit is the max coexist merge schedules.
// +optional
MergeScheduleLimit *uint64 `json:"merge-schedule-limit,omitempty"`
MergeScheduleLimit *uint64 `json:"merge-schedule-limit,omitempty" toml:"merge-schedule-limit,omitempty"`
// HotRegionScheduleLimit is the max coexist hot region schedules.
// +optional
HotRegionScheduleLimit *uint64 `json:"hot-region-schedule-limit,omitempty"`
HotRegionScheduleLimit *uint64 `json:"hot-region-schedule-limit,omitempty" toml:"hot-region-schedule-limit,omitempty"`
// MaxReplicas is the number of replicas for each region.
// +optional
MaxReplicas *uint64 `json:"max-replicas,omitempty"`
MaxReplicas *uint64 `json:"max-replicas,omitempty" toml:"max-replicas,omitempty"`
}

// ScheduleConfig is the schedule configuration.
Expand Down Expand Up @@ -365,3 +364,46 @@ type PDServerConfig struct {
// +optional
UseRegionStorage *bool `toml:"use-region-storage,omitempty" json:"use-region-storage,string,omitempty"`
}

// +k8s:openapi-gen=true
type PDMetricConfig struct {
PushJob string `toml:"job,omitempty" json:"job,omitempty"`
PushAddress string `toml:"address,omitempty" json:"address,omitempty"`
PushInterval string `toml:"interval,omitempty" json:"interval,omitempty"`
}

// +k8s:openapi-gen=true
type FileLogConfig struct {
// Log filename, leave empty to disable file log.
Filename string `toml:"filename,omitempty" json:"filename,omitempty"`
// Is log rotate enabled.
LogRotate bool `toml:"log-rotate,omitempty" json:"log-rotate,omitempty"`
// Max size for a single file, in MB.
MaxSize int `toml:"max-size,omitempty" json:"max-size,omitempty"`
// Max log keep days, default is never deleting.
MaxDays int `toml:"max-days,omitempty" json:"max-days,omitempty"`
// Maximum number of old log files to retain.
MaxBackups int `toml:"max-backups,omitempty" json:"max-backups,omitempty"`
}

//StringSlice is more friendly to json encode/decode
type StringSlice []string

// MarshalJSON returns the size as a JSON string.
func (s StringSlice) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(strings.Join(s, ","))), nil
}

// UnmarshalJSON parses a JSON string into the bytesize.
func (s *StringSlice) UnmarshalJSON(text []byte) error {
data, err := strconv.Unquote(string(text))
if err != nil {
return err
}
if len(data) == 0 {
*s = nil
return nil
}
*s = strings.Split(data, ",")
return nil
}
Loading

0 comments on commit 2996b69

Please sign in to comment.