From 8dd1b05453ef6681daed1e1a67019d3c94095706 Mon Sep 17 00:00:00 2001 From: Song Gao Date: Fri, 28 Feb 2020 14:36:49 +0800 Subject: [PATCH 1/2] enable defaulting (#1816) --- 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 3733a567066..31a8caa3b11 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 829a470e1fc..6b4bcda1c1c 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 9bd5aa47830..c6a1701c756 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 } } From 9b69f6d826d1743f4a289e4f2dfedfdaf21ba76e Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Fri, 28 Feb 2020 18:48:41 +0800 Subject: [PATCH 2/2] show cli flags in logs (#1807) --- cmd/admission-webhook/main.go | 6 +++++- cmd/controller-manager/main.go | 4 ++++ cmd/discovery/main.go | 4 ++++ cmd/scheduler/main.go | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/admission-webhook/main.go b/cmd/admission-webhook/main.go index 120b0f70a1e..9df37ba7523 100644 --- a/cmd/admission-webhook/main.go +++ b/cmd/admission-webhook/main.go @@ -19,11 +19,11 @@ import ( "time" "github.com/openshift/generic-admission-server/pkg/cmd" - "github.com/pingcap/tidb-operator/pkg/features" "github.com/pingcap/tidb-operator/pkg/version" "github.com/pingcap/tidb-operator/pkg/webhook" "k8s.io/component-base/logs" + "k8s.io/klog" ) var ( @@ -51,6 +51,10 @@ func main() { } version.LogVersionInfo() + flag.CommandLine.VisitAll(func(flag *flag.Flag) { + klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value) + }) + ah := &webhook.AdmissionHook{ ExtraServiceAccounts: extraServiceAccounts, EvictRegionLeaderTimeout: evictRegionLeaderTimeout, diff --git a/cmd/controller-manager/main.go b/cmd/controller-manager/main.go index f3179d36149..746026eea4b 100644 --- a/cmd/controller-manager/main.go +++ b/cmd/controller-manager/main.go @@ -93,6 +93,10 @@ func main() { logs.InitLogs() defer logs.FlushLogs() + flag.CommandLine.VisitAll(func(flag *flag.Flag) { + klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value) + }) + hostName, err := os.Hostname() if err != nil { klog.Fatalf("failed to get hostname: %v", err) diff --git a/cmd/discovery/main.go b/cmd/discovery/main.go index afe437be5d3..9aea6001d06 100644 --- a/cmd/discovery/main.go +++ b/cmd/discovery/main.go @@ -52,6 +52,10 @@ func main() { logs.InitLogs() defer logs.FlushLogs() + flag.CommandLine.VisitAll(func(flag *flag.Flag) { + klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value) + }) + cfg, err := rest.InClusterConfig() if err != nil { klog.Fatalf("failed to get config: %v", err) diff --git a/cmd/scheduler/main.go b/cmd/scheduler/main.go index e445119eaa2..f7e4e7b6933 100644 --- a/cmd/scheduler/main.go +++ b/cmd/scheduler/main.go @@ -54,6 +54,10 @@ func main() { logs.InitLogs() defer logs.FlushLogs() + flag.CommandLine.VisitAll(func(flag *flag.Flag) { + klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value) + }) + cfg, err := rest.InClusterConfig() if err != nil { klog.Fatalf("failed to get config: %v", err)