-
Notifications
You must be signed in to change notification settings - Fork 500
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
Extend tidbcluster v1alpha1 to support configuration and pump #1193
Changes from 2 commits
5f5f1fc
974e289
8b03f61
9a3e851
a293880
356b8cd
387a7c9
1d2036d
03bb83e
4a89156
5fc8cef
d8724a6
137ae2c
ff8d88f
2ec8481
6682235
d109f36
9d3df34
72ea45c
32fc5c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,166 @@ | |
|
||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const ( | ||
// defaultHelperImage is default image of helper | ||
defaultHelperImage = "busybox:1.26.2" | ||
) | ||
|
||
// ComponentAccessor is the interface to access component details, which respects the cluster-level properties | ||
// and component-level overrides | ||
type ComponentAccessor interface { | ||
Image() string | ||
ImagePullPolicy() corev1.PullPolicy | ||
HostNetwork() bool | ||
Affinity() *corev1.Affinity | ||
PriorityClassName() string | ||
NodeSelector() map[string]string | ||
Annotations() map[string]string | ||
Tolerations() []corev1.Toleration | ||
PodSecurityContext() *corev1.PodSecurityContext | ||
SchedulerName() string | ||
} | ||
|
||
type componentAccessorImpl struct { | ||
// Cluster is the TidbCluster Spec | ||
ClusterSpec *TidbClusterSpec | ||
|
||
// Cluster is the Component Spec | ||
ComponentSpec *ComponentSpec | ||
} | ||
|
||
func (a *componentAccessorImpl) Image() string { | ||
image := a.ComponentSpec.Image | ||
baseImage := a.ComponentSpec.BaseImage | ||
// base image takes higher priority | ||
if baseImage != "" { | ||
version := a.ComponentSpec.Version | ||
if version == "" { | ||
version = a.ClusterSpec.Version | ||
} | ||
image = fmt.Sprintf("%s:%s", baseImage, version) | ||
} | ||
return image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. image requires a tag and baseImage cannot have a tag? Why define two images in componentSpec? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For backward compatibility, we keep the |
||
} | ||
|
||
func (a *componentAccessorImpl) PodSecurityContext() *corev1.PodSecurityContext { | ||
return a.ComponentSpec.PodSecurityContext | ||
} | ||
|
||
func (a *componentAccessorImpl) ImagePullPolicy() corev1.PullPolicy { | ||
pp := a.ComponentSpec.ImagePullPolicy | ||
if pp == nil { | ||
pp = &a.ClusterSpec.ImagePullPolicy | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there will be a defaulting through mutating-webhook and validation to ensure clusterSpec.ImagePullPolicy and component.ImagePullPolicy is not both empty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it's not an issue if clusterSpec.ImagePullPolicy is empty, we just write empty pull policy in PodSpec and use the default of kubernetes |
||
return *pp | ||
} | ||
|
||
func (a *componentAccessorImpl) HostNetwork() bool { | ||
hostNetwork := a.ComponentSpec.HostNetwork | ||
if hostNetwork == nil { | ||
hostNetwork = &a.ClusterSpec.HostNetwork | ||
} | ||
return *hostNetwork | ||
} | ||
|
||
func (a *componentAccessorImpl) Affinity() *corev1.Affinity { | ||
affi := a.ComponentSpec.Affinity | ||
if affi == nil { | ||
affi = a.ClusterSpec.Affinity | ||
} | ||
return affi | ||
} | ||
|
||
func (a *componentAccessorImpl) PriorityClassName() string { | ||
pcn := a.ComponentSpec.PriorityClassName | ||
if pcn == "" { | ||
pcn = a.ClusterSpec.PriorityClassName | ||
} | ||
return pcn | ||
} | ||
|
||
func (a *componentAccessorImpl) SchedulerName() string { | ||
pcn := a.ComponentSpec.SchedulerName | ||
if pcn == "" { | ||
pcn = a.ClusterSpec.SchedulerName | ||
} | ||
return pcn | ||
} | ||
|
||
func (a *componentAccessorImpl) NodeSelector() map[string]string { | ||
sel := map[string]string{} | ||
for k, v := range a.ClusterSpec.NodeSelector { | ||
sel[k] = v | ||
} | ||
for k, v := range a.ComponentSpec.NodeSelector { | ||
sel[k] = v | ||
} | ||
return sel | ||
} | ||
|
||
func (a *componentAccessorImpl) Annotations() map[string]string { | ||
anno := map[string]string{} | ||
for k, v := range a.ClusterSpec.Annotations { | ||
anno[k] = v | ||
} | ||
for k, v := range a.ComponentSpec.Annotations { | ||
anno[k] = v | ||
} | ||
return anno | ||
} | ||
|
||
func (a *componentAccessorImpl) Tolerations() []corev1.Toleration { | ||
tols := a.ClusterSpec.Tolerations | ||
tols = append(tols, a.ComponentSpec.Tolerations...) | ||
aylei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return tols | ||
} | ||
|
||
func (tc *TidbCluster) BaseTiDBSpec() ComponentAccessor { | ||
return &componentAccessorImpl{&tc.Spec, &tc.Spec.TiDB.ComponentSpec} | ||
} | ||
|
||
func (tc *TidbCluster) BaseTiKVSpec() ComponentAccessor { | ||
return &componentAccessorImpl{&tc.Spec, &tc.Spec.TiKV.ComponentSpec} | ||
} | ||
|
||
func (tc *TidbCluster) BasePDSpec() ComponentAccessor { | ||
return &componentAccessorImpl{&tc.Spec, &tc.Spec.PD.ComponentSpec} | ||
} | ||
|
||
func (tc *TidbCluster) BasePumpSpec() ComponentAccessor { | ||
return &componentAccessorImpl{&tc.Spec, &tc.Spec.Pump.ComponentSpec} | ||
} | ||
|
||
func (tc *TidbCluster) HelperImage() string { | ||
image := tc.Spec.Helper.Image | ||
if image == "" { | ||
// for backward compatiability | ||
image = tc.Spec.TiDB.SlowLogTailer.Image | ||
} | ||
if image == "" { | ||
image = defaultHelperImage | ||
} | ||
return image | ||
} | ||
|
||
func (tc *TidbCluster) HelperImagePullPolicy() corev1.PullPolicy { | ||
pp := tc.Spec.Helper.ImagePullPolicy | ||
if pp == nil { | ||
// for backward compatiability | ||
pp = tc.Spec.TiDB.SlowLogTailer.ImagePullPolicy | ||
} | ||
if pp == nil { | ||
pp = &tc.Spec.ImagePullPolicy | ||
} | ||
return *pp | ||
} | ||
|
||
func (mt MemberType) String() string { | ||
return string(mt) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validation constraints will guarantee either .spec.version or .spec..version is not-empty if
baseImage
is present