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

Fix location label #1941

Merged
merged 12 commits into from
Mar 30, 2020
13 changes: 1 addition & 12 deletions docs/api-references/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -4331,9 +4331,7 @@ <h3 id="pingcap.com/v1alpha1.PDReplicationConfig">PDReplicationConfig
<td>
<code>location-labels</code></br>
<em>
<a href="#pingcap.com/v1alpha1.StringSlice">
StringSlice
</a>
[]string
</em>
</td>
<td>
Expand Down Expand Up @@ -6643,15 +6641,6 @@ <h3 id="pingcap.com/v1alpha1.StorageProvider">StorageProvider
</tr>
</tbody>
</table>
<h3 id="pingcap.com/v1alpha1.StringSlice">StringSlice
(<code>[]string</code> alias)</p></h3>
<p>
(<em>Appears on:</em>
<a href="#pingcap.com/v1alpha1.PDReplicationConfig">PDReplicationConfig</a>)
</p>
<p>
<p>StringSlice is more friendly to json encode/decode</p>
</p>
<h3 id="pingcap.com/v1alpha1.TLSCluster">TLSCluster
</h3>
<p>
Expand Down
29 changes: 1 addition & 28 deletions pkg/apis/pingcap/v1alpha1/pd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

package v1alpha1

import (
"strconv"
"strings"
)

// Maintain a copy of PDConfig to make it more friendly with the kubernetes API:
//
// - add 'omitempty' json and toml tag to avoid passing the empty value of primitive types to tidb-server, e.g. 0 of int
Expand Down Expand Up @@ -177,7 +172,7 @@ type PDReplicationConfig struct {
// Immutable, change should be made through pd-ctl after cluster creation
// +k8s:openapi-gen=false
// +optional
LocationLabels StringSlice `toml:"location-labels,omitempty" json:"location-labels,omitempty"`
LocationLabels []string `toml:"location-labels,omitempty" json:"location-labels,omitempty"`
// StrictlyMatchLabel strictly checks if the label of TiKV is matched with LocaltionLabels.
// Immutable, change should be made through pd-ctl after cluster creation
// +optional
Expand Down Expand Up @@ -417,25 +412,3 @@ type FileLogConfig struct {
// 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
}
2 changes: 1 addition & 1 deletion pkg/apis/pingcap/v1alpha1/tidb_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type Log struct {
QueryLogMaxLen *uint64 `toml:"query-log-max-len,omitempty" json:"query-log-max-len,omitempty"`
// Optional: Defaults to 1
// +optional
RecordPlanInSlowLog uint32 `toml:"record-plan-in-slow-log,omitempty" json:"record-plan-in-slow-log,omitempty"`
RecordPlanInSlowLog *uint32 `toml:"record-plan-in-slow-log,omitempty" json:"record-plan-in-slow-log,omitempty"`
}

// Security is the security section of the config.
Expand Down
27 changes: 6 additions & 21 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: 1 addition & 1 deletion pkg/manager/member/pd_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ func TestGetPDConfigMap(t *testing.T) {
},
Replication: &v1alpha1.PDReplicationConfig{
MaxReplicas: func() *uint64 { i := uint64(5); return &i }(),
LocationLabels: v1alpha1.StringSlice{"node", "rack"},
LocationLabels: []string{"node", "rack"},
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/manager/member/tikv_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestTiKVMemberManagerSyncCreate(t *testing.T) {
pdClient.AddReaction(pdapi.GetConfigActionType, func(action *pdapi.Action) (interface{}, error) {
return &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
LocationLabels: v1alpha1.StringSlice{"region", "zone", "rack", "host"},
LocationLabels: []string{"region", "zone", "rack", "host"},
},
}, nil
})
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestTiKVMemberManagerSyncUpdate(t *testing.T) {
pdClient.AddReaction(pdapi.GetConfigActionType, func(action *pdapi.Action) (interface{}, error) {
return &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
LocationLabels: v1alpha1.StringSlice{"region", "zone", "rack", "host"},
LocationLabels: []string{"region", "zone", "rack", "host"},
},
}, nil
})
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestTiKVMemberManagerSetStoreLabelsForTiKV(t *testing.T) {
pdClient.AddReaction(pdapi.GetConfigActionType, func(action *pdapi.Action) (interface{}, error) {
return &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
LocationLabels: v1alpha1.StringSlice{"region", "zone", "rack", "host"},
LocationLabels: []string{"region", "zone", "rack", "host"},
},
}, nil
})
Expand Down