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

add store labels #3784

Merged
merged 10 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -18057,6 +18057,18 @@ Defaults to 10m</p>
<p>StorageVolumes configure additional storage for TiKV pods.</p>
</td>
</tr>
<tr>
<td>
<code>storeLabels</code></br>
<em>
[]string
</em>
</td>
<td>
<em>(Optional)</em>
<p>StoreLabels configures additional labels for TiKV stores.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tikvstatus">TiKVStatus</h3>
Expand Down
4 changes: 4 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12788,6 +12788,10 @@ spec:
storageVolumes:
items: {}
type: array
storeLabels:
items:
type: string
type: array
terminationGracePeriodSeconds:
format: int64
type: integer
Expand Down
14 changes: 14 additions & 0 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.

4 changes: 4 additions & 0 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ type TiKVSpec struct {
// StorageVolumes configure additional storage for TiKV pods.
// +optional
StorageVolumes []StorageVolume `json:"storageVolumes,omitempty"`

// StoreLabels configures additional labels for TiKV stores.
// +optional
StoreLabels []string `json:"storeLabels,omitempty"`
}

// TiFlashSpec contains details of TiFlash members
Expand Down
5 changes: 5 additions & 0 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.

6 changes: 3 additions & 3 deletions pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ func (m *tikvMemberManager) setStoreLabelsForTiKV(tc *v1alpha1.TidbCluster) (int
return setCount, err
}

locationLabels := []string(config.Replication.LocationLabels)
if locationLabels == nil {
storeLabels := append(config.Replication.LocationLabels, tc.Spec.TiKV.StoreLabels...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are some duplicated labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里重复的话,下面逻辑都是根据 storeLabels 对 map 赋值,所以对下面逻辑不会有影响,改了还要多几行代码(,这里就不改了吧(

if storeLabels == nil {
return setCount, nil
}

Expand All @@ -843,7 +843,7 @@ func (m *tikvMemberManager) setStoreLabelsForTiKV(tc *v1alpha1.TidbCluster) (int
}

nodeName := pod.Spec.NodeName
ls, err := m.getNodeLabels(nodeName, locationLabels)
ls, err := m.getNodeLabels(nodeName, storeLabels)
if err != nil || len(ls) == 0 {
klog.Warningf("node: [%s] has no node labels, skipping set store labels for Pod: [%s/%s]", nodeName, ns, podName)
continue
Expand Down