Skip to content

Commit

Permalink
enable defaulting (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer authored Feb 28, 2020
1 parent 0af5ca1 commit 8dd1b05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
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
}
}

0 comments on commit 8dd1b05

Please sign in to comment.