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

Enable defaulting for tidbcluster (#1816) #1821

Merged
merged 1 commit into from
Mar 2, 2020
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
2 changes: 1 addition & 1 deletion charts/tidb-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ admissionWebhook:
## validating hook validates the correctness of the resources under pingcap.com group
validating: false
## defaulting hook set default values for the the resources under pingcap.com group
defaulting: false
defaulting: true
## failurePolicy are applied to ValidatingWebhookConfiguration which affect tidb-admission-webhook
## refer to https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#failure-policy
failurePolicy:
Expand Down
2 changes: 1 addition & 1 deletion ci/deploy_tidb_operator_staging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ admissionWebhook:
pods: true
# TODO: enable validating and defaulting after we ease the constrain
validating: false
defaulting: false
defaulting: true
features:
- AutoScaling=true
'''
Expand Down
51 changes: 41 additions & 10 deletions pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,59 @@ const (
)

func SetTidbClusterDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.BaseImage == "" {
tc.Spec.TiDB.BaseImage = defaultTiDBImage
setTidbClusterSpecDefault(tc)
setPdSpecDefault(tc)
setTikvSpecDefault(tc)
setTidbSpecDefault(tc)
if tc.Spec.Pump != nil {
setPumpSpecDefault(tc)
}
if tc.Spec.TiKV.BaseImage == "" {
tc.Spec.TiKV.BaseImage = defaultTiKVImage
}

// setTidbClusterSpecDefault is only managed the property under Spec
func setTidbClusterSpecDefault(tc *v1alpha1.TidbCluster) {
if string(tc.Spec.ImagePullPolicy) == "" {
tc.Spec.ImagePullPolicy = corev1.PullIfNotPresent
}
if tc.Spec.PD.BaseImage == "" {
tc.Spec.PD.BaseImage = defaultPDImage
if tc.Spec.EnableTLSCluster == nil {
d := false
tc.Spec.EnableTLSCluster = &d
}
if tc.Spec.Pump != nil && tc.Spec.Pump.BaseImage == "" {
tc.Spec.Pump.BaseImage = defaultBinlogImage
if tc.Spec.EnablePVReclaim == nil {
d := false
tc.Spec.EnablePVReclaim = &d
}
}

func setTidbSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.BaseImage == "" {
tc.Spec.TiDB.BaseImage = defaultTiDBImage
}
if tc.Spec.TiDB.Config == nil {
tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{}
}
}

func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiKV.Config == nil {
tc.Spec.TiKV.Config = &v1alpha1.TiKVConfig{}
}
if tc.Spec.TiKV.BaseImage == "" {
tc.Spec.TiKV.BaseImage = defaultTiKVImage
}
}

func setPdSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.PD.Config == nil {
tc.Spec.PD.Config = &v1alpha1.PDConfig{}
}
if string(tc.Spec.ImagePullPolicy) == "" {
tc.Spec.ImagePullPolicy = corev1.PullIfNotPresent
if tc.Spec.PD.BaseImage == "" {
tc.Spec.PD.BaseImage = defaultPDImage
}
}

func setPumpSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.Pump.BaseImage == "" {
tc.Spec.Pump.BaseImage = defaultBinlogImage
}
}