Skip to content

Commit

Permalink
Fix location label (#1941) (#2069)
Browse files Browse the repository at this point in the history
* Fix location label

Signed-off-by: Aylei <[email protected]>

* Fix api doc

Signed-off-by: Aylei <[email protected]>

* Separate struct used for crd and pd client

Signed-off-by: Aylei <[email protected]>

* Fix boilerplate

Signed-off-by: Aylei <[email protected]>

Co-authored-by: Aylei <[email protected]>
  • Loading branch information
sre-bot and aylei authored Mar 30, 2020
1 parent 64925a6 commit 7e48ad3
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 80 deletions.
13 changes: 1 addition & 12 deletions docs/api-references/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -4568,9 +4568,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 @@ -6993,15 +6991,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 @@ -176,7 +171,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.
// Imported from v3.1.0
Expand Down Expand Up @@ -443,25 +438,3 @@ type FileLogConfig struct {
// +optional
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
}
22 changes: 1 addition & 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 @@ -1168,7 +1168,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
14 changes: 7 additions & 7 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 @@ -219,9 +219,9 @@ func TestTiKVMemberManagerSyncUpdate(t *testing.T) {

tkmm, fakeSetControl, fakeSvcControl, pdClient, _, _ := newFakeTiKVMemberManager(tc)
pdClient.AddReaction(pdapi.GetConfigActionType, func(action *pdapi.Action) (interface{}, error) {
return &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
LocationLabels: v1alpha1.StringSlice{"region", "zone", "rack", "host"},
return &pdapi.PDConfigFromAPI{
Replication: &pdapi.PDReplicationConfig{
LocationLabels: []string{"region", "zone", "rack", "host"},
},
}, nil
})
Expand Down Expand Up @@ -481,9 +481,9 @@ func TestTiKVMemberManagerSetStoreLabelsForTiKV(t *testing.T) {
tc := newTidbClusterForPD()
pmm, _, _, pdClient, podIndexer, nodeIndexer := newFakeTiKVMemberManager(tc)
pdClient.AddReaction(pdapi.GetConfigActionType, func(action *pdapi.Action) (interface{}, error) {
return &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
LocationLabels: v1alpha1.StringSlice{"region", "zone", "rack", "host"},
return &pdapi.PDConfigFromAPI{
Replication: &pdapi.PDReplicationConfig{
LocationLabels: []string{"region", "zone", "rack", "host"},
},
}, nil
})
Expand Down
Loading

0 comments on commit 7e48ad3

Please sign in to comment.