Skip to content

Commit

Permalink
Fix defaulting webhook error (#1876)
Browse files Browse the repository at this point in the history
* fix defaulting

* remove config validation

* fix e2e test

* fix e2e test
  • Loading branch information
Yisaer authored Mar 10, 2020
1 parent 7088148 commit 6bfa729
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
9 changes: 0 additions & 9 deletions pkg/apis/pingcap/v1alpha1/defaulting/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ func setTidbClusterSpecDefault(tc *v1alpha1.TidbCluster) {
}

func setTidbSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiDB.Config == nil {
tc.Spec.TiDB.Config = &v1alpha1.TiDBConfig{}
}
if len(tc.Spec.Version) > 0 || tc.Spec.TiDB.Version != nil {
if tc.Spec.TiDB.BaseImage == "" {
tc.Spec.TiDB.BaseImage = defaultTiDBImage
Expand All @@ -62,9 +59,6 @@ func setTidbSpecDefault(tc *v1alpha1.TidbCluster) {
}

func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.TiKV.Config == nil {
tc.Spec.TiKV.Config = &v1alpha1.TiKVConfig{}
}
if len(tc.Spec.Version) > 0 || tc.Spec.TiKV.Version != nil {
if tc.Spec.TiKV.BaseImage == "" {
tc.Spec.TiKV.BaseImage = defaultTiKVImage
Expand All @@ -73,9 +67,6 @@ func setTikvSpecDefault(tc *v1alpha1.TidbCluster) {
}

func setPdSpecDefault(tc *v1alpha1.TidbCluster) {
if tc.Spec.PD.Config == nil {
tc.Spec.PD.Config = &v1alpha1.PDConfig{}
}
if len(tc.Spec.Version) > 0 || tc.Spec.PD.Version != nil {
if tc.Spec.PD.BaseImage == "" {
tc.Spec.PD.BaseImage = defaultPDImage
Expand Down
9 changes: 0 additions & 9 deletions pkg/apis/pingcap/v1alpha1/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ func validateNewTidbClusterSpec(spec *v1alpha1.TidbClusterSpec, path *field.Path
if spec.PD.Image != "" {
allErrs = append(allErrs, field.Invalid(path.Child("pd.image"), spec.PD.Image, "image has been deprecated, use baseImage instead"))
}
if spec.TiDB.Config == nil {
allErrs = append(allErrs, field.Invalid(path.Child("tidb.config"), spec.TiDB.Config, "tidb.config must not be nil"))
}
if spec.TiKV.Config == nil {
allErrs = append(allErrs, field.Invalid(path.Child("tikv.config"), spec.TiKV.Config, "tidb.config must not be nil"))
}
if spec.PD.Config == nil {
allErrs = append(allErrs, field.Invalid(path.Child("pd.config"), spec.PD.Config, "tidb.config must not be nil"))
}
return allErrs
}

Expand Down
9 changes: 4 additions & 5 deletions tests/e2e/tidbcluster/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ var _ = ginkgo.Describe("[tidb-operator][Serial]", func() {
if empty, err := gomega.BeEmpty().Match(newTC.Spec.TiDB.BaseImage); empty {
e2elog.Failf("Expected tidb.baseImage has default value set, %v", err)
}
if isNil, err := gomega.BeNil().Match(newTC.Spec.TiDB.Config); isNil {
e2elog.Failf("Expected tidb.config has default value set, %v", err)
}

ginkgo.By("Validating should reject illegal update")
newTC.Labels = map[string]string{
Expand All @@ -601,8 +598,10 @@ var _ = ginkgo.Describe("[tidb-operator][Serial]", func() {
_, err = cli.PingcapV1alpha1().TidbClusters(ns).Update(newTC)
framework.ExpectError(err, "Could not set instance label with value other than cluster name")

newTC.Spec.PD.Config.Replication = &v1alpha1.PDReplicationConfig{
MaxReplicas: func() *uint64 { i := uint64(5); return &i }(),
newTC.Spec.PD.Config = &v1alpha1.PDConfig{
Replication: &v1alpha1.PDReplicationConfig{
MaxReplicas: func() *uint64 { i := uint64(5); return &i }(),
},
}
_, err = cli.PingcapV1alpha1().TidbClusters(ns).Update(newTC)
framework.ExpectError(err, "PD replication config is immutable through CR")
Expand Down

0 comments on commit 6bfa729

Please sign in to comment.