From 014eb53bc5cc5b3bf415e89554d04409c6eab595 Mon Sep 17 00:00:00 2001 From: Song Gao <2695690803@qq.com> Date: Fri, 28 Feb 2020 11:45:54 +0800 Subject: [PATCH] enable defaulting --- charts/tidb-operator/values.yaml | 2 +- ci/deploy_tidb_operator_staging.groovy | 2 +- .../v1alpha1/defaulting/tidbcluster.go | 51 +++++++++++++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/charts/tidb-operator/values.yaml b/charts/tidb-operator/values.yaml index 3733a56706..31a8caa3b1 100644 --- a/charts/tidb-operator/values.yaml +++ b/charts/tidb-operator/values.yaml @@ -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: diff --git a/ci/deploy_tidb_operator_staging.groovy b/ci/deploy_tidb_operator_staging.groovy index 829a470e1f..6b4bcda1c1 100644 --- a/ci/deploy_tidb_operator_staging.groovy +++ b/ci/deploy_tidb_operator_staging.groovy @@ -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 ''' diff --git a/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go index 9bd5aa4783..c6a1701c75 100644 --- a/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go +++ b/pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go @@ -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 } }