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

Support initialization store labels #2945

Closed
wants to merge 3 commits into from

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Jul 15, 2020

What problem does this PR solve?

Close #2692

What is changed and how does it work?

Support initialization store labels for TiKV

Related changes

  • Need to cherry-pick to the release branch

Does this PR introduce a user-facing change?:

Support initialize store labels for TiKVGroup and TidbCluster

@Yisaer Yisaer added the area/heterogeneous related to tidb/tikv heterogeneous groups label Jul 15, 2020
} else {
storeLabels = map[string]string{}
}
storeLabels["groupName"] = tg.Name
Copy link
Contributor Author

@Yisaer Yisaer Jul 15, 2020

Choose a reason for hiding this comment

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

For each TiKVGroup instance, we will set groupName: tikvgroup-name as its store label. @rleungx


// InitializeStoreLabels indicates the store label set during initialization
// +optional
InitializeStoreLabels map[string]string `json:"initializeStoreLabels,omitempty"`
Copy link
Contributor

@cofyc cofyc Jul 15, 2020

Choose a reason for hiding this comment

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

I would prefer a shorter name, storeLabels or initStorelabels

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should this generic way to configure environments for containers

https://github.com/pingcap/tidb-operator/blob/master/pkg/apis/pingcap/v1alpha1/types.go#L711

Copy link
Contributor Author

@Yisaer Yisaer Jul 15, 2020

Choose a reason for hiding this comment

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

Setting store label by ENV is the way operator pass the store labels for tikv but not obvious and convenient for users, I still suggest exposing store labels by a certain atrribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary to provide a special way for this. It's simple as configuring environments for a normal pod in Kubernetes.

Copy link
Contributor

Choose a reason for hiding this comment

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

We already have too many special configurations. Anyone knowing the standard way to configure environments for containers can configure this env and any other environments for TiKV and other components.

If we use this special field for STORE_LABELS, we have more things to consider, e.g. what if users set both STORE_LABELS env and storeLabels field. Should we merge them? If not, which one has a higher priority, etc. If we have a special field for this env, should we add fields for other envs if users ask?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I agree with setting store labels by env.

Comment on lines +394 to +409
if len(labels) < 1 {
return ""
}
s := ""
var keys []string
for k := range labels {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
v, ok := labels[key]
if ok {
s = fmt.Sprintf("%s,%s", s, fmt.Sprintf("%s=%s", key, v))
}
}
return s[1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(labels) < 1 {
return ""
}
s := ""
var keys []string
for k := range labels {
keys = append(keys, k)
}
sort.Strings(keys)
for _, key := range keys {
v, ok := labels[key]
if ok {
s = fmt.Sprintf("%s,%s", s, fmt.Sprintf("%s=%s", key, v))
}
}
return s[1:]
var envs []string
for k, v := range labels {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
sort.Strings(envs)
return strings.Join(envs, ",")

we should always try to use built-in functions to simplify code

btw, please add some basic units 1) nil map 2) 1 element map 3) more than 1 elements map

@Yisaer Yisaer closed this Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/heterogeneous related to tidb/tikv heterogeneous groups
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide way to set store labels for TiKV during initialization
2 participants